public void CompileModuleWithDeps(DnxSdk sdk) { // Arrange var solution = TestProjectsRepository.EnsureRestoredSolution("CompileModuleWithDependencies"); var project = solution.GetProject("A"); using (var server = sdk.Dth.CreateServer()) using (var client = server.CreateClient()) { client.Initialize(project.ProjectDirectory); client.SendPayLoad(project, "GetDiagnostics"); // Assert var diagnosticsPerFramework = client.DrainTillFirst("AllDiagnostics") .RetrievePayloadAs <JArray>() .AssertJArrayCount(3); foreach (var frameworkDiagnostics in diagnosticsPerFramework) { var errors = frameworkDiagnostics.Value <JArray>("Errors"); var warnings = frameworkDiagnostics.Value <JArray>("Warnings"); Assert.Equal(0, errors.Count); Assert.Equal(0, warnings.Count); } } TestUtils.CleanUpTestDir <DthStartupTests>(sdk); }
public void DthStartup_GetProjectInformation(DnxSdk sdk) { using (var server = sdk.Dth.CreateServer()) using (var client = new DthTestClient(server)) { var solution = TestProjectsRepository.EnsureRestoredSolution("DthTestProjects"); var project = solution.GetProject("EmptyConsoleApp"); sdk.Dnu.Restore(project).EnsureSuccess(); client.Initialize(project.ProjectDirectory); var projectInformation = client.DrainTillFirst("ProjectInformation") .EnsureSource(server, client) .RetrievePayloadAs <JObject>() .AssertProperty("Name", project.Name); projectInformation.RetrievePropertyAs <JArray>("Configurations") .AssertJArrayCount(2) .AssertJArrayContains("Debug") .AssertJArrayContains("Release"); var frameworkShortNames = projectInformation.RetrievePropertyAs <JArray>("Frameworks") .AssertJArrayCount(2) .Select(f => f["ShortName"].Value <string>()); Assert.Contains("dnxcore50", frameworkShortNames); Assert.Contains("dnx451", frameworkShortNames); TestUtils.CleanUpTestDir <DthStartupTests>(sdk); } }
public void DthCompilation_ChangeConfiguration(DnxSdk sdk) { // arrange using (var server = sdk.Dth.CreateServer()) using (var client = server.CreateClient()) { var project = TestProjectsRepository.EnsureRestoredSolution("DthTestProjects") .GetProject("FailReleaseProject"); var contextId = client.Initialize(project.ProjectDirectory); client.SendPayLoad(contextId, DthMessageTypes.GetDiagnostics); // the default configuration must be debug. therefore the sample project // can be compiled successfully client.DrainTillFirst(DthMessageTypes.AllDiagnostics) .RetrieveCompilationDiagnostics("dnxcore50") .RetrievePropertyAs <JArray>("Errors") .AssertJArrayEmpty(); client.SendPayLoad(contextId, DthMessageTypes.ChangeConfiguration, new { Configuration = "Release" }); client.SendPayLoad(contextId, DthMessageTypes.GetDiagnostics); client.DrainTillFirst(DthMessageTypes.AllDiagnostics) .RetrieveCompilationDiagnostics("dnxcore50") .RetrievePropertyAs <JArray>("Errors") .AssertJArrayNotEmpty(); } }
public void DthStartup_EnumerateProjectContexts(DnxSdk sdk) { // arrange using (var server = sdk.Dth.CreateServer()) using (var client = server.CreateClient()) { var solution = TestProjectsRepository.EnsureRestoredSolution("DthTestProjects"); var projects = new Project[] { solution.GetProject("EmptyLibrary"), solution.GetProject("UnresolvedPackageSample"), solution.GetProject("EmptyConsoleApp") }; var contexts = projects.ToDictionary(proj => proj.ProjectDirectory, proj => client.Initialize(proj.ProjectDirectory)); // 7 response for each project initalization client.DrainMessage(21); // the context id here doesn't matter, this request is processed before it reaches // ApplicationContext client.SendPayLoad(1, DthMessageTypes.EnumerateProjectContexts, new { Version = 1 }); var message = client.DrainTillFirst(DthMessageTypes.ProjectContexts); Assert.Equal(contexts.Count, message.Projects.Count); Assert.True(Enumerable.SequenceEqual(contexts, message.Projects)); } }
public void DthNegative_BrokenProjectPathInLockFile_V2(DnxSdk sdk) { var projectName = "BrokenProjectPathSample"; var project = TestProjectsRepository.EnsureRestoredSolution("DthTestProjects") .GetProject(projectName); using (var server = sdk.Dth.CreateServer()) using (var client = server.CreateClient()) { // After restore the project is copied to another place so that // the relative path in project lock file is invalid. var movedProjectPath = Path.Combine(TestUtils.GetTempTestFolder <DthStartupTests>(sdk), projectName); TestUtils.CopyFolder(project.ProjectDirectory, movedProjectPath); client.Initialize(movedProjectPath, protocolVersion: 2); client.DrainTillFirst("DependencyDiagnostics") .RetrieveDependencyDiagnosticsCollection() .RetrieveDependencyDiagnosticsErrorAt(0) .AssertProperty <string>("FormattedMessage", message => message.Contains("error NU1002")) .RetrievePropertyAs <JObject>("Source") .AssertProperty("Name", "EmptyLibrary"); client.DrainTillFirst("Dependencies") .RetrieveDependency("EmptyLibrary") .AssertProperty <JArray>("Errors", errorsArray => errorsArray.Count == 1) .AssertProperty <JArray>("Warnings", warningsArray => warningsArray.Count == 0) .AssertProperty("Name", "EmptyLibrary") .AssertProperty("Resolved", false); } TestUtils.CleanUpTestDir <DthStartupTests>(sdk); }
public void DthNegative_BrokenProjectPathInLockFile_V1(DnxSdk sdk) { var projectName = "BrokenProjectPathSample"; var project = TestProjectsRepository.EnsureRestoredSolution("DthTestProjects") .GetProject(projectName); using (var server = sdk.Dth.CreateServer()) using (var client = server.CreateClient()) { // After restore the project is copied to another place so that // the relative path in project lock file is invalid. var movedProjectPath = Path.Combine(TestUtils.GetTempTestFolder <DthStartupTests>(sdk), projectName); TestUtils.CopyFolder(project.ProjectDirectory, movedProjectPath); client.Initialize(movedProjectPath, protocolVersion: 1); var error = client.DrainTillFirst("DependencyDiagnostics") .RetrieveDependencyDiagnosticsCollection() .RetrieveDependencyDiagnosticsErrorAt <JValue>(0); Assert.Contains("error NU1002", error.Value <string>()); client.DrainTillFirst("Dependencies") .RetrieveDependency("EmptyLibrary") .AssertProperty("Name", "EmptyLibrary") .AssertProperty("Resolved", false); TestUtils.CleanUpTestDir <DthStartupTests>(sdk); } }
public void DthCompilation_GetDiagnostics_OnEmptyConsoleApp(DnxSdk sdk, int protocolVersion) { using (var server = sdk.Dth.CreateServer()) using (var client = server.CreateClient()) { var solution = TestProjectsRepository.EnsureRestoredSolution("DthTestProjects"); var project = solution.GetProject("EmptyConsoleApp"); // Drain the inital messages client.Initialize(project.ProjectDirectory, protocolVersion); client.SendPayLoad(project, "GetDiagnostics"); var diagnosticsGroup = client.DrainTillFirst("AllDiagnostics") .EnsureSource(server, client) .RetrievePayloadAs <JArray>() .AssertJArrayCount(3); foreach (var group in diagnosticsGroup) { group.AsJObject() .AssertProperty <JArray>("Errors", errorsArray => !errorsArray.Any()) .AssertProperty <JArray>("Warnings", warningsArray => !warningsArray.Any()); } TestUtils.CleanUpTestDir <DthStartupTests>(sdk); } }
public async Task TestDiscovery(DnxSdk sdk) { using (var server = sdk.Dth.CreateServer()) using (var client = server.CreateClient()) { var solution = TestProjectsRepository.EnsureRestoredSolution("DthTestProjects"); var project = solution.GetProject("EmptyConsoleApp"); client.Initialize(project.ProjectDirectory); client.DrainMessage(7); var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(new IPEndPoint(IPAddress.Loopback, server.Port)); var stream = new NetworkStream(socket); var compiler = new DesignTimeHostCompiler(stream); client.SendPayLoad(1, DthMessageTypes.EnumerateProjectContexts); var target = new CompilationTarget("EmptyConsoleApp", VersionUtility.ParseFrameworkName("dnx451"), "Debug", aspect: null); var response = await compiler.Compile(project.ProjectDirectory, target); Assert.NotNull(response); Assert.Empty(response.Diagnostics); Assert.NotEmpty(response.AssemblyBytes); } }
public void DthCompilation_Initialize_UnresolvedDependency(DnxSdk sdk, int protocolVersion, string referenceType, string testProjectName, string expectedUnresolvedDependency, string expectedUnresolvedType) { using (var server = sdk.Dth.CreateServer()) using (var client = server.CreateClient()) { var solution = TestProjectsRepository.EnsureRestoredSolution("DthTestProjects"); var project = solution.GetProject(testProjectName); client.Initialize(project.ProjectDirectory, protocolVersion); var unresolveDependency = client.DrainTillFirst("Dependencies") .EnsureSource(server, client) .RetrieveDependency(expectedUnresolvedDependency); unresolveDependency.AssertProperty("Name", expectedUnresolvedDependency) .AssertProperty("DisplayName", expectedUnresolvedDependency) .AssertProperty("Resolved", false) .AssertProperty("Type", expectedUnresolvedType); if (expectedUnresolvedType == "Project") { unresolveDependency.AssertProperty("Path", Path.Combine(Path.GetDirectoryName(project.ProjectDirectory), expectedUnresolvedDependency, Project.ProjectFileName)); } else { Assert.False(unresolveDependency["Path"].HasValues); } var referencesMessage = client.DrainTillFirst("References") .EnsureSource(server, client); if (referenceType == "Project") { var expectedUnresolvedProjectPath = Path.Combine(Path.GetDirectoryName(project.ProjectDirectory), expectedUnresolvedDependency, Project.ProjectFileName); referencesMessage.RetrievePayloadAs <JObject>() .RetrievePropertyAs <JArray>("ProjectReferences") .AssertJArrayCount(1) .RetrieveArraryElementAs <JObject>(0) .AssertProperty("Name", expectedUnresolvedDependency) .AssertProperty("Path", expectedUnresolvedProjectPath) .AssertProperty <JToken>("WrappedProjectPath", prop => !prop.HasValues); } else if (referenceType == "Package") { referencesMessage.RetrievePayloadAs <JObject>() .RetrievePropertyAs <JArray>("ProjectReferences") .AssertJArrayCount(0); } TestUtils.CleanUpTestDir <DthStartupTests>(sdk); } }