public IDisposable CreateDisposableTestProject(string projectName, DnxSdk sdk, out string testProjectDir) { var source = Path.Combine(TestUtils.GetTestSolutionsDirectory(), "DthTestProjects", projectName); if (!Directory.Exists(source)) { throw new ArgumentException($"Test project {source} doesn't exist.", nameof(projectName)); } var disposableDir = new DisposableDir(); CreateDisposableTestProject(sdk, disposableDir, source); testProjectDir = Path.Combine(disposableDir, projectName); return disposableDir; }
public void DthNegative_BrokenProjectPathInLockFile_V2(DnxSdk sdk) { var testProject = _fixture.GetTestProjectPath("BrokenProjectPathSample"); using (var disposableDir = new DisposableDir()) using (var server = DthTestServer.Create(sdk)) using (var client = server.CreateClient()) { // copy the project to difference location so that the project path in its lock file is invalid var targetPath = Path.Combine(disposableDir, "BrokenProjectPathSample"); Testing.TestUtils.CopyFolder(testProject, targetPath); client.Initialize(targetPath, protocolVersion: 2); var messages = client.DrainAllMessages() .AssertDoesNotContain("Error"); messages.RetrieveSingleMessage("DependencyDiagnostics") .RetrieveDependencyDiagnosticsCollection() .RetrieveDependencyDiagnosticsErrorAt(0) .AssertProperty<string>("FormattedMessage", message => message.Contains("error NU1001: The dependency EmptyLibrary could not be resolved.")) .RetrievePropertyAs<JObject>("Source") .AssertProperty("Name", "EmptyLibrary"); messages.RetrieveSingleMessage("Dependencies") .RetrieveDependency("EmptyLibrary") .AssertProperty<JArray>("Errors", errorsArray => errorsArray.Count == 1) .AssertProperty<JArray>("Warnings", warningsArray => warningsArray.Count == 0) .AssertProperty("Name", "EmptyLibrary") .AssertProperty("Resolved", false); } }
public void DthDependencies_UpdateGlobalJson_RefreshDependencies(DnxSdk sdk) { using (var disposableDir = new DisposableDir()) using (var server = DthTestServer.Create(sdk)) using (var client = server.CreateClient()) { Testing.TestUtils.CopyFolder( _fixture.GetTestProjectPath("UpdateSearchPathSample"), Path.Combine(disposableDir, "UpdateSearchPathSample")); var root = Path.Combine(disposableDir, "UpdateSearchPathSample", "home"); sdk.Dnu.Restore(root).EnsureSuccess(); var testProject = Path.Combine(root, "src", "MainProject"); client.Initialize(testProject, protocolVersion: 2); var messages = client.DrainAllMessages(); messages.RetrieveSingleMessage("ProjectInformation") .RetrievePayloadAs<JObject>() .RetrievePropertyAs<JArray>("ProjectSearchPaths") .AssertJArrayCount(2); messages.RetrieveSingleMessage("Dependencies") .RetrieveDependency("Newtonsoft.Json") .AssertProperty("Type", "Project") .AssertProperty("Resolved", true) .AssertProperty<JArray>("Errors", array => array.Count == 0, _ => "Dependency shouldn't contain any error."); messages.RetrieveSingleMessage("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(root, GlobalSettings.GlobalFileName), JsonConvert.SerializeObject(new { project = new string[] { "src" } })); client.SendPayLoad(testProject, "RefreshDependencies"); messages = client.DrainAllMessages(); messages.RetrieveSingleMessage("ProjectInformation") .RetrievePayloadAs<JObject>() .RetrievePropertyAs<JArray>("ProjectSearchPaths") .AssertJArrayCount(1) .AssertJArrayElement(0, Path.Combine(root, "src")); messages.RetrieveSingleMessage("Dependencies") .RetrieveDependency("Newtonsoft.Json") .AssertProperty("Type", LibraryTypes.Unresolved) .AssertProperty("Resolved", false) .RetrievePropertyAs<JArray>("Errors") .AssertJArrayCount(1) .RetrieveArraryElementAs<JObject>(0) .AssertProperty("ErrorCode", "NU1010"); messages.RetrieveSingleMessage("DependencyDiagnostics") .RetrieveDependencyDiagnosticsCollection() .RetrieveDependencyDiagnosticsErrorAt<JObject>(0) .AssertProperty("ErrorCode", "NU1010"); } }
public DthFunctionalTestFixture() { _context = new DisposableDir(); PrepareTestProjects(); }