public void RefreshDependenciesResultsAreConsistent(string messageType, bool?clearCache) { var projectPath = Path.Combine(_testAssetsManager.AssetsRoot, "EmptyNetCoreApp"); Assert.True(Directory.Exists(projectPath)); using (var server = new DthTestServer()) using (var client = new DthTestClient(server)) { client.Initialize(projectPath); var originalDependencies = client.DrainMessage(7).Single(m => m.MessageType == MessageTypes.Dependencies) .RetrievePayloadAs <JObject>(); if (clearCache.HasValue) { client.SendPayload(projectPath, messageType, new { Reset = clearCache.Value }); } else { client.SendPayload(projectPath, messageType); } var refreshedDependencies = client.DrainTillFirst(MessageTypes.Dependencies).Payload.ToString(); Assert.Equal(originalDependencies.ToString(), refreshedDependencies.ToString()); } }
public void RefreshDependenciesResultsAreConsistent(string messageType, bool? clearCache) { var projectPath = Path.Combine(_testAssetsManager.AssetsRoot, "EmptyNetCoreApp"); Assert.True(Directory.Exists(projectPath)); using (var server = new DthTestServer()) using (var client = new DthTestClient(server)) { client.Initialize(projectPath); var originalDependencies = client.DrainMessage(7).Single(m => m.MessageType == MessageTypes.Dependencies) .RetrievePayloadAs<JObject>(); if (clearCache.HasValue) { client.SendPayload(projectPath, messageType, new { Reset = clearCache.Value }); } else { client.SendPayload(projectPath, messageType); } var refreshedDependencies = client.DrainTillFirst(MessageTypes.Dependencies).Payload.ToString(); Assert.Equal(originalDependencies.ToString(), refreshedDependencies.ToString()); } }
public void DthDependencies_UpdateGlobalJson_RefreshDependencies() { var assets = new TestAssetsManager(Path.Combine(AppContext.BaseDirectory, "TestAssets", "ProjectModelServer")); var projectPath = assets.CreateTestInstance("DthUpdateSearchPathSample").WithLockFiles().TestRoot; Assert.True(Directory.Exists(projectPath)); using (var server = new DthTestServer()) using (var client = new DthTestClient(server)) { var testProject = Path.Combine(projectPath, "home", "src", "MainProject"); client.Initialize(testProject); client.DrainTillFirst("ProjectInformation") .RetrievePayloadAs <JObject>() .RetrievePropertyAs <JArray>("ProjectSearchPaths") .AssertJArrayCount(2); client.DrainTillFirst("Dependencies") .RetrieveDependency("Newtonsoft.Json") .AssertProperty("Type", "Project") .AssertProperty("Resolved", true) .AssertProperty <JArray>("Errors", array => array.Count == 0, _ => "Dependency shouldn't contain any error."); client.DrainTillFirst("DependencyDiagnostics") .RetrievePayloadAs <JObject>() .AssertProperty <JArray>("Errors", array => array.Count == 0) .AssertProperty <JArray>("Warnings", array => array.Count == 0); // 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" } })); client.SendPayload(testProject, "RefreshDependencies"); client.DrainTillFirst("ProjectInformation") .RetrievePayloadAs <JObject>() .RetrievePropertyAs <JArray>("ProjectSearchPaths") .AssertJArrayCount(1) .AssertJArrayElement(0, Path.Combine(projectPath, "home", "src")); client.DrainTillFirst("Dependencies") .RetrieveDependency("Newtonsoft.Json") .AssertProperty("Type", "") .AssertProperty("Resolved", false) .RetrievePropertyAs <JArray>("Errors") .AssertJArrayCount(1) .RetrieveArraryElementAs <JObject>(0) .AssertProperty("ErrorCode", "NU1010"); client.DrainTillFirst("DependencyDiagnostics") .RetrieveDependencyDiagnosticsCollection() .RetrieveDependencyDiagnosticsErrorAt <JObject>(0) .AssertProperty("ErrorCode", "NU1010"); } }
public void RemoveMSBuildDependencyFromProjectJson() { // Remove a msbuild project dependency from project.json and then request refreshing dependency before // restore. var tam = new TestAssetsManager( Path.Combine(RepoRoot, "TestAssets", "ProjectModelServer", "MSBuildReferencesProjects")); // var appName = "EmptyNetCoreApp"; var projectPath = tam.CreateTestInstance("ValidCase01").WithLockFiles().TestRoot; projectPath = Path.Combine(projectPath, "src", "MainApp"); using (var server = new DthTestServer()) using (var client = new DthTestClient(server)) { client.Initialize(projectPath); client.DrainAllMessages() .AssertDoesNotContain(MessageTypes.Error) .RetrieveSingleMessage(MessageTypes.Dependencies) .RetrieveDependency("MainApp") .RetrievePropertyAs <JArray>("Dependencies") .AssertJArrayContains <JObject>(dep => dep["Name"].Value <string>() == "ClassLibrary1") .AssertJArrayContains <JObject>(dep => dep["Name"].Value <string>() == "ClassLibrary2") .AssertJArrayContains <JObject>(dep => dep["Name"].Value <string>() == "ClassLibrary3"); var projectFilePath = Path.Combine(projectPath, Project.FileName); var projectJson = JsonConvert.DeserializeObject <JObject>(File.ReadAllText(projectFilePath)); // Remove ClassLibrary2 and ClassLibrary3 dependency var dependencies = projectJson["frameworks"]["net46"]["dependencies"] as JObject; dependencies.Remove("ClassLibrary2"); dependencies.Remove("ClassLibrary3"); File.WriteAllText(projectFilePath, JsonConvert.SerializeObject(projectJson)); client.SendPayload(projectPath, MessageTypes.RefreshDependencies); var afterDependencies = client.DrainTillFirst(MessageTypes.Dependencies); afterDependencies.RetrieveDependency("MainApp") .RetrievePropertyAs <JArray>("Dependencies") .AssertJArrayNotContains <JObject>(dep => dep["Name"].Value <string>() == "ClassLibrary2") .AssertJArrayNotContains <JObject>(dep => dep["Name"].Value <string>() == "ClassLibrary3"); afterDependencies.RetrieveDependency("ClassLibrary2"); afterDependencies.RetrieveDependency("ClassLibrary3"); } }
public void RemovePackageDependencyFromProjectJson() { // Remove a package dependency from project.json and then request refreshing dependency before // restore. var appName = "EmptyNetCoreApp"; var projectPath = _testAssetsManager.CreateTestInstance(appName) .WithLockFiles() .TestRoot; using (var server = new DthTestServer()) using (var client = new DthTestClient(server)) { client.Initialize(projectPath); client.DrainAllMessages() .AssertDoesNotContain(MessageTypes.Error) .RetrieveSingleMessage(MessageTypes.Dependencies) .RetrieveDependency(appName) .RetrievePropertyAs <JArray>("Dependencies") .AssertJArrayCount(2); var projectFilePath = Path.Combine(projectPath, Project.FileName); var projectJson = JsonConvert.DeserializeObject <JObject>(File.ReadAllText(projectFilePath)); // Remove newtonsoft.json dependency var dependencies = projectJson["frameworks"]["netcoreapp1.0"]["dependencies"] as JObject; dependencies.Remove("Newtonsoft.Json"); File.WriteAllText(projectFilePath, JsonConvert.SerializeObject(projectJson)); client.SendPayload(projectPath, MessageTypes.RefreshDependencies); var afterDependencies = client.DrainTillFirst(MessageTypes.Dependencies); afterDependencies.RetrieveDependency(appName) .RetrievePropertyAs <JArray>("Dependencies") .AssertJArrayCount(1) .RetrieveArraryElementAs <JObject>(0) .AssertProperty("Name", "Microsoft.NETCore.App"); afterDependencies.RetrieveDependency("Newtonsoft.Json"); } }
public void RecoverFromGlobalError() { var testProject = _testAssetsManager.CreateTestInstance("EmptyConsoleApp") .WithLockFiles() .TestRoot; using (var server = new DthTestServer()) using (var client = new DthTestClient(server)) { var projectFile = Path.Combine(testProject, Project.FileName); var content = File.ReadAllText(projectFile); File.WriteAllText(projectFile, content + "}"); client.Initialize(testProject); var messages = client.DrainAllMessages(); messages.ContainsMessage(MessageTypes.Error); File.WriteAllText(projectFile, content); client.SendPayload(testProject, MessageTypes.FilesChanged); var clearError = client.DrainTillFirst(MessageTypes.Error); clearError.Payload.AsJObject().AssertProperty("Message", null as string); } }
public void TestTargetFrameworkChange() { using (var server = new DthTestServer()) using (var client = new DthTestClient(server)) { var testProject = _testAssetsManager.CreateTestInstance("EmptyLibrary") .WithLockFiles() .TestRoot; // initialize the project and drain all messages (7 message for project with one framework) client.Initialize(testProject); client.DrainMessage(7); // update the target framework from netstandard1.3 to netstandard 1.5 so as to invalidate all // dependencies var projectJsonPath = Path.Combine(testProject, "project.json"); File.WriteAllText(projectJsonPath, File.ReadAllText(projectJsonPath).Replace("netstandard1.3", "netstandard1.5")); // send files change request to server to prompt update client.SendPayload(testProject, MessageTypes.FilesChanged); // assert project information is updated client.DrainTillFirst(MessageTypes.ProjectInformation) .RetrievePayloadAs<JObject>() .RetrievePropertyAs<JArray>("Frameworks") .AssertJArrayCount(1) .RetrieveArraryElementAs<JObject>(0) .AssertProperty("ShortName", "netstandard1.5"); // the NETStandard.Library dependency should turn unresolved var dependencies = client.DrainTillFirst(MessageTypes.Dependencies); dependencies.RetrievePayloadAs<JObject>() .RetrievePropertyAs<JObject>("Framework") .AssertProperty("ShortName", "netstandard1.5"); dependencies.RetrieveDependency("NETStandard.Library") .RetrievePropertyAs<JArray>("Errors") .AssertJArrayCount(1) .RetrieveArraryElementAs<JObject>(0) .AssertProperty("ErrorCode", "NU1001"); // warning for project.json and project.lock.json out of sync var diagnostics = client.DrainTillFirst(MessageTypes.DependencyDiagnostics); diagnostics.RetrievePayloadAs<JObject>() .RetrievePropertyAs<JObject>("Framework") .AssertProperty("ShortName", "netstandard1.5"); diagnostics.RetrievePayloadAs<JObject>() .RetrievePropertyAs<JArray>("Warnings") .AssertJArrayCount(1) .RetrieveArraryElementAs<JObject>(0) .AssertProperty("ErrorCode", "NU1006"); // restore again var restoreCommand = new RestoreCommand(); restoreCommand.WorkingDirectory = testProject; restoreCommand.Execute().Should().Pass(); client.SendPayload(testProject, MessageTypes.RefreshDependencies); client.DrainTillFirst(MessageTypes.Dependencies) .RetrieveDependency("NETStandard.Library") .RetrievePropertyAs<JArray>("Errors") .AssertJArrayCount(0); client.DrainTillFirst(MessageTypes.DependencyDiagnostics) .RetrievePayloadAs<JObject>() .RetrievePropertyAs<JArray>("Warnings") .AssertJArrayCount(0); } }
public void RemoveMSBuildDependencyFromProjectJson() { // Remove a msbuild project dependency from project.json and then request refreshing dependency before // restore. var tam = new TestAssetsManager( Path.Combine(RepoRoot, "TestAssets", "ProjectModelServer", "MSBuildReferencesProjects")); // var appName = "EmptyNetCoreApp"; var projectPath = tam.CreateTestInstance("ValidCase01").WithLockFiles().TestRoot; projectPath = Path.Combine(projectPath, "src", "MainApp"); using (var server = new DthTestServer()) using (var client = new DthTestClient(server)) { client.Initialize(projectPath); client.DrainMessage(7) .AssertDoesNotContain(MessageTypes.Error) .RetrieveSingleMessage(MessageTypes.Dependencies) .RetrieveDependency("MainApp") .RetrievePropertyAs<JArray>("Dependencies") .AssertJArrayContains<JObject>(dep => dep["Name"].Value<string>() == "ClassLibrary1") .AssertJArrayContains<JObject>(dep => dep["Name"].Value<string>() == "ClassLibrary2") .AssertJArrayContains<JObject>(dep => dep["Name"].Value<string>() == "ClassLibrary3"); var projectFilePath = Path.Combine(projectPath, Project.FileName); var projectJson = JsonConvert.DeserializeObject<JObject>(File.ReadAllText(projectFilePath)); // Remove ClassLibrary2 and ClassLibrary3 dependency var dependencies = projectJson["frameworks"]["net46"]["dependencies"] as JObject; dependencies.Remove("ClassLibrary2"); dependencies.Remove("ClassLibrary3"); File.WriteAllText(projectFilePath, JsonConvert.SerializeObject(projectJson)); client.SendPayload(projectPath, MessageTypes.RefreshDependencies); var afterDependencies = client.DrainTillFirst(MessageTypes.Dependencies); afterDependencies.RetrieveDependency("MainApp") .RetrievePropertyAs<JArray>("Dependencies") .AssertJArrayNotContains<JObject>(dep => dep["Name"].Value<string>() == "ClassLibrary2") .AssertJArrayNotContains<JObject>(dep => dep["Name"].Value<string>() == "ClassLibrary3"); afterDependencies.RetrieveDependency("ClassLibrary2"); afterDependencies.RetrieveDependency("ClassLibrary3"); } }
public void RemovePackageDependencyFromProjectJson() { // Remove a package dependency from project.json and then request refreshing dependency before // restore. var appName = "EmptyNetCoreApp"; var projectPath = _testAssetsManager.CreateTestInstance(appName) .WithLockFiles() .TestRoot; using (var server = new DthTestServer()) using (var client = new DthTestClient(server)) { client.Initialize(projectPath); client.DrainMessage(7) .AssertDoesNotContain(MessageTypes.Error) .RetrieveSingleMessage(MessageTypes.Dependencies) .RetrieveDependency(appName) .RetrievePropertyAs<JArray>("Dependencies") .AssertJArrayCount(2); var projectFilePath = Path.Combine(projectPath, Project.FileName); var projectJson = JsonConvert.DeserializeObject<JObject>(File.ReadAllText(projectFilePath)); // Remove newtonsoft.json dependency var dependencies = projectJson["frameworks"]["netcoreapp1.0"]["dependencies"] as JObject; dependencies.Remove("Newtonsoft.Json"); File.WriteAllText(projectFilePath, JsonConvert.SerializeObject(projectJson)); client.SendPayload(projectPath, MessageTypes.RefreshDependencies); var afterDependencies = client.DrainTillFirst(MessageTypes.Dependencies); afterDependencies.RetrieveDependency(appName) .RetrievePropertyAs<JArray>("Dependencies") .AssertJArrayCount(1) .RetrieveArraryElementAs<JObject>(0) .AssertProperty("Name", "Microsoft.NETCore.App"); afterDependencies.RetrieveDependency("Newtonsoft.Json"); } }
public void RecoverFromGlobalError() { var testProject = _testAssetsManager.CreateTestInstance("EmptyConsoleApp") .WithLockFiles() .TestRoot; using (var server = new DthTestServer()) using (var client = new DthTestClient(server)) { var projectFile = Path.Combine(testProject, Project.FileName); var content = File.ReadAllText(projectFile); File.WriteAllText(projectFile, content + "}"); client.Initialize(testProject); client.DrainTillFirst(MessageTypes.Error); File.WriteAllText(projectFile, content); client.SendPayload(testProject, MessageTypes.FilesChanged); client.DrainTillFirst(MessageTypes.Error) .Payload.AsJObject() .AssertProperty("Message", null as string); } }
public void DthDependencies_UpdateGlobalJson_RefreshDependencies() { 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()) using (var client = new DthTestClient(server)) { var testProject = Path.Combine(projectPath, "home", "src", "MainProject"); client.Initialize(testProject); client.DrainTillFirst("ProjectInformation") .RetrievePayloadAs<JObject>() .RetrievePropertyAs<JArray>("ProjectSearchPaths") .AssertJArrayCount(2); client.DrainTillFirst("Dependencies") .RetrieveDependency("Newtonsoft.Json") .AssertProperty("Type", "Project") .AssertProperty("Resolved", true) .AssertProperty<JArray>("Errors", array => array.Count == 0, _ => "Dependency shouldn't contain any error."); client.DrainTillFirst("DependencyDiagnostics") .RetrievePayloadAs<JObject>() .AssertProperty<JArray>("Errors", array => array.Count == 0) .AssertProperty<JArray>("Warnings", array => array.Count == 0); // Overwrite the global.json to remove search path to ext File.WriteAllText( Path.Combine(projectPath, "home", GlobalSettings.FileName), JsonConvert.SerializeObject(new { projects = new string[] { "src" } })); client.SendPayload(testProject, "RefreshDependencies"); client.DrainTillFirst("ProjectInformation") .RetrievePayloadAs<JObject>() .RetrievePropertyAs<JArray>("ProjectSearchPaths") .AssertJArrayCount(1) .AssertJArrayElement(0, Path.Combine(projectPath, "home", "src")); client.DrainTillFirst("Dependencies") .RetrieveDependency("Newtonsoft.Json") .AssertProperty("Resolved", false) .AssertProperty("Type", "Project") .RetrievePropertyAs<JArray>("Errors") .AssertJArrayCount(1) .RetrieveArraryElementAs<JObject>(0) .AssertProperty("ErrorCode", ErrorCodes.NU1010); client.DrainTillFirst("DependencyDiagnostics") .RetrieveDependencyDiagnosticsCollection() .RetrieveDependencyDiagnosticsErrorAt<JObject>(0) .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" } })); client.SendPayload(testProject, "RefreshDependencies"); 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); } }
public void TestTargetFrameworkChange() { using (var server = new DthTestServer()) using (var client = new DthTestClient(server)) { var testProject = _testAssetsManager.CreateTestInstance("EmptyLibrary") .WithLockFiles() .TestRoot; // initialize the project and drain all messages (7 message for project with one framework) client.Initialize(testProject); client.DrainAllMessages(); // update the target framework from netstandard1.3 to netstandard 1.5 so as to invalidate all // dependencies var projectJsonPath = Path.Combine(testProject, "project.json"); File.WriteAllText(projectJsonPath, File.ReadAllText(projectJsonPath).Replace("netstandard1.3", "netstandard1.5")); // send files change request to server to prompt update client.SendPayload(testProject, MessageTypes.FilesChanged); // assert project information is updated client.DrainTillFirst(MessageTypes.ProjectInformation) .RetrievePayloadAs <JObject>() .RetrievePropertyAs <JArray>("Frameworks") .AssertJArrayCount(1) .RetrieveArraryElementAs <JObject>(0) .AssertProperty("ShortName", "netstandard1.5"); // the NETStandard.Library dependency should turn unresolved var dependencies = client.DrainTillFirst(MessageTypes.Dependencies); dependencies.RetrievePayloadAs <JObject>() .RetrievePropertyAs <JObject>("Framework") .AssertProperty("ShortName", "netstandard1.5"); dependencies.RetrieveDependency("NETStandard.Library") .RetrievePropertyAs <JArray>("Errors") .AssertJArrayCount(1) .RetrieveArraryElementAs <JObject>(0) .AssertProperty("ErrorCode", "NU1001"); // warning for project.json and project.lock.json out of sync var diagnostics = client.DrainTillFirst(MessageTypes.DependencyDiagnostics); diagnostics.RetrievePayloadAs <JObject>() .RetrievePropertyAs <JObject>("Framework") .AssertProperty("ShortName", "netstandard1.5"); diagnostics.RetrievePayloadAs <JObject>() .RetrievePropertyAs <JArray>("Warnings") .AssertJArrayCount(1) .RetrieveArraryElementAs <JObject>(0) .AssertProperty("ErrorCode", "NU1006"); // restore again var restoreCommand = new RestoreCommand(); restoreCommand.WorkingDirectory = testProject; restoreCommand.Execute().Should().Pass(); client.SendPayload(testProject, MessageTypes.RefreshDependencies); client.DrainTillFirst(MessageTypes.Dependencies) .RetrieveDependency("NETStandard.Library") .RetrievePropertyAs <JArray>("Errors") .AssertJArrayCount(0); client.DrainTillFirst(MessageTypes.DependencyDiagnostics) .RetrievePayloadAs <JObject>() .RetrievePropertyAs <JArray>("Warnings") .AssertJArrayCount(0); } }