Beispiel #1
0
        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);
                }
        }
Beispiel #2
0
        public void DnuRestoreInstallsIndirectDependency(DnxSdk sdk)
        {
            // SimpleChain -> DependencyA -> DependencyB
            const string feedSolutionName    = "DependencyGraphsFeed";
            const string projectSolutionName = "DependencyGraphsProject";
            const string projectName         = "SimpleChain";

            var feedSolution = TestUtils.GetSolution <DnuRestoreTests>(sdk, feedSolutionName, appendSolutionNameToTestFolder: true);
            var localFeed    = TestUtils.CreateLocalFeed <DnuRestoreTests>(sdk, feedSolution);

            var projectSolution = TestUtils.GetSolution <DnuRestoreTests>(sdk, projectSolutionName, appendSolutionNameToTestFolder: true);
            var project         = projectSolution.GetProject(projectName);
            var packagesDir     = Path.Combine(project.ProjectDirectory, "packages");

            var result = sdk.Dnu.Restore(
                project.ProjectDirectory,
                packagesDir,
                feeds: new [] { localFeed });

            result.EnsureSuccess();

            Assert.Empty(result.StandardError);
            Assert.Contains($"Installing DependencyA.1.0.0", result.StandardOutput);
            Assert.Contains($"Installing DependencyB.2.0.0", result.StandardOutput);
            Assert.True(Directory.Exists(Path.Combine(packagesDir, "DependencyA", "1.0.0")));
            Assert.True(Directory.Exists(Path.Combine(packagesDir, "DependencyB", "2.0.0")));

            TestUtils.CleanUpTestDir <DnuRestoreTests>(sdk);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        public void DnuPublishWebApp_SubdirAsPublicDir_DirPlusFlatList(DnxSdk sdk)
        {
            const string projectName = "ProjectForTesting";

            FrameworkName[] frameworkCandidates =
            {
                FrameworkNameHelper.ParseFrameworkName("dnx451"),
                FrameworkNameHelper.ParseFrameworkName("dnxcore50")
            };

            var targetFramework = DependencyContext.SelectFrameworkNameForRuntime(
                frameworkCandidates, sdk.FullName).FullName;

            var projectJson = new JObject
            {
                ["publishExclude"] = "**.useless",
                ["webroot"]        = "public",
                ["frameworks"]     = new JObject
                {
                    ["dnx451"]    = new JObject {
                    },
                    ["dnxcore50"] = new JObject {
                    }
                }
            };

            var projectStructure = new Dir
            {
Beispiel #5
0
        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);
                }
        }
Beispiel #6
0
        public void DnuPack_ClientProfile(DnxSdk sdk)
        {
            const string ProjectName      = "ClientProfileProject";
            var          projectStructure = new Dir
            {
                [ProjectName] = new Dir
                {
                    ["project.json"] = new JObject
                    {
                        ["frameworks"] = new JObject
                        {
                            ["net40-client"] = new JObject(),
                            ["net35-client"] = new JObject()
                        }
                    }
                },
                ["Output"] = new Dir()
            };

            var baseDir    = TestUtils.GetTestFolder <DnuPackTests>(sdk);
            var projectDir = Path.Combine(baseDir, ProjectName);
            var outputDir  = Path.Combine(baseDir, "Output");

            projectStructure.Save(baseDir);

            sdk.Dnu.Restore(projectDir).EnsureSuccess();
            var result = sdk.Dnu.Pack(projectDir, outputDir);

            Assert.Equal(0, result.ExitCode);
        }
Beispiel #7
0
        public void ComparisonTest(DnxSdk sdk)
        {
            var file1a = new JObject
            {
                ["info"] = "foo"
            };

            var file1b = new JObject
            {
                ["info"] = "bar1"
            };

            var project1 = new Dir
            {
                ["file1"] = file1a,
                ["file2"] = file1b
            };

            var file2a = new JObject
            {
                ["info"] = "foo"
            };

            var file2b = new JObject
            {
                ["info"] = "bar2"
            };

            var project2 = new Dir
            {
                ["file1"] = file2a,
                ["file2"] = file2b
            };

            var project3 = new Dir
            {
                ["file1"] = file2a,
                ["file2"] = new DirItem(Dir.EmptyFile, skipComparison: true)
            };

            var project4 = new Dir
            {
                ["subdir1"] = project1,
                ["subdir2"] = project1
            };

            var project5 = new Dir
            {
                ["subdir1"] = new DirItem(project2, skipComparison: true),
                ["subdir2"] = project2
            };

            DirAssert.Equal(project1, project2, compareContents: false);
            DirAssert.Equal(project1, project3, compareContents: false);
            DirAssert.Equal(project1, project3);
            DirAssert.Equal(project2, project3);
            //DirAssert.Equal(project4, project5); // this should fail, but only subdir2 should be different

            TestUtils.CleanUpTestDir <DnuPublishTests>(sdk);
        }
Beispiel #8
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);
                    }
                }
        }
Beispiel #9
0
        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));
                }
        }
Beispiel #10
0
        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);
        }
Beispiel #11
0
        public void DthDependencies_UpdateGlobalJson_RefreshDependencies(DnxSdk sdk)
        {
            using (var server = sdk.Dth.CreateServer())
                using (var client = server.CreateClient())
                {
                    var solution = TestUtils.GetSolution <DthStartupTests>(sdk, "DthUpdateSearchPathSample");

                    var root = Path.Combine(solution.RootPath, "home");
                    sdk.Dnu.Restore(root).EnsureSuccess();

                    var testProject = Path.Combine(root, "src", "MainProject");

                    client.Initialize(testProject, protocolVersion: 2);

                    client.DrainTillFirst("ProjectInformation")
                    .RetrievePayloadAs <JObject>()
                    .RetrievePropertyAs <JArray>("ProjectSearchPaths")
                    .AssertJArrayCount(2);

                    client.DrainTillFirst("DependencyDiagnostics")
                    .RetrievePayloadAs <JObject>()
                    .AssertProperty <JArray>("Errors", array => array.Count == 0)
                    .AssertProperty <JArray>("Warnings", array => array.Count == 0);

                    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.");

                    // 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");

                    client.DrainTillFirst("ProjectInformation")
                    .RetrievePayloadAs <JObject>()
                    .RetrievePropertyAs <JArray>("ProjectSearchPaths")
                    .AssertJArrayCount(1)
                    .AssertJArrayElement(0, Path.Combine(root, "src"));

                    client.DrainTillFirst("DependencyDiagnostics")
                    .RetrieveDependencyDiagnosticsCollection()
                    .RetrieveDependencyDiagnosticsErrorAt <JObject>(0)
                    .AssertProperty("ErrorCode", "NU1010");

                    client.DrainTillFirst("Dependencies")
                    .RetrieveDependency("Newtonsoft.Json")
                    .AssertProperty("Type", LibraryTypes.Unresolved)
                    .AssertProperty("Resolved", false)
                    .RetrievePropertyAs <JArray>("Errors")
                    .AssertJArrayCount(1)
                    .RetrieveArraryElementAs <JObject>(0)
                    .AssertProperty("ErrorCode", "NU1010");

                    TestUtils.CleanUpTestDir <DthStartupTests>(sdk);
                }
        }
Beispiel #12
0
        public void Restore_PackageOverProjectTarget(DnxSdk sdk)
        {
            var solution    = TestUtils.GetSolution <DnuRestoreTests2>(sdk, "DependencyTargets");
            var bOutputPath = Path.Combine(solution.ArtifactsPath, "B");

            // Build a package for B
            sdk.Dnu.Restore(solution.GetProject("A")).EnsureSuccess();
            sdk.Dnu.Restore(solution.GetProject("B")).EnsureSuccess();
            sdk.Dnu.Pack(
                solution.GetProject("B").ProjectDirectory,
                bOutputPath,
                configuration: "package").EnsureSuccess();
            sdk.Dnu.PackagesAdd(
                Path.Combine(bOutputPath, "package", "B.1.0.0.nupkg"),
                solution.LocalPackagesDir).EnsureSuccess();

            // Restore the app, it'll work but it will choose the package over the project
            sdk.Dnu.Restore(solution.GetProject("App")).EnsureSuccess();

            // Run the app
            var result = sdk.Dnx.Execute(solution.GetProject("App"));

            Assert.Equal(@"A: This is Project A
B: This is Package B
", result.StandardOutput);
        }
Beispiel #13
0
        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);
                }
        }
Beispiel #14
0
        public void DthCompilation_RestoreComplete_OnEmptyLibrary(DnxSdk sdk, int protocolVersion)
        {
            using (var server = sdk.Dth.CreateServer())
                using (var client = server.CreateClient())
                {
                    var solution = TestUtils.GetSolution <DthStartupTests>(sdk, "DthTestProjects");
                    var project  = solution.GetProject("EmptyLibrary");

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

                    // Drain the inital messages
                    client.Initialize(project.ProjectDirectory, protocolVersion);

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

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

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

                    client.SendPayLoad(project, "RestoreComplete");

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

                    TestUtils.CleanUpTestDir <DthStartupTests>(sdk);
                }
        }
Beispiel #15
0
        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);
                }
        }
Beispiel #16
0
        public void Restore_ProjectOverPackageTarget(DnxSdk sdk)
        {
            var solution    = TestUtils.GetSolution <DnuRestoreTests2>(sdk, "DependencyTargets");
            var aOutputPath = Path.Combine(solution.ArtifactsPath, "A");

            sdk.Dnu.Restore(solution.GetProject("B")).EnsureSuccess();

            // Build a package for A
            sdk.Dnu.Restore(solution.GetProject("A")).EnsureSuccess();
            sdk.Dnu.Pack(
                solution.GetProject("A").ProjectDirectory,
                aOutputPath,
                configuration: "package").EnsureSuccess();
            sdk.Dnu.PackagesAdd(
                Path.Combine(aOutputPath, "package", "A.1.0.0.nupkg"),
                solution.LocalPackagesDir).EnsureSuccess();

            // Delete the project A
            CommonTestUtils.TestUtils.DeleteFolder(solution.GetProject("A").ProjectDirectory);

            // Restore the app, it should fail because the project is gone!
            var result = sdk.Dnu.Restore(solution.GetProject("App"));

            Assert.NotEqual(0, result.ExitCode);
            Assert.Contains("Unable to locate Project A", result.StandardError);
        }
Beispiel #17
0
        public void DnuRestoreInstallsIndirectDependency(DnxSdk sdk)
        {
            // SimpleChain -> DependencyA -> DependencyB
            const string feedSolutionName = "DependencyGraphsFeed";
            const string projectSolutionName = "DependencyGraphsProject";
            const string projectName = "SimpleChain";

            var feedSolution = TestUtils.GetSolution<DnuRestoreTests>(sdk, feedSolutionName, appendSolutionNameToTestFolder: true);
            var localFeed = TestUtils.CreateLocalFeed<DnuRestoreTests>(sdk, feedSolution);

            var projectSolution = TestUtils.GetSolution<DnuRestoreTests>(sdk, projectSolutionName, appendSolutionNameToTestFolder: true);
            var project = projectSolution.GetProject(projectName);
            var packagesDir = Path.Combine(project.ProjectDirectory, "packages");

            var result = sdk.Dnu.Restore(
                project.ProjectDirectory,
                packagesDir,
                feeds: new [] { localFeed });
            result.EnsureSuccess();

            Assert.Empty(result.StandardError);
            Assert.Contains($"Installing DependencyA.1.0.0", result.StandardOutput);
            Assert.Contains($"Installing DependencyB.2.0.0", result.StandardOutput);
            Assert.True(Directory.Exists(Path.Combine(packagesDir, "DependencyA", "1.0.0")));
            Assert.True(Directory.Exists(Path.Combine(packagesDir, "DependencyB", "2.0.0")));

            TestUtils.CleanUpTestDir<DnuRestoreTests>(sdk);
        }
Beispiel #18
0
        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();
                }
        }
Beispiel #19
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);
                    }
        }
Beispiel #20
0
        public void ComparisonTest(DnxSdk sdk)
        {
            var file1a = new JObject
            {
                ["info"] = "foo"
            };

            var file1b = new JObject
            {
                ["info"] = "bar1"
            };

            var project1 = new Dir
            {
                ["file1"] = file1a,
                ["file2"] = file1b
            };

            var file2a = new JObject
            {
                ["info"] = "foo"
            };

            var file2b = new JObject
            {
                ["info"] = "bar2"
            };

            var project2 = new Dir
            {
                ["file1"] = file2a,
                ["file2"] = file2b
            };

            var project3 = new Dir
            {
                ["file1"] = file2a,
                ["file2"] = new DirItem(Dir.EmptyFile, skipComparison: true)
            };

            var project4 = new Dir
            {
                ["subdir1"] = project1,
                ["subdir2"] = project1
            };

            var project5 = new Dir
            {
                ["subdir1"] = new DirItem(project2, skipComparison: true),
                ["subdir2"] = project2
            };

            DirAssert.Equal(project1, project2, compareContents: false);
            DirAssert.Equal(project1, project3, compareContents: false);
            DirAssert.Equal(project1, project3);
            DirAssert.Equal(project2, project3);
            //DirAssert.Equal(project4, project5); // this should fail, but only subdir2 should be different

            TestUtils.CleanUpTestDir<DnuPublishTests>(sdk);
        }
Beispiel #21
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);
                }
        }
Beispiel #22
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");
                    }
        }
Beispiel #23
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());
                    }
                }
        }
Beispiel #24
0
        public void PublishWrappedProjectForSpecificFramework(DnxSdk sdk)
        {
            var solutionName = Path.Combine("DnuWrapTestSolutions", "WrapAndPublish");
            var solution     = TestUtils.GetSolution <DnuPublishTests2>(sdk, solutionName);

            // Restore the wrapper project
            sdk.Dnu.Restore(solution.GetWrapperProjectPath("ClassLibrary")).EnsureSuccess();
            sdk.Dnu.Restore(solution.GetProject("DnxConsoleApp")).EnsureSuccess();

            // Build the console app in Debug mode (we specify the config explicitly since dnx here defaults to a Debug
            // build but on the CI we might have the Configuration environment variable set so that MSBuild builds as Release by default).
            var msbuild = CommonTestUtils.TestUtils.ResolveMSBuildPath();

            Exec.Run(msbuild, "/p:Configuration=Debug", workingDir: Path.Combine(solution.SourcePath, "ClassLibrary")).EnsureSuccess();;

            // Publish the console app
            sdk.Dnu.Publish(solution.GetProject("DnxConsoleApp").ProjectFilePath, solution.ArtifactsPath, "--framework dnx451").EnsureSuccess();

            // Get an SDK we can use the RUN the wrapped project (it has to be CLR because the project only supports dnx451)
            var clrSdk = GetRuntime("clr", "win", "x86");

            // Run it
            var outputPath = Path.Combine(solution.ArtifactsPath, "approot", "src", "DnxConsoleApp");
            var result     = clrSdk.Dnx.Execute(
                commandLine: $"--project \"{outputPath}\" --configuration Debug DnxConsoleApp run")
                             .EnsureSuccess();

            Assert.Contains($"Hello from the wrapped project{Environment.NewLine}", result.StandardOutput);
        }
Beispiel #25
0
        public void Restore_NormalizesVersionCasing(DnxSdk sdk)
        {
            var solution = TestUtils.GetSolution <DnuRestoreTests>(sdk, "MismatchedVersionCasing");

            var result = sdk.Dnu.Restore(solution.GetProject("A"));

            Assert.Equal(0, result.ExitCode);
        }
Beispiel #26
0
        public void FailTest(DnxSdk sdk)
        {
            var feedSolution = TestUtils.GetSolution<DnuCommonUtilTests>(sdk, "DependencyGraphsProject");

            //Assert.True(false);

            TestUtils.CleanUpTestDir<DnuCommonUtilTests>(sdk);
        }
Beispiel #27
0
        public void FailTest(DnxSdk sdk)
        {
            var feedSolution = TestUtils.GetSolution <DnuCommonUtilTests>(sdk, "DependencyGraphsProject");

            //Assert.True(false);

            TestUtils.CleanUpTestDir <DnuCommonUtilTests>(sdk);
        }
Beispiel #28
0
        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);
                }
        }
Beispiel #29
0
        public void UnresolvedProjectDoesNotThrow(DnxSdk sdk)
        {
            const string solutionName = "BootstrapperSolution";
            var          solution     = TestUtils.GetSolution <BootstrapperTests>(sdk, solutionName);

            var result = sdk.Dnx.Execute($"--project {solution.RootPath} run");

            Assert.NotEqual(0, result.ExitCode);
            Assert.Equal($"Error: Unable to resolve project from {solution.RootPath}{Environment.NewLine}", result.StandardError);
        }
Beispiel #30
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);
                    }
                }
        }
Beispiel #31
0
        public BootstrapperTestFixture()
        {
            Console.WriteLine($@"
Environment information:
  DNX_HOME: {Environment.GetEnvironmentVariable("DNX_HOME")}
  DNX_SDK_VERSION_FOR_TESTING: {Environment.GetEnvironmentVariable("DNX_SDK_VERSION_FOR_TESTING")}

Information of DNX under testing:
  DNX Home: {DnxSdk.GetRuntimeHome()}
  DNX Version: {DnxSdkFunctionalTestBase.SdkVersionForTesting}
");
        }
Beispiel #32
0
        public void DthStartup_ProtocolNegotiation_ZeroIsNoAllowed(DnxSdk sdk)
        {
            using (var server = sdk.Dth.CreateServer())
                using (var client = server.CreateClient())
                {
                    client.SetProtocolVersion(0);

                    Assert.Throws <TimeoutException>(() =>
                    {
                        client.DrainTillFirst(ProtocolManager.NegotiationMessageTypeName, timeout: TimeSpan.FromSeconds(1));
                    });
                }
        }
Beispiel #33
0
        public void PublishedAppWithWebRootFailsIfIISCommandInvalid(DnxSdk sdk)
        {
            // Arrange
            var solution   = TestUtils.GetSolution <DnuPublishTests2>(sdk, "HelloWorldWithWebRoot");
            var outputPath = Path.Combine(solution.RootPath, "Output");
            var project    = solution.GetProject("HelloWorldWithWebRoot");

            // Act
            sdk.Dnu.Restore(project).EnsureSuccess();
            var result = sdk.Dnu.Publish(project.ProjectDirectory, outputPath, $"--iis-command SomethingRandom");

            Assert.NotEqual(0, result.ExitCode);
        }
Beispiel #34
0
        public void DnuPublishWebApp_SubdirAsPublicDir_DirPlusFlatList(DnxSdk sdk)
        {
            const string projectName = "ProjectForTesting";
            FrameworkName[] frameworkCandidates = {
                FrameworkNameHelper.ParseFrameworkName("dnx451"),
                FrameworkNameHelper.ParseFrameworkName("dnxcore50")
            };

            var targetFramework = DependencyContext.SelectFrameworkNameForRuntime(
                frameworkCandidates, sdk.FullName).FullName;

            var projectJson = new JObject
            {
                ["publishExclude"] = "**.useless",
                ["webroot"] = "public",
                ["frameworks"] = new JObject
                {
                    ["dnx451"] = new JObject { },
                    ["dnxcore50"] = new JObject { }
                }
            };

            var projectStructure = new Dir
            {