Example #1
0
        private static void SetupStaticTestProject()
        {
            AssetsRoot = Path.Combine(AppContext.BaseDirectory, "bin");
            RestoredTestProjectDirectory = Path.Combine(AssetsRoot, s_testdirName);

            // Ignore Delete Failure
            try
            {
                Directory.Delete(RestoredTestProjectDirectory, true);
            }
            catch (Exception) { }

            Directory.CreateDirectory(RestoredTestProjectDirectory);

            // Todo: this is a hack until corefx is on nuget.org remove this After RC 2 Release
            NuGetConfig.Write(RestoredTestProjectDirectory);

            var newCommand = new NewCommand();
            newCommand.WorkingDirectory = RestoredTestProjectDirectory;
            newCommand.Execute().Should().Pass();

            var restoreCommand = new RestoreCommand();
            restoreCommand.WorkingDirectory = RestoredTestProjectDirectory;
            restoreCommand.Execute().Should().Pass();
        }
Example #2
0
        public void CrossPublishingSucceedsAndHasExpectedArtifacts()
        {            
            TestInstance instance = TestAssetsManager.CreateTestInstance(Path.Combine("PortableTests"));

            var testProject = Path.Combine(instance.TestRoot, "StandaloneApp", "project.json");
            var workingDirectory = Path.GetDirectoryName(testProject);
            var testNugetCache = Path.Combine(workingDirectory, "packages_cross_publish_test");

            var restoreCommand = new RestoreCommand();

            restoreCommand.WorkingDirectory = workingDirectory;            

            restoreCommand.Environment["NUGET_PACKAGES"] = testNugetCache;
            restoreCommand.Execute().Should().Pass();

            foreach (var testData in CrossPublishTestData)
            {
                var buildCommand = new BuildCommand(testProject, runtime: testData.Rid);

                buildCommand.WorkingDirectory = Path.GetDirectoryName(testProject);
                buildCommand.Environment["NUGET_PACKAGES"] = testNugetCache;
                buildCommand.Execute().Should().Pass();

                var publishCommand = new PublishCommand(testProject, runtime: testData.Rid, noBuild: true);
                publishCommand.Environment["NUGET_PACKAGES"] = testNugetCache;
                publishCommand.WorkingDirectory = Path.GetDirectoryName(testProject);
                publishCommand.Execute().Should().Pass();

                var publishedDir = publishCommand.GetOutputDirectory();
                publishedDir.Should().HaveFile("StandaloneApp"+ testData.HostExtension);

                foreach (var artifact in testData.ExpectedArtifacts)
                {
                    publishedDir.Should().HaveFile(artifact);
                }
            }
        }
Example #3
0
 private void RunRestore(string args)
 {
     var restoreCommand = new RestoreCommand();
     restoreCommand.Execute($"--quiet {args}").Should().Pass();
 }
Example #4
0
        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);
            }
        }
Example #5
0
        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);
            }
        }
Example #6
0
        private void App_WithSelfReferencingDependency_FailsBuild()
        {
            var testAssetsManager = GetTestGroupTestAssetsManager("NonRestoredTestProjects");
            var testInstance = testAssetsManager.CreateTestInstance("TestProjectWithSelfReferencingDependency")
                                                .WithLockFiles();

            var restoreResult = new RestoreCommand() { WorkingDirectory = testInstance.TestRoot }.ExecuteWithCapturedOutput();
            restoreResult.Should().Fail();
            restoreResult.StdOut.Should().Contain("error: Cycle detected");
        }
Example #7
0
        public void UnresolvedReferenceCausesBuildToFailAndNotProduceOutput()
        {
            var testAssetsManager = GetTestGroupTestAssetsManager("NonRestoredTestProjects");
            var testInstance = testAssetsManager.CreateTestInstance("TestProjectWithUnresolvedDependency")
                                                .WithLockFiles();

            var restoreResult = new RestoreCommand() { WorkingDirectory = testInstance.TestRoot }.Execute();
            restoreResult.Should().Fail();
            new DirectoryInfo(testInstance.TestRoot).Should().HaveFile("project.lock.json");

            var buildCmd = new BuildCommand(testInstance.TestRoot);
            var buildResult = buildCmd.ExecuteWithCapturedOutput();
            buildResult.Should().Fail();

            buildResult.StdErr.Should().Contain("The dependency ThisIsNotARealDependencyAndIfSomeoneGoesAndAddsAProjectWithThisNameIWillFindThemAndPunishThem could not be resolved.");

            var outputDir = new DirectoryInfo(Path.Combine(testInstance.TestRoot, "bin", "Debug", "netcoreapp1.0"));
            outputDir.GetFiles().Length.Should().Be(0);
        }