Fix dependencies type changes scenario in project model server.

This commit is contained in:
Troy Dai 2016-05-31 16:14:26 -07:00
parent 0d470ecea0
commit 97da0b0696
2 changed files with 62 additions and 8 deletions

View file

@ -42,7 +42,7 @@ namespace Microsoft.DotNet.ProjectModel.Server
foreach (var projectContext in projectContextsCollection.FrameworkOnlyContexts)
{
snapshot.ProjectContexts[projectContext.TargetFramework] =
ProjectContextSnapshot.Create(projectContext, configuration, currentSearchPaths);
ProjectContextSnapshot.Create(projectContext, configuration, projectSearchPaths);
}
return snapshot;

View file

@ -257,11 +257,11 @@ namespace Microsoft.DotNet.ProjectModel.Server.Tests
}
}
[Fact(Skip = "Require dotnet restore integration test")]
[Fact]
public void DthDependencies_UpdateGlobalJson_RefreshDependencies()
{
var assets = new TestAssetsManager(Path.Combine(AppContext.BaseDirectory, "TestAssets", "ProjectModelServer"));
var projectPath = assets.CreateTestInstance("DthUpdateSearchPathSample").WithLockFiles().TestRoot;
var assetsManager = new TestAssetsManager(Path.Combine(RepoRoot, "TestAssets", "ProjectModelServer"));
var projectPath = assetsManager.CreateTestInstance("DthUpdateSearchPathSample").WithLockFiles().TestRoot;
Assert.True(Directory.Exists(projectPath));
using (var server = new DthTestServer())
@ -290,7 +290,7 @@ namespace Microsoft.DotNet.ProjectModel.Server.Tests
// Overwrite the global.json to remove search path to ext
File.WriteAllText(
Path.Combine(projectPath, "home", GlobalSettings.FileName),
JsonConvert.SerializeObject(new { project = new string[] { "src" } }));
JsonConvert.SerializeObject(new { projects = new string[] { "src" } }));
client.SendPayload(testProject, "RefreshDependencies");
@ -302,17 +302,71 @@ namespace Microsoft.DotNet.ProjectModel.Server.Tests
client.DrainTillFirst("Dependencies")
.RetrieveDependency("Newtonsoft.Json")
.AssertProperty("Type", "")
.AssertProperty("Resolved", false)
.AssertProperty("Type", "Project")
.RetrievePropertyAs<JArray>("Errors")
.AssertJArrayCount(1)
.RetrieveArraryElementAs<JObject>(0)
.AssertProperty("ErrorCode", "NU1010");
.AssertProperty("ErrorCode", ErrorCodes.NU1010);
client.DrainTillFirst("DependencyDiagnostics")
.RetrieveDependencyDiagnosticsCollection()
.RetrieveDependencyDiagnosticsErrorAt<JObject>(0)
.AssertProperty("ErrorCode", "NU1010");
.AssertProperty("ErrorCode", ErrorCodes.NU1010);
var restoreCommand = new RestoreCommand();
restoreCommand.WorkingDirectory = projectPath;
restoreCommand.Execute().Should().Pass();
client.SendPayload(testProject, "RefreshDependencies");
client.DrainTillFirst("Dependencies")
.RetrieveDependency("Newtonsoft.Json")
.AssertProperty("Resolved", true)
.AssertProperty("Type", "Package")
.RetrievePropertyAs<JArray>("Errors")
.AssertJArrayCount(0);
client.DrainTillFirst("DependencyDiagnostics")
.RetrievePayloadAs<JObject>()
.AssertProperty<JArray>("Errors", array => array.Count == 0)
.AssertProperty<JArray>("Warnings", array => array.Count == 0);
// Overwrite the global.json to add search path to ext back
File.WriteAllText(
Path.Combine(projectPath, "home", GlobalSettings.FileName),
JsonConvert.SerializeObject(new { projects = new string[] { "src", "../ext" } }));
// Console.WriteLine($"attach to {System.Diagnostics.Process.GetCurrentProcess().Id}");
// while(!System.Diagnostics.Debugger.IsAttached)
// {
// System.Threading.Thread.Sleep(100);
// }
client.SendPayload(testProject, "RefreshDependencies");
// var messages = client.DrainAllMessages(TimeSpan.FromDays(1));
client.DrainTillFirst("ProjectInformation")
.RetrievePayloadAs<JObject>()
.RetrievePropertyAs<JArray>("ProjectSearchPaths")
.AssertJArrayCount(2)
.AssertJArrayElement(0, Path.Combine(projectPath, "home", "src"))
.AssertJArrayElement(1, Path.Combine(projectPath, "ext"));
client.DrainTillFirst("Dependencies")
.RetrieveDependency("Newtonsoft.Json")
.AssertProperty("Resolved", false)
.AssertProperty("Type", "Package")
.RetrievePropertyAs<JArray>("Errors")
.AssertJArrayCount(1)
.RetrieveArraryElementAs<JObject>(0)
.AssertProperty("ErrorCode", ErrorCodes.NU1010);
client.DrainTillFirst("DependencyDiagnostics")
.RetrieveDependencyDiagnosticsCollection()
.RetrieveDependencyDiagnosticsErrorAt<JObject>(0)
.AssertProperty("ErrorCode", ErrorCodes.NU1010);
}
}