예제 #1
0
        public void DthCompilation_RestoreComplete_OnEmptyLibrary(DnxSdk sdk, int protocolVersion)
        {
            var projectName = "EmptyLibrary";

            string testProject;

            using (_fixture.CreateDisposableTestProject(projectName, sdk, out testProject))
                using (var server = DthTestServer.Create(sdk))
                    using (var client = server.CreateClient())
                    {
                        // Drain the inital messages
                        client.Initialize(testProject, protocolVersion);

                        client.DrainTillFirst("Dependencies")
                        .EnsureSource(server, client)
                        .EnsureNotContainDependency("System.Console");

                        File.Copy(Path.Combine(testProject, "project-update.json"),
                                  Path.Combine(testProject, "project.json"),
                                  overwrite: true);

                        sdk.Dnu.Restore(testProject).EnsureSuccess();

                        client.SendPayLoad(testProject, "RestoreComplete");

                        client.DrainTillFirst("Dependencies")
                        .EnsureSource(server, client)
                        .RetrieveDependency("System.Console");
                    }
        }
예제 #2
0
        public void DthStartup_GetProjectInformation(DnxSdk sdk)
        {
            var projectName = "EmptyConsoleApp";
            var testProject = _fixture.GetTestProjectPath(projectName);

            using (var server = DthTestServer.Create(sdk))
                using (var client = new DthTestClient(server))
                {
                    client.Initialize(testProject);

                    var projectInformation = client.DrainAllMessages()
                                             .RetrieveSingleMessage("ProjectInformation")
                                             .EnsureSource(server, client)
                                             .RetrievePayloadAs <JObject>()
                                             .AssertProperty("Name", projectName);

                    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);
                }
        }
예제 #3
0
        public void CompileModuleWithDeps(DnxSdk sdk)
        {
            // Arrange
            var solution = TestUtils.GetSolution <DthStartupTests>(sdk, "CompileModuleWithDependencies");
            var project  = solution.GetProject("A");

            using (var server = DthTestServer.Create(sdk))
                using (var client = server.CreateClient())
                {
                    sdk.Dnu.Restore(solution.RootPath).EnsureSuccess();

                    client.Initialize(project.ProjectDirectory);

                    client.SendPayLoad(project, "GetDiagnostics");

                    var messages = client.DrainAllMessages();


                    // Assert
                    messages.AssertDoesNotContain("Error");

                    var diagnosticsPerFramework = messages.RetrieveSingleMessage("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);
                    }
                }
        }
예제 #4
0
        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);
                    }
        }
예제 #5
0
        public void DthCompilation_GetDiagnostics_OnEmptyConsoleApp(DnxSdk sdk, int protocolVersion)
        {
            var projectName = "EmptyConsoleApp";
            var testProject = _fixture.GetTestProjectPath(projectName);

            using (var server = DthTestServer.Create(sdk))
                using (var client = server.CreateClient())
                {
                    // Drain the inital messages
                    client.Initialize(testProject, protocolVersion);
                    client.SendPayLoad(testProject, "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());
                    }
                }
        }
예제 #6
0
        public void DthStartup_GetProjectInformation(string flavor, string os, string architecture)
        {
            var projectName     = "EmptyConsoleApp";
            var runtimeHomePath = _fixture.GetRuntimeHomeDir(flavor, os, architecture);
            var testProject     = _fixture.GetTestProjectPath(projectName);

            using (var server = DthTestServer.Create(runtimeHomePath, testProject))
                using (var client = new DthTestClient(server, 0))
                {
                    client.Initialize(testProject);

                    var response = client.GetResponse <ProjectMessage>();
                    Assert.NotNull(response);
                    Assert.Equal(server.HostId, response.HostId);
                    Assert.Equal(0, response.ContextId);
                    Assert.Equal("ProjectInformation", response.MessageType);

                    var projectInfo = response.Payload;
                    Assert.Equal(projectName, projectInfo.Name);
                    Assert.Equal(2, projectInfo.Configurations.Count);
                    Assert.Contains("Debug", projectInfo.Configurations);
                    Assert.Contains("Release", projectInfo.Configurations);

                    var frameworkShorNames = projectInfo.Frameworks.Select(f => f.ShortName);
                    Assert.Equal(3, frameworkShorNames.Count());
                    Assert.Contains("dnxcore50", frameworkShorNames);
                    Assert.Contains("dnx451", frameworkShorNames);
                    Assert.Contains("net46", frameworkShorNames);
                }
        }
예제 #7
0
        public void DthCompilation_Initialize_UnresolvedDependency(DnxSdk sdk, int protocolVersion, string referenceType, string testProjectName,
                                                                   string expectedUnresolvedDependency, string expectedUnresolvedType)
        {
            var testProject = _fixture.GetTestProjectPath(testProjectName);

            using (var server = DthTestServer.Create(sdk))
                using (var client = server.CreateClient())
                {
                    client.Initialize(testProject, protocolVersion);

                    var messages = client.DrainAllMessages();

                    var unresolveDependency = messages.RetrieveSingleMessage("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(testProject), expectedUnresolvedDependency, Project.ProjectFileName));
                    }
                    else
                    {
                        Assert.False(unresolveDependency["Path"].HasValues);
                    }

                    var referencesMessage = messages.RetrieveSingleMessage("References")
                                            .EnsureSource(server, client);

                    if (referenceType == "Project")
                    {
                        var expectedUnresolvedProjectPath = Path.Combine(Path.GetDirectoryName(testProject), 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);
                    }
                }
        }
예제 #8
0
        public void DthStartup_ProtocolNegotiation_ZeroIsNoAllowed(DnxSdk sdk)
        {
            var projectName = "EmptyConsoleApp";
            var testProject = _fixture.GetTestProjectPath(projectName);

            using (var server = DthTestServer.Create(sdk))
                using (var client = server.CreateClient())
                {
                    client.SetProtocolVersion(0);

                    Assert.Throws <TimeoutException>(() =>
                    {
                        client.DrainTillFirst(ProtocolManager.NegotiationMessageTypeName);
                    });
                }
        }
예제 #9
0
        public void DthStartup_ProtocolNegotiation(DnxSdk sdk, int requestVersion, int expectVersion)
        {
            var projectName = "EmptyConsoleApp";
            var testProject = _fixture.GetTestProjectPath(projectName);

            using (var server = DthTestServer.Create(sdk))
                using (var client = server.CreateClient())
                {
                    client.SetProtocolVersion(requestVersion);

                    var response = client.DrainTillFirst(ProtocolManager.NegotiationMessageTypeName);
                    response.EnsureSource(server, client);

                    Assert.Equal(expectVersion, response.Payload["Version"]?.Value <int>());
                }
        }
예제 #10
0
파일: Dth.cs 프로젝트: yossidev/dnx
 public DthTestServer CreateServer(TimeSpan timeout)
 {
     return(DthTestServer.Create(_sdkPath, timeout));
 }
예제 #11
0
        public void AddDepsReturnsReferences(DnxSdk sdk)
        {
            // Arrange
            var solution = TestUtils.GetSolution <DthStartupTests>(sdk, "HelloWorld");
            var project  = solution.GetProject("HelloWorld");

            using (var server = DthTestServer.Create(sdk))
                using (var client = server.CreateClient())
                {
                    sdk.Dnu.Restore(solution.RootPath).EnsureSuccess();

                    client.SetProtocolVersion(3);

                    client.Initialize(project.ProjectDirectory);

                    var messages = client.DrainAllMessages();

                    foreach (var frameworkInfo in project.GetTargetFrameworks())
                    {
                        var messagesByFramework = messages.GetMessagesByFramework(frameworkInfo.FrameworkName);

                        messagesByFramework.RetrieveSingleMessage("Dependencies")
                        .RetrieveDependency("Newtonsoft.Json")
                        .AssertProperty("Type", LibraryTypes.Package);

                        var references = messagesByFramework.RetrieveSingleMessage("References")
                                         .RetrievePayloadAs <JObject>()
                                         .RetrievePropertyAs <JArray>("FileReferences");

                        Assert.NotEmpty(references);
                        Assert.Contains("Newtonsoft.Json", references.Select(r => Path.GetFileNameWithoutExtension(r.Value <string>())));
                    }

                    // Update dependencies
                    project = project.UpdateProjectFile(json =>
                    {
                        json["dependencies"]["DoesNotExist"] = "1.0.0";
                    });

                    client.SendPayLoad(project, "FilesChanged");

                    messages = client.DrainAllMessages();

                    foreach (var frameworkInfo in project.GetTargetFrameworks())
                    {
                        var messagesByFramework = messages.GetMessagesByFramework(frameworkInfo.FrameworkName);

                        var dependencies = messagesByFramework.RetrieveSingleMessage("Dependencies");

                        dependencies.RetrieveDependency("Newtonsoft.Json")
                        .AssertProperty("Type", LibraryTypes.Package);

                        dependencies.RetrieveDependency("DoesNotExist")
                        .AssertProperty("Type", LibraryTypes.Unresolved);

                        // The references should not have changed
                        messagesByFramework.AssertDoesNotContain("References");
                    }

                    client.SendPayLoad(project, "GetDiagnostics");

                    messages = client.DrainAllMessages();

                    var diagnosticsPerFramework = messages.RetrieveSingleMessage("AllDiagnostics")
                                                  .RetrievePayloadAs <JArray>()
                                                  .AssertJArrayCount(3);

                    foreach (var frameworkDiagnostics in diagnosticsPerFramework)
                    {
                        if (!frameworkDiagnostics["Framework"].HasValues)
                        {
                            continue;
                        }

                        var errors   = frameworkDiagnostics.Value <JArray>("Errors");
                        var warnings = frameworkDiagnostics.Value <JArray>("Warnings");
                        Assert.Equal(2, errors.Count);
                        Assert.Equal(0, warnings.Count);

                        var error1 = errors[0];
                        var error2 = errors[1];

                        Assert.Equal("NU1006", error1.Value <string>("ErrorCode"));
                        Assert.Equal("NU1001", error2.Value <string>("ErrorCode"));
                        Assert.Equal("DoesNotExist", error2["Source"].Value <string>("Name"));
                    }
                }
        }
예제 #12
0
        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");
                    }
        }