コード例 #1
0
ファイル: GivenDotnetSlnList.cs プロジェクト: vladdou/cli
        public void WhenProjectReferencesArePresentInTheSolutionItListsThem()
        {
            string OutputText = $@"Project reference(s)
--------------------
{Path.Combine("App", "App.csproj")}
{Path.Combine("Lib", "Lib.csproj")}";

            var projectDirectory = TestAssets
                                   .Get("TestAppWithSlnAndExistingCsprojReferences")
                                   .CreateInstance()
                                   .WithSourceFiles()
                                   .Root
                                   .FullName;

            var cmd = new DotnetCommand()
                      .WithWorkingDirectory(projectDirectory)
                      .ExecuteWithCapturedOutput("sln list");

            cmd.Should().Pass();
            cmd.StdOut.Should().BeVisuallyEquivalentTo(OutputText);
        }
コード例 #2
0
        private void TestTemplateBuild(string templateName, bool selfContained = false)
        {
            var    directory        = TestAssets.CreateTestDirectory(identifier: templateName);
            string projectDirectory = directory.FullName;

            string newArgs = $"{templateName} --debug:ephemeral-hive --no-restore";

            new NewCommandShim()
            .WithWorkingDirectory(projectDirectory)
            .Execute(newArgs)
            .Should().Pass();

            var buildArgs  = selfContained ? "" :$"-r {RuntimeInformation.RuntimeIdentifier}";
            var dotnetRoot = Path.GetDirectoryName(RepoDirectoriesProvider.DotnetUnderTest);

            new BuildCommand()
            .WithEnvironmentVariable("PATH", dotnetRoot)      // override PATH since razor rely on PATH to find dotnet
            .WithWorkingDirectory(projectDirectory)
            .Execute(buildArgs)
            .Should().Pass();
        }
コード例 #3
0
        public void ItEscapesCommandArgumentsWhenReturningACommandSpec()
        {
            var projectToolsCommandResolver = SetupProjectToolsCommandResolver();

            var testInstance = TestAssets.Get(TestProjectName)
                               .CreateInstance()
                               .WithSourceFiles()
                               .WithRestoreFiles();

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName      = "dotnet-portable",
                CommandArguments = new[] { "arg with space" },
                ProjectDirectory = testInstance.Root.FullName
            };

            var result = projectToolsCommandResolver.Resolve(commandResolverArguments);

            result.Should().NotBeNull("Because the command is a project tool dependency");
            result.Args.Should().Contain("\"arg with space\"");
        }
コード例 #4
0
ファイル: GivenDotnetSlnList.cs プロジェクト: zsd4yr/cli
        public void WhenProjectsPresentInTheSolutionItListsThem()
        {
            var expectedOutput = $@"{CommandLocalizableStrings.ProjectsHeader}
{new string('-', CommandLocalizableStrings.ProjectsHeader.Length)}
{Path.Combine("App", "App.csproj")}
{Path.Combine("Lib", "Lib.csproj")}";

            var projectDirectory = TestAssets
                                   .Get("TestAppWithSlnAndExistingCsprojReferences")
                                   .CreateInstance()
                                   .WithSourceFiles()
                                   .Root
                                   .FullName;

            var cmd = new DotnetCommand()
                      .WithWorkingDirectory(projectDirectory)
                      .ExecuteWithCapturedOutput("sln list");

            cmd.Should().Pass();
            cmd.StdOut.Should().BeVisuallyEquivalentTo(expectedOutput);
        }
コード例 #5
0
        public void ItShouldDetectFileWithMarkOfTheWeb()
        {
            var testFile = Path.Combine(TestAssets.CreateTestDirectory().FullName, Path.GetRandomFileName());

            File.WriteAllText(testFile, string.Empty);
            AlternateStream.WriteAlternateStream(
                testFile,
                "Zone.Identifier",
                "[ZoneTransfer]\r\nZoneId=3\r\nReferrerUrl=C:\\Users\\test.zip\r\n");

            bool isTestFileDangerous = new DangerousFileDetector().IsDangerous(testFile);

            if (!HasInternetSecurityManagerNativeApi())
            {
                isTestFileDangerous.Should().BeFalse("Locked down version of Windows does not have IE to download files");
            }
            else
            {
                isTestFileDangerous.Should().BeTrue();
            }
        }
コード例 #6
0
        public void GenerateDepsJsonMethodDoesntOverwriteWhenDepsFileAlreadyExists()
        {
            var testInstance = TestAssets.Get(TestProjectName)
                               .CreateInstance()
                               .WithSourceFiles()
                               .WithRestoreFiles();

            var repoDirectoriesProvider = new RepoDirectoriesProvider();

            var nugetPackagesRoot = repoDirectoriesProvider.NugetPackages;

            var toolPathCalculator = new ToolPathCalculator(nugetPackagesRoot);

            var lockFilePath = toolPathCalculator.GetLockFilePath(
                "dotnet-portable",
                new NuGetVersion("1.0.0"),
                s_toolPackageFramework);

            var lockFile = new LockFileFormat().Read(lockFilePath);

            var depsJsonFile = Path.Combine(
                Path.GetDirectoryName(lockFilePath),
                "dotnet-portable.deps.json");

            if (File.Exists(depsJsonFile))
            {
                File.Delete(depsJsonFile);
            }
            File.WriteAllText(depsJsonFile, "temp");

            var projectToolsCommandResolver = SetupProjectToolsCommandResolver();

            projectToolsCommandResolver.GenerateDepsJsonFile(
                lockFile,
                depsJsonFile,
                new SingleProjectInfo("dotnet-portable", "1.0.0", Enumerable.Empty <ResourceAssemblyInfo>()));

            File.ReadAllText(depsJsonFile).Should().Be("temp");
            File.Delete(depsJsonFile);
        }
コード例 #7
0
        public void TemplateRestoresAndBuildsWithoutWarnings(
            string language,
            string projectType,
            bool useNuGetConfigForAspNet,
            bool skipSpaWebpackSteps)
        {
            string rootPath = TestAssets.CreateTestDirectory(identifier: $"{language}_{projectType}").FullName;

            new TestCommand("dotnet")
            {
                WorkingDirectory = rootPath
            }
            .Execute($"new {projectType} -lang {language} -o {rootPath} --debug:ephemeral-hive")
            .Should().Pass();

            if (useNuGetConfigForAspNet)
            {
                var configFile = new FileInfo(Path.Combine(rootPath, "..", "..", "..", "..", "..", "NuGet.tempaspnetpatch.config"));
                File.Copy(configFile.FullName, Path.Combine(rootPath, "NuGet.Config"));
            }

            if (skipSpaWebpackSteps)
            {
                // Not all CI machines have Node installed, so the build would fail if we tried
                // to run Webpack. Bypass this by making it appear that Webpack already ran.
                Directory.CreateDirectory(Path.Combine(rootPath, "wwwroot", "dist"));
            }

            // https://github.com/dotnet/templating/issues/946 - remove DisableImplicitAssetTargetFallback once this is fixed.
            new TestCommand("dotnet")
            .WithWorkingDirectory(rootPath)
            .Execute($"restore /p:DisableImplicitAssetTargetFallback=true")
            .Should().Pass();

            var buildResult = new TestCommand("dotnet")
                              .WithWorkingDirectory(rootPath)
                              .ExecuteWithCapturedOutput("build --no-restore")
                              .Should().Pass()
                              .And.NotHaveStdErr();
        }
コード例 #8
0
        public void ItCanNewRestoreBuildRunCleanMSBuildProject()
        {
            var    directory        = TestAssets.CreateTestDirectory();
            string projectDirectory = directory.FullName;

            string newArgs = "console --debug:ephemeral-hive --no-restore";

            new NewCommandShim()
            .WithWorkingDirectory(projectDirectory)
            .Execute(newArgs)
            .Should().Pass();

            new RestoreCommand()
            .WithWorkingDirectory(projectDirectory)
            .Execute()
            .Should().Pass();

            new BuildCommand()
            .WithWorkingDirectory(projectDirectory)
            .Execute()
            .Should().Pass();

            var runCommand = new RunCommand()
                             .WithWorkingDirectory(projectDirectory)
                             .ExecuteWithCapturedOutput()
                             // Templates are still at 3.1 and will not run on 5.0, revert to commented out assertion when 5.0 templates land
                             //.Should().Pass().And.HaveStdOutContaining("Hello World!");
                             .Should().Fail().And.HaveStdErrContaining("https://aka.ms/dotnet-core-applaunch");

            var binDirectory = new DirectoryInfo(projectDirectory).Sub("bin");

            binDirectory.Should().HaveFilesMatching("*.dll", SearchOption.AllDirectories);

            new CleanCommand()
            .WithWorkingDirectory(projectDirectory)
            .Execute()
            .Should().Pass();

            binDirectory.Should().NotHaveFilesMatching("*.dll", SearchOption.AllDirectories);
        }
コード例 #9
0
        public void MigratingDeprecatedResource()
        {
            var projectDirectory = TestAssets
                                   .GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJDeprecatedResource")
                                   .CreateInstance()
                                   .WithSourceFiles()
                                   .Root
                                   .GetDirectory("project");

            new MigrateTestCommand()
            .WithWorkingDirectory(projectDirectory)
            .Execute()
            .Should()
            .Pass();

            new DotnetCommand()
            .WithWorkingDirectory(projectDirectory)
            .Execute("restore")
            .Should()
            .Pass();

            new DotnetCommand()
            .WithWorkingDirectory(projectDirectory)
            .Execute("build -c Debug")
            .Should()
            .Pass();

            if (!EnvironmentInfo.HasSharedFramework("netcoreapp1.1"))
            {
                // running the app requires netcoreapp1.1
                return;
            }

            var cmd = new DotnetCommand()
                      .WithWorkingDirectory(projectDirectory)
                      .ExecuteWithCapturedOutput("run -c Debug");

            cmd.Should().Pass();
            cmd.StdOut.Should().Contain("3 Resources Found:");
        }
コード例 #10
0
        public void XunitMultiTFM()
        {
            // Copy XunitMulti project in output directory of project dotnet-test.Tests
            string testAppName  = "XunitMulti";
            var    testInstance = TestAssets.Get(testAppName)
                                  .CreateInstance("2")
                                  .WithSourceFiles();

            var testProjectDirectory = testInstance.Root.FullName;

            // Restore project XunitMulti
            new RestoreCommand()
            .WithWorkingDirectory(testProjectDirectory)
            .Execute()
            .Should()
            .Pass();

            // Call test
            CommandResult result = new DotnetTestCommand()
                                   .WithWorkingDirectory(testProjectDirectory)
                                   .ExecuteWithCapturedOutput(TestBase.ConsoleLoggerOutputNormal);

            // Verify
            if (!DotnetUnderTest.IsLocalized())
            {
                // for target framework net46
                result.StdOut.Should().Contain("Total tests: 3");
                result.StdOut.Should().Contain("Passed: 2");
                result.StdOut.Should().Contain("Failed: 1");
                result.StdOut.Should().Contain("\u221a TestNamespace.VSTestXunitTests.VSTestXunitPassTestDesktop");

                // for target framework netcoreapp1.0
                result.StdOut.Should().Contain("Total tests: 3");
                result.StdOut.Should().Contain("Passed: 1");
                result.StdOut.Should().Contain("Failed: 2");
                result.StdOut.Should().Contain("X TestNamespace.VSTestXunitTests.VSTestXunitFailTestNetCoreApp");
            }

            result.ExitCode.Should().Be(1);
        }
コード例 #11
0
        public void ItPassesSIGTERMToChild()
        {
            var asset = TestAssets.Get("TestAppThatWaits")
                        .CreateInstance()
                        .WithSourceFiles();

            var command = new RunCommand()
                          .WithWorkingDirectory(asset.Root.FullName);

            bool    killed = false;
            Process child  = null;

            command.OutputDataReceived += (s, e) =>
            {
                if (killed)
                {
                    return;
                }

                child = Process.GetProcessById(Convert.ToInt32(e.Data));
                NativeMethods.Posix.kill(command.CurrentProcess.Id, NativeMethods.Posix.SIGTERM).Should().Be(0);

                killed = true;
            };

            command
            .ExecuteWithCapturedOutput()
            .Should()
            .ExitWith(43)
            .And
            .HaveStdOutContaining("Terminating!");

            killed.Should().BeTrue();

            if (!child.WaitForExit(WaitTimeout))
            {
                child.Kill();
                throw new XunitException("child process failed to terminate.");
            }
        }
コード例 #12
0
        public void ItCanNewRestoreBuildRunCleanMSBuildProject()
        {
            var    directory        = TestAssets.CreateTestDirectory();
            string projectDirectory = directory.FullName;

            string newArgs = "console --debug:ephemeral-hive --no-restore";

            new NewCommandShim()
            .WithWorkingDirectory(projectDirectory)
            .Execute(newArgs)
            .Should().Pass();

            RetargetProject(projectDirectory);

            new RestoreCommand()
            .WithWorkingDirectory(projectDirectory)
            .Execute()
            .Should().Pass();

            new BuildCommand()
            .WithWorkingDirectory(projectDirectory)
            .Execute()
            .Should().Pass();

            var runCommand = new RunCommand()
                             .WithWorkingDirectory(projectDirectory)
                             .ExecuteWithCapturedOutput()
                             .Should().Pass().And.HaveStdOutContaining("Hello World!");

            var binDirectory = new DirectoryInfo(projectDirectory).Sub("bin");

            binDirectory.Should().HaveFilesMatching("*.dll", SearchOption.AllDirectories);

            new CleanCommand()
            .WithWorkingDirectory(projectDirectory)
            .Execute()
            .Should().Pass();

            binDirectory.Should().NotHaveFilesMatching("*.dll", SearchOption.AllDirectories);
        }
コード例 #13
0
        public void ItMigratesProjectWithOutputName()
        {
            var projectName        = "AppWithOutputAssemblyName";
            var expectedOutputName = "MyApp";

            var projectDirectory = TestAssets
                                   .GetProjectJson(projectName)
                                   .CreateInstance()
                                   .WithSourceFiles()
                                   .WithRestoreFiles()
                                   .Root;

            var expectedCsprojPath = projectDirectory.GetFile($"{projectName}.csproj");

            if (expectedCsprojPath.Exists)
            {
                expectedCsprojPath.Delete();
            }

            CleanBinObj(projectDirectory);
            MigrateProject(projectDirectory.FullName);

            expectedCsprojPath.Refresh();

            expectedCsprojPath.Should().Exist();

            Restore(projectDirectory, projectName);
            BuildMSBuild(projectDirectory, projectName);
            projectDirectory
            .GetDirectory("bin")
            .EnumerateFiles($"{expectedOutputName}.pdb", SearchOption.AllDirectories)
            .Count().Should().Be(1);

            PackMSBuild(projectDirectory, projectName);

            projectDirectory
            .GetDirectory("bin")
            .EnumerateFiles($"{projectName}.1.0.0.nupkg", SearchOption.AllDirectories)
            .Count().Should().Be(1);
        }
コード例 #14
0
        public void ItPublishesSuccessfullyWithNoBuildIfPreviouslyBuilt(bool selfContained)
        {
            var rootPath = TestAssets.CreateTestDirectory(identifier: selfContained ? "_sc" : "").FullName;
            var rootDir  = new DirectoryInfo(rootPath);

            string newArgs = $"console -o \"{rootPath}\" --no-restore";

            new NewCommandShim()
            .WithWorkingDirectory(rootPath)
            .Execute(newArgs)
            .Should()
            .Pass();

            var rid    = selfContained ? DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier() : "";
            var ridArg = selfContained ? $"-r {rid}" : "";

            new BuildCommand()
            .WithWorkingDirectory(rootPath)
            .ExecuteWithCapturedOutput(ridArg)
            .Should()
            .Pass();

            new PublishCommand()
            .WithWorkingDirectory(rootPath)
            .ExecuteWithCapturedOutput($"{ridArg} --no-build")
            .Should()
            .Pass();

            var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";

            var outputProgram = rootDir
                                .GetDirectory("bin", configuration, "netcoreapp2.1", rid, "publish", $"{rootDir.Name}.dll")
                                .FullName;

            new TestCommand(outputProgram)
            .ExecuteWithCapturedOutput()
            .Should()
            .Pass()
            .And.HaveStdOutContaining("Hello World");
        }
コード例 #15
0
        public void ItRunsWhenRestoringToSpecificPackageDir()
        {
            var rootPath = TestAssets.CreateTestDirectory().FullName;

            string dir  = "pkgs";
            string args = $"--packages {dir}";

            string newArgs = $"console -f netcoreapp2.1 -o \"{rootPath}\" --debug:ephemeral-hive --no-restore";

            new NewCommandShim()
            .WithWorkingDirectory(rootPath)
            .Execute(newArgs)
            .Should()
            .Pass();

            new RestoreCommand()
            .WithWorkingDirectory(rootPath)
            .Execute(args)
            .Should()
            .Pass()
            .And.NotHaveStdErr();

            new BuildCommand()
            .WithWorkingDirectory(rootPath)
            .Execute("--no-restore")
            .Should().Pass();

            var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";

            var outputDll = Directory.EnumerateFiles(
                Path.Combine(rootPath, "bin", configuration, "netcoreapp2.1"), "*.dll",
                SearchOption.TopDirectoryOnly)
                            .Single();

            var outputRunCommand = new DotnetCommand();

            outputRunCommand.ExecuteWithCapturedOutput(outputDll)
            .Should().Pass()
            .And.HaveStdOutContaining("Hello World");
        }
コード例 #16
0
        public void ItMigratesAndBuildsProjectsInGlobalJson(string path, string projectNameSuffix)
        {
            var assetsDir = TestAssets
                            .GetProjectJson("ProjectsWithGlobalJson")
                            .CreateInstance(identifier: projectNameSuffix)
                            .WithSourceFiles()
                            .WithRestoreFiles()
                            .WithEmptyGlobalJson()
                            .Root;

            var projectName = $"Project{projectNameSuffix}";

            var globalJson = assetsDir.GetFile("global.json");

            var restoreDirectories = new DirectoryInfo[]
            {
                assetsDir.GetDirectory("src", "ProjectH"),
                assetsDir.GetDirectory("src", "ProjectI"),
                assetsDir.GetDirectory("src with spaces", "ProjectJ")
            };

            var projectDirectory = assetsDir.GetDirectory(path, projectName);

            var outputComparisonData = BuildProjectJsonMigrateBuildMSBuild(projectDirectory,
                                                                           projectName,
                                                                           new [] { globalJson.FullName },
                                                                           restoreDirectories);

            var outputsIdentical = outputComparisonData.ProjectJsonBuildOutputs
                                   .SetEquals(outputComparisonData.MSBuildBuildOutputs);

            if (!outputsIdentical)
            {
                OutputDiagnostics(outputComparisonData);
            }

            outputsIdentical.Should().BeTrue();

            VerifyAllMSBuildOutputsRunnable(projectDirectory);
        }
コード例 #17
0
        private void WhenSlnContainsSolutionFolderWithDifferentCasingItDoesNotCreateDuplicate()
        {
            var projectDirectory = TestAssets
                                   .Get("TestAppWithSlnAndCaseSensitiveSolutionFolders")
                                   .CreateInstance()
                                   .WithSourceFiles()
                                   .Root
                                   .FullName;

            var projectToAdd = Path.Combine("src", "Lib", "Lib.csproj");
            var cmd          = new DotnetCommand()
                               .WithWorkingDirectory(projectDirectory)
                               .Execute($"sln App.sln add {projectToAdd}");

            cmd.Should().Pass();

            var slnFile = SlnFile.Read(Path.Combine(projectDirectory, "App.sln"));
            var solutionFolderProjects = slnFile.Projects.Where(
                p => p.TypeGuid == ProjectTypeGuids.SolutionFolderGuid);

            solutionFolderProjects.Count().Should().Be(1);
        }
コード例 #18
0
        public void WhenNestedProjectIsAddedSolutionFoldersAreCreated()
        {
            var projectDirectory = TestAssets
                                   .Get("TestAppWithSlnAndCsprojInSubDir")
                                   .CreateInstance()
                                   .WithSourceFiles()
                                   .Root
                                   .FullName;

            var projectToAdd = Path.Combine("src", "Lib", "Lib.csproj");
            var cmd          = new DotnetCommand()
                               .WithWorkingDirectory(projectDirectory)
                               .ExecuteWithCapturedOutput($"sln App.sln add {projectToAdd}");

            cmd.Should().Pass();

            var slnPath             = Path.Combine(projectDirectory, "App.sln");
            var expectedSlnContents = GetExpectedSlnContents(slnPath, ExpectedSlnFileAfterAddingNestedProj);

            File.ReadAllText(slnPath)
            .Should().BeVisuallyEquivalentTo(expectedSlnContents);
        }
コード例 #19
0
        public void ItDoesNotAddFxVersionAsAParamWhenTheToolDoesNotHaveThePrefercliruntimeFile()
        {
            var projectToolsCommandResolver = SetupProjectToolsCommandResolver();

            var testInstance = TestAssets.Get(TestProjectName)
                               .CreateInstance()
                               .WithSourceFiles()
                               .WithRestoreFiles();

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName      = "dotnet-portable",
                CommandArguments = null,
                ProjectDirectory = testInstance.Root.FullName
            };

            var result = projectToolsCommandResolver.Resolve(commandResolverArguments);

            result.Should().NotBeNull();

            result.Args.Should().NotContain("--fx-version");
        }
コード例 #20
0
        public void ItTestsWithTheSpecifiedRuntimeOption()
        {
            var testInstance = TestAssets.Get("XunitCore")
                               .CreateInstance()
                               .WithSourceFiles();

            var rootPath = testInstance.Root.FullName;
            var rid      = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier();

            new BuildCommand()
            .WithWorkingDirectory(rootPath)
            .ExecuteWithCapturedOutput($"--runtime {rid}")
            .Should()
            .Pass()
            .And.NotHaveStdErr();

            var result = new DotnetTestCommand()
                         .WithWorkingDirectory(rootPath)
                         .ExecuteWithCapturedOutput($"{TestBase.ConsoleLoggerOutputNormal} --no-build --runtime {rid}");

            result
            .Should()
            .NotHaveStdErrContaining("MSB1001")
            .And
            .HaveStdOutContaining(rid);

            if (!DotnetUnderTest.IsLocalized())
            {
                result
                .Should()
                .HaveStdOutContaining("Total tests: 2. Passed: 1. Failed: 1. Skipped: 0.")
                .And
                .HaveStdOutContaining("Passed   TestNamespace.VSTestXunitTests.VSTestXunitPassTest")
                .And
                .HaveStdOutContaining("Failed   TestNamespace.VSTestXunitTests.VSTestXunitFailTest");
            }

            result.ExitCode.Should().Be(1);
        }
コード例 #21
0
        private void TestTemplateBuild(string templateName)
        {
            var    directory        = TestAssets.CreateTestDirectory(identifier: templateName);
            string projectDirectory = directory.FullName;

            string newArgs = $"{templateName} --debug:ephemeral-hive --no-restore";

            new NewCommandShim()
            .WithWorkingDirectory(projectDirectory)
            .Execute(newArgs)
            .Should().Pass();

            new RestoreCommand()
            .WithWorkingDirectory(projectDirectory)
            .Execute()
            .Should().Pass();

            new BuildCommand()
            .WithWorkingDirectory(projectDirectory)
            .Execute()
            .Should().Pass();
        }
コード例 #22
0
        public void ItMigratesDotnetNewConsoleWithIdenticalOutputs()
        {
            var projectDirectory = TestAssets
                                   .GetProjectJson("ProjectJsonConsoleTemplate")
                                   .CreateInstance()
                                   .WithSourceFiles()
                                   .Root;

            var outputComparisonData = GetComparisonData(projectDirectory);

            var outputsIdentical =
                outputComparisonData.ProjectJsonBuildOutputs.SetEquals(outputComparisonData.MSBuildBuildOutputs);

            if (!outputsIdentical)
            {
                OutputDiagnostics(outputComparisonData);
            }

            outputsIdentical.Should().BeTrue();

            VerifyAllMSBuildOutputsRunnable(projectDirectory);
        }
コード例 #23
0
        public void ItMigratesAllProjectsInGivenDirectory(bool skipRefs)
        {
            var projectDirectory = TestAssets
                                   .GetProjectJson("TestAppDependencyGraph")
                                   .CreateInstance(callingMethod: $"MigrateDirectory.SkipRefs.{skipRefs}")
                                   .WithSourceFiles()
                                   .WithEmptyGlobalJson()
                                   .Root;

            if (skipRefs)
            {
                MigrateProject(new [] { projectDirectory.FullName, "--skip-project-references" });
            }
            else
            {
                MigrateProject(new [] { projectDirectory.FullName });
            }

            string[] migratedProjects = new string[] { "ProjectA", "ProjectB", "ProjectC", "ProjectD", "ProjectE", "ProjectF", "ProjectG", "ProjectH", "ProjectI", "ProjectJ" };

            VerifyMigration(migratedProjects, projectDirectory);
        }
コード例 #24
0
        public void ItMigratesProjectsWithMultipleTFMs(string projectName)
        {
            var projectDirectory = TestAssets
                                   .GetProjectJson(projectName)
                                   .CreateInstance(identifier: projectName)
                                   .WithSourceFiles()
                                   .WithRestoreFiles()
                                   .WithEmptyGlobalJson()
                                   .Root;

            var outputComparisonData = BuildProjectJsonMigrateBuildMSBuild(projectDirectory, projectName);

            var outputsIdentical =
                outputComparisonData.ProjectJsonBuildOutputs.SetEquals(outputComparisonData.MSBuildBuildOutputs);

            if (!outputsIdentical)
            {
                OutputDiagnostics(outputComparisonData);
            }

            outputsIdentical.Should().BeTrue();
        }
コード例 #25
0
        public void WhenValidPackageIsPassedWithFrameworkItGetsAdded()
        {
            var testAsset        = "TestAppSimple";
            var projectDirectory = TestAssets
                                   .Get(testAsset)
                                   .CreateInstance()
                                   .WithSourceFiles()
                                   .Root
                                   .FullName;

            var packageName    = "Newtonsoft.Json";
            var packageVersion = "9.0.1";
            var framework      = "netcoreapp2.1";
            var cmd            = new DotnetCommand()
                                 .WithWorkingDirectory(projectDirectory)
                                 .ExecuteWithCapturedOutput($"add package {packageName} --version {packageVersion} --framework {framework}");

            cmd.Should().Pass();
            cmd.StdOut.Should().Contain($"PackageReference for package '{packageName}' version '{packageVersion}' " +
                                        $"added to file '{projectDirectory + Path.DirectorySeparatorChar + testAsset}.csproj'.");
            cmd.StdErr.Should().BeEmpty();
        }
コード例 #26
0
        public void ItDoesNotAcceptInvalidFramework()
        {
            var testAsset        = "MSBuildAppWithMultipleFrameworks";
            var projectDirectory = TestAssets
                                   .Get(testAsset)
                                   .CreateInstance()
                                   .WithSourceFiles()
                                   .Root
                                   .FullName;

            new RestoreCommand()
            .WithWorkingDirectory(projectDirectory)
            .Execute()
            .Should()
            .Pass();

            new ListPackageCommand()
            .WithPath(projectDirectory)
            .Execute("--framework invalid")
            .Should()
            .Fail();
        }
コード例 #27
0
        public void PortablePublishWithLatestTFMUsesBundledAspNetCoreAppVersion()
        {
            var _testInstance = TestAssets.Get(AspNetTestProject)
                                .CreateInstance(identifier: LatestSupportedAspNetCoreAppVersion)
                                .WithSourceFiles();

            string projectDirectory = _testInstance.Root.FullName;
            string projectPath      = Path.Combine(projectDirectory, $"{AspNetTestProject}.csproj");

            var project = XDocument.Load(projectPath);
            var ns      = project.Root.Name.Namespace;

            //  Update TargetFramework to the right version of .NET Core
            project.Root.Element(ns + "PropertyGroup")
            .Element(ns + "TargetFramework")
            .Value = "netcoreapp" + LatestSupportedAspNetCoreAppVersion;

            project.Save(projectPath);

            //  Get the implicit version
            new RestoreCommand()
            .WithWorkingDirectory(projectDirectory)
            .Execute()
            .Should().Pass();

            var assetsFilePath = Path.Combine(projectDirectory, "obj", "project.assets.json");
            var assetsFile     = new LockFileFormat().Read(assetsFilePath);

            var restoredVersion = GetAspNetCoreAppVersion(assetsFile, portable: true);

            restoredVersion.Should().NotBeNull();

            var bundledVersionPath = Path.Combine(projectDirectory, ".BundledAspNetCoreVersion");
            var bundledVersion     = File.ReadAllText(bundledVersionPath).Trim();

            restoredVersion.ToNormalizedString().Should().BeEquivalentTo(bundledVersion,
                                                                         "The bundled aspnetcore versions set in Microsoft.NETCoreSdk.BundledVersions.props should be idenitical to the versions set in DependencyVersions.props." +
                                                                         "Please update MSBuildExtensions.targets in this repo so these versions match.");
        }
コード例 #28
0
        public void ItBuildsAndTestsAppWhenRestoringToSpecificDirectory()
        {
            // Creating folder with name short name "RestoreTest" to avoid PathTooLongException
            var rootPath = TestAssets.Get("VSTestCore").CreateInstance("8").WithSourceFiles().Root.FullName;

            // Moving pkgs folder on top to avoid PathTooLongException
            string dir      = @"..\..\..\..\pkgs";
            string fullPath = Path.GetFullPath(Path.Combine(rootPath, dir));

            string args = $"--packages \"{dir}\"";

            new RestoreCommand()
            .WithWorkingDirectory(rootPath)
            .Execute(args)
            .Should()
            .Pass();

            new BuildCommand()
            .WithWorkingDirectory(rootPath)
            .ExecuteWithCapturedOutput("--no-restore")
            .Should()
            .Pass()
            .And.NotHaveStdErr();

            CommandResult result = new DotnetTestCommand()
                                   .WithWorkingDirectory(rootPath)
                                   .ExecuteWithCapturedOutput($"{TestBase.ConsoleLoggerOutputNormal} --no-restore");

            if (!DotnetUnderTest.IsLocalized())
            {
                result.StdOut.Should().Contain("Total tests: 2");
                result.StdOut.Should().Contain("Passed: 1");
                result.StdOut.Should().Contain("Failed: 1");
                result.StdOut.Should().Contain("\u221a VSTestPassTest");
                result.StdOut.Should().Contain("X VSTestFailTest");
            }

            result.ExitCode.Should().Be(1);
        }
コード例 #29
0
        public void ItImplicitlyRestoresAProjectWhenTesting()
        {
            string testAppName  = "VSTestCore";
            var    testInstance = TestAssets.Get(testAppName)
                                  .CreateInstance()
                                  .WithSourceFiles();

            var testProjectDirectory = testInstance.Root.FullName;

            CommandResult result = new DotnetTestCommand()
                                   .WithWorkingDirectory(testProjectDirectory)
                                   .ExecuteWithCapturedOutput(TestBase.ConsoleLoggerOutputNormal);

            if (!DotnetUnderTest.IsLocalized())
            {
                result.StdOut.Should().Contain("Total tests: 2. Passed: 1. Failed: 1. Skipped: 0.");
                result.StdOut.Should().Contain("Passed   TestNamespace.VSTestTests.VSTestPassTest");
                result.StdOut.Should().Contain("Failed   TestNamespace.VSTestTests.VSTestFailTest");
            }

            result.ExitCode.Should().Be(1);
        }
コード例 #30
0
        private void CreateNoopExe(string intoDir, string name, bool fail = false)
        {
            var rootPath = Temp.CreateDirectory().Path;

            TestAssets.CopyDirTo("Noop", rootPath);

            Func <string, TestCommand> test = n => new TestCommand(n)
            {
                WorkingDirectory = rootPath
            };

            string rid         = GetCurrentRID();
            string msbuildArgs = $"/p:AssemblyName={name} " + (fail? "/p:Fail=true" : "");

            test("dotnet")
            .Execute($"restore -r {rid} {RestoreDefaultArgs} {RestoreSourcesArgs(NugetConfigSources)} {RestoreProps()} {msbuildArgs}")
            .Should().Pass();

            test("dotnet")
            .Execute($"publish -r {rid} -o \"{intoDir}\" {msbuildArgs}")
            .Should().Pass();
        }