コード例 #1
0
ファイル: PackTests.cs プロジェクト: ramarag/cli
        public void OutputsPackagesFlatIntoOutputDirWhenOutputParameterIsPassed()
        {
            var testInstance = TestAssets.Get("TestLibraryWithConfiguration")
                               .CreateInstance()
                               .WithSourceFiles()
                               .WithBuildFiles()
                               .WithRestoreFiles();

            var outputDir = testInstance.Root
                            .GetDirectory("bin2");

            var packCommand = new PackCommand(output: outputDir.FullName)
                              .WithWorkingDirectory(testInstance.Root)
                              .Execute()
                              .Should().Pass();

            outputDir.Should().Exist()
            .And.HaveFiles(new []
            {
                "TestLibraryWithConfiguration.1.0.0.nupkg"
            });
        }
コード例 #2
0
        public void ItDoesNotMigrateADependencyWithTargetPackageThatHasAMatchingProjectAsAProjectReference()
        {
            var solutionDirectory = TestAssets.Get("NonRestoredTestProjects", "AppWithProjectDependencyAsTarget")
                                    .CreateInstance(callingMethod: "p")
                                    .WithSourceFiles()
                                    .Root.FullName;

            var appDirectory = Path.Combine(solutionDirectory, "TestApp");

            var projectContext = ProjectContext.Create(appDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10);
            var mockProj       = ProjectRootElement.Create();
            var testSettings   = MigrationSettings.CreateMigrationSettingsTestHook(appDirectory, appDirectory, mockProj, null);
            var testInputs     = new MigrationRuleInputs(new[] { projectContext }, mockProj, mockProj.AddItemGroup(),
                                                         mockProj.AddPropertyGroup());

            new MigrateProjectDependenciesRule().Apply(testSettings, testInputs);

            var projectReferences = mockProj.Items.Where(
                item => item.ItemType.Equals("ProjectReference", StringComparison.Ordinal));

            projectReferences.Should().BeEmpty();
        }
コード例 #3
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");
        }
コード例 #4
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.");
        }
コード例 #5
0
        public void TestFrameworkSpecificDependencyToolsCanBeInvoked(string identifier, string framework, string expectedDependencyToolPath)
        {
            var testInstance = TestAssets.Get(TestAssetKinds.DesktopTestProjects, "AppWithProjTool2Fx")
                               .CreateInstance(identifier: identifier)
                               .WithSourceFiles()
                               .WithRestoreFiles();

            new BuildCommand()
            .WithWorkingDirectory(testInstance.Root)
            .WithConfiguration("Debug")
            .Execute()
            .Should().Pass();

            new DependencyToolInvokerCommand()
            .WithWorkingDirectory(testInstance.Root)
            .ExecuteWithCapturedOutput($"desktop-and-portable {framework} {identifier}")
            .Should().HaveStdOutContaining(framework)
            .And.HaveStdOutContaining(identifier)
            .And.HaveStdOutContaining(expectedDependencyToolPath)
            .And.NotHaveStdErr()
            .And.Pass();
        }
コード例 #6
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   VSTestPassTest");
                result.StdOut.Should().Contain("Failed   VSTestFailTest");
            }

            result.ExitCode.Should().Be(1);
        }
コード例 #7
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);
        }
コード例 #8
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);
        }
コード例 #9
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);
        }
コード例 #10
0
        public void AppFailsDueToMissingCache()
        {
            var testAppName            = "NuGetConfigDependentProject";
            var profileProjectName     = "NuGetConfigProfile";
            var targetManifestFileName = "NuGetConfigFilterProfile.xml";

            var testInstance = TestAssets.Get(testAppName)
                               .CreateInstance()
                               .WithSourceFiles()
                               .UseCurrentRuntimeFrameworkVersion();

            var testProjectDirectory = testInstance.Root.ToString();
            var profileProjectPath   = TestAssets.Get(profileProjectName).Root.FullName;
            var profileFilter        = Path.Combine(profileProjectPath, targetManifestFileName);

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

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

            new PublishCommand()
            .WithFramework(_tfm)
            .WithWorkingDirectory(testProjectDirectory)
            .WithTargetManifest(profileFilter)
            .Execute()
            .Should().Pass();

            var outputDll = Path.Combine(testProjectDirectory, "bin", configuration, _tfm, "publish", $"{testAppName}.dll");

            new DotnetCommand()
            .ExecuteWithCapturedOutput(outputDll)
            .Should().Fail()
            .And.HaveStdErrContaining($"Error:{Environment.NewLine}" +
                                      $"  An assembly specified in the application dependencies manifest (NuGetConfigDependentProject.deps.json) was not found:{Environment.NewLine}" +
                                      $"    package: 'NuGet.Configuration', version: '4.3.0-beta1-2418'{Environment.NewLine}" +
                                      "    path: 'lib/netstandard1.3/NuGet.Configuration.dll'");
        }
コード例 #11
0
        public void AppFailsDueToMissingCache()
        {
            var testAppName        = "NewtonSoftDependentProject";
            var profileProjectName = "NewtonsoftFilterProfile";

            var testInstance = TestAssets.Get(testAppName)
                               .CreateInstance()
                               .WithSourceFiles()
                               .UseCurrentRuntimeFrameworkVersion();

            var testProjectDirectory = testInstance.Root.ToString();
            var profileProjectPath   = TestAssets.Get(profileProjectName)
                                       .CreateInstance()
                                       .WithSourceFiles()
                                       .Root.FullName;
            var profileProject = Path.Combine(profileProjectPath, $"{profileProjectName}.xml");

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

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

            new PublishCommand()
            .WithFramework(_tfm)
            .WithWorkingDirectory(testProjectDirectory)
            .WithProFileProject(profileProject)
            .Execute()
            .Should().Pass();

            var outputDll = Path.Combine(testProjectDirectory, "bin", configuration, _tfm, "publish", $"{testAppName}.dll");

            new TestCommand("dotnet")
            .ExecuteWithCapturedOutput(outputDll)
            .Should().Fail()
            .And.HaveStdErrContaining("assembly specified in the dependencies manifest was not found -- package: 'newtonsoft.json',");
        }
コード例 #12
0
        public void ItIgnoresSIGINT()
        {
            var asset = TestAssets.Get("TestAppThatWaits")
                        .CreateInstance()
                        .WithSourceFiles();

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

            bool killed = false;

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

                // Simulate a SIGINT sent to a process group (i.e. both `dotnet run` and `TestAppThatWaits`).
                // Ideally we would send SIGINT to an actual process group, but the new child process (i.e. `dotnet run`)
                // will inherit the current process group from the `dotnet test` process that is running this test.
                // We would need to fork(), setpgid(), and then execve() to break out of the current group and that is
                // too complex for a simple unit test.
                NativeMethods.Posix.kill(command.CurrentProcess.Id, NativeMethods.Posix.SIGINT).Should().Be(0); // dotnet run
                NativeMethods.Posix.kill(Convert.ToInt32(e.Data), NativeMethods.Posix.SIGINT).Should().Be(0);   // TestAppThatWaits

                killed = true;
            };

            command
            .ExecuteWithCapturedOutput()
            .Should()
            .ExitWith(42)
            .And
            .HaveStdOutContaining("Interrupted!");

            killed.Should().BeTrue();
        }
コード例 #13
0
        public void ItShowsStackTraceWhenRunAsTool()
        {
            var root = TestAssets.Get("NonRestoredTestProjects", "AppThrowingException")
                       .CreateInstance()
                       .WithSourceFiles()
                       .Root;

            var appRoot = Path.Combine(root.FullName, "App");

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

            new PackCommand()
            .WithWorkingDirectory(appRoot)
            .Execute("-o ../pkgs")
            .Should()
            .Pass();

            var appWithToolDepRoot = Path.Combine(root.FullName, "AppDependingOnOtherAsTool");

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

            string msg1 = "Unhandled Exception: AppThrowing.MyException: "
                          + "Exception of type 'AppThrowing.MyException' was thrown.";
            string msg2 = "at AppThrowing.MyException.Main(String[] args)";

            new DotnetCommand()
            .WithWorkingDirectory(appWithToolDepRoot)
            .ExecuteWithCapturedOutput("throwingtool")
            .Should().Fail()
            .And.HaveStdErrContaining(msg1)
            .And.HaveStdErrContaining(msg2);
        }
コード例 #14
0
        public void TestsFromAGivenContainerShouldRunWithExpectedOutput()
        {
            var testAppName = "VSTestCore";
            var testRoot    = TestAssets.Get(testAppName)
                              .CreateInstance()
                              .WithSourceFiles()
                              .WithRestoreFiles()
                              .WithVersionVariables()
                              .Root;

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

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

            var outputDll = testRoot
                            .GetDirectory("bin", configuration, "netcoreapp3.0")
                            .GetFile($"{testAppName}.dll");

            var argsForVstest = $"\"{outputDll.FullName}\" --logger:console;verbosity=normal";

            // Call vstest
            var result = new VSTestCommand().ExecuteWithCapturedOutput(argsForVstest);

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

            result.ExitCode.Should().Be(1);
        }
コード例 #15
0
        public void WhenProjectReferencesArePresentInTheSolutionItListsThem()
        {
            string OutputText = CommonLocalizableStrings.ProjectReferenceOneOrMore;

            OutputText += $@"
{new string('-', OutputText.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(OutputText);
        }
コード例 #16
0
        public void It_promotes_FrameworkAssemblies_from_P2P_references_up_in_the_dependency_chain()
        {
            var solutionDirectory = TestAssets.Get(TestAssetKinds.DesktopTestProjects, "TestAppWithFrameworkAssemblies")
                                    .CreateInstance()
                                    .WithSourceFiles().Root;

            var appDirectory = Path.Combine(solutionDirectory.FullName, "ProjectA");

            var projectContext = ProjectContext.Create(appDirectory, FrameworkConstants.CommonFrameworks.Net451);
            var mockProj       = ProjectRootElement.Create();
            var testSettings   = MigrationSettings.CreateMigrationSettingsTestHook(appDirectory, appDirectory, mockProj, null);
            var testInputs     = new MigrationRuleInputs(new[] { projectContext }, mockProj, mockProj.AddItemGroup(),
                                                         mockProj.AddPropertyGroup());

            new MigrateProjectDependenciesRule().Apply(testSettings, testInputs);

            var frameworkAssemblyReferences = mockProj.Items.Where(
                item => item.ItemType == "Reference" &&
                item.Include == "System.ComponentModel.DataAnnotations" &&
                item.Parent.Condition == " '$(TargetFramework)' == 'net451' ");

            frameworkAssemblyReferences.Count().Should().Be(1);
        }
コード例 #17
0
        public void ItFindsToolsLocatedInTheNuGetFallbackFolder()
        {
            var testInstance = TestAssets.Get("AppWithFallbackFolderToolDependency")
                               .CreateInstance("NF") // use shorter name since path could be too long
                               .WithSourceFiles()
                               .WithNuGetConfig(RepoDirectoriesProvider.TestPackages);
            var testProjectDirectory = testInstance.Root.FullName;
            var fallbackFolder       = Path.Combine(testProjectDirectory, "fallbackFolder");

            PopulateFallbackFolder(testProjectDirectory, fallbackFolder);

            var nugetConfig = UseNuGetConfigWithFallbackFolder(testInstance, fallbackFolder);

            new RestoreCommand()
            .WithWorkingDirectory(testProjectDirectory)
            .Execute($"--configfile {nugetConfig}")
            .Should()
            .Pass();

            new DotnetCommand()
            .WithWorkingDirectory(testProjectDirectory)
            .Execute($"fallbackfoldertool").Should().Pass();
        }
コード例 #18
0
        public void CanInvokeToolFromDirectDependenciesIfPackageNameDifferentFromToolName()
        {
            var testInstance = TestAssets.Get("AppWithDirectDepWithOutputName")
                               .CreateInstance()
                               .WithSourceFiles()
                               .WithRestoreFiles();

            string framework = Tools.Tests.Utilities.NuGetFrameworks.NetCoreApp21.DotNetFrameworkName;

            new BuildCommand()
            .WithProjectDirectory(testInstance.Root)
            .WithConfiguration("Debug")
            .Execute()
            .Should().Pass();

            new DependencyToolInvokerCommand(DotnetUnderTest.WithBackwardsCompatibleRuntimes)
            .WithWorkingDirectory(testInstance.Root)
            .WithEnvironmentVariable(CommandContext.Variables.Verbose, "true")
            .ExecuteWithCapturedOutput($"tool-with-output-name", framework, "")
            .Should().HaveStdOutContaining("Tool with output name!")
            .And.NotHaveStdErr()
            .And.Pass();
        }
コード例 #19
0
        private DirectoryInfo PublishAppWithSelfContained(string testAppName, bool selfContained)
        {
            var testInstance = TestAssets.Get(testAppName)
                               .CreateInstance($"PublishesSelfContained{selfContained}")
                               .WithSourceFiles()
                               .WithRestoreFiles();

            var testProjectDirectory = testInstance.Root;

            var rid = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier();

            new PublishCommand()
            .WithRuntime(rid)
            .WithSelfContained(selfContained)
            .WithWorkingDirectory(testProjectDirectory)
            .Execute()
            .Should().Pass();

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

            return(testProjectDirectory
                   .GetDirectory("bin", configuration, "netcoreapp2.0", rid, "publish"));
        }
コード例 #20
0
        public void ItRestoresTestAppToSpecificDirectory()
        {
            var rootPath = TestAssets.Get("VSTestCore")
                           .CreateInstance()
                           .WithSourceFiles()
                           .WithVersionVariables()
                           .Root.FullName;

            string dir      = "pkgs";
            string fullPath = Path.GetFullPath(Path.Combine(rootPath, dir));

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

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

            Directory.Exists(fullPath).Should().BeTrue();
            Directory.EnumerateFiles(fullPath, "*.dll", SearchOption.AllDirectories).Count().Should().BeGreaterThan(0);
        }
コード例 #21
0
        public void TestProjectDependencyIsNotAvailableThroughDriver()
        {
            var testInstance = TestAssets.Get("AppWithDirectDep")
                               .CreateInstance()
                               .WithSourceFiles()
                               .WithRestoreFiles();

            new BuildCommand()
            .WithWorkingDirectory(testInstance.Root)
            .WithFramework(NuGet.Frameworks.FrameworkConstants.CommonFrameworks.NetCoreApp10)
            .Execute()
            .Should().Pass();

            var currentDirectory = Directory.GetCurrentDirectory();

            CommandResult result = new HelloCommand()
                                   .WithWorkingDirectory(testInstance.Root)
                                   .ExecuteWithCapturedOutput();

            result.StdErr.Should().Contain("No executable found matching command");

            result.Should().Fail();
        }
コード例 #22
0
        public void WhenDirectoryContainingProjectIsGivenProjectIsRemoved()
        {
            var projectDirectory = TestAssets
                                   .Get("TestAppWithSlnAndCsprojToRemove")
                                   .CreateInstance()
                                   .WithSourceFiles()
                                   .Root
                                   .FullName;

            var     solutionPath = Path.Combine(projectDirectory, "App.sln");
            SlnFile slnFile      = SlnFile.Read(solutionPath);

            slnFile.Projects.Count.Should().Be(2);

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

            cmd.Should().Pass();

            File.ReadAllText(solutionPath)
            .Should().BeVisuallyEquivalentTo(ExpectedSlnContentsAfterRemove);
        }
コード例 #23
0
        public void WhenPassedMultipleProjectsAndOneOfthemDoesNotExistItCancelsWholeOperation()
        {
            var projectDirectory = TestAssets
                                   .Get("TestAppWithSlnAndCsprojFiles")
                                   .CreateInstance()
                                   .WithSourceFiles()
                                   .Root
                                   .FullName;

            var slnFullPath   = Path.Combine(projectDirectory, "App.sln");
            var contentBefore = File.ReadAllText(slnFullPath);

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

            cmd.Should().Fail();
            cmd.StdErr.Should().Be("Project `idonotexist.csproj` does not exist.");

            File.ReadAllText(slnFullPath)
            .Should().BeVisuallyEquivalentTo(contentBefore);
        }
コード例 #24
0
        public void WhenNoProjectIsPassedItPrintsErrorAndUsage()
        {
            var projectDirectory = TestAssets
                                   .Get("TestAppWithSlnAndCsprojFiles")
                                   .CreateInstance()
                                   .WithSourceFiles()
                                   .Root
                                   .FullName;

            var cmd = new DotnetCommand()
                      .WithWorkingDirectory(projectDirectory)
                      .ExecuteWithCapturedOutput(@"sln App.sln add");

            cmd.Should().Fail();
            cmd.StdErr.Should().Be("You must specify at least one project to add.");

            _output.WriteLine("[STD OUT]");
            _output.WriteLine(cmd.StdOut);
            _output.WriteLine("[HelpText]");
            _output.WriteLine(HelpText);

            cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText);
        }
コード例 #25
0
        public void ItShouldShowImportantMessageWhenInteractiveFlagIsPassed()
        {
            string testAppName  = "VSTestCore";
            var    testInstance = TestAssets.Get(testAppName)
                                  .CreateInstance()
                                  .WithSourceFiles()
                                  .WithProjectChanges(ProjectModification.AddDisplayMessageBeforeVsTestToProject);

            var testProjectDirectory = testInstance.Root.FullName;

            // Call test
            CommandResult result = new DotnetTestCommand()
                                   .WithWorkingDirectory(testProjectDirectory)
                                   .ExecuteWithCapturedOutput("--interactive");

            // Verify
            if (!DotnetUnderTest.IsLocalized())
            {
                result.StdOut.Should().Contain("Important text");
            }

            result.ExitCode.Should().Be(1);
        }
コード例 #26
0
        public void ItReturnsNullWhenCommandNameDoesNotExistInProjectDependenciesForMSBuildProject()
        {
            MSBuildTestProjectInstance =
                TestAssets.Get("TestAppWithProjDepTool")
                    .CreateInstance()
                    .WithSourceFiles()
                    .WithNuGetConfig(RepoDirectoriesProvider.TestPackages)
                    .WithRestoreFiles();

            var projectDependenciesCommandResolver = SetupProjectDependenciesCommandResolver();

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName = "nonexistent-command",
                CommandArguments = null,
                ProjectDirectory = MSBuildTestProjectInstance.Root.FullName,
                Framework = NuGetFrameworks.NetCoreApp30
            };

            var result = projectDependenciesCommandResolver.Resolve(commandResolverArguments);

            result.Should().BeNull();
        }
コード例 #27
0
        public void WhenProjectDirectoryIsAddedSolutionFoldersAreNotCreated()
        {
            var projectDirectory = TestAssets
                                   .Get("TestAppWithSlnAndCsprojFiles")
                                   .CreateInstance()
                                   .WithSourceFiles()
                                   .Root
                                   .FullName;

            var projectToAdd = Path.Combine("Lib", "Lib.csproj");
            var cmd          = new DotnetCommand()
                               .WithWorkingDirectory(projectDirectory)
                               .ExecuteWithCapturedOutput($"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(0);
            slnFile.Sections.GetSection("NestedProjects").Should().BeNull();
        }
コード例 #28
0
        public void CanInvokeToolFromDirectDependenciesIfPackageNameDifferentFromToolName()
        {
            var testInstance = TestAssets.Get("AppWithDirectDepWithOutputName")
                               .CreateInstance()
                               .WithSourceFiles()
                               .WithRestoreFiles();

            const string framework = ".NETCoreApp,Version=v1.0";

            new BuildCommand()
            .WithProjectDirectory(testInstance.Root)
            .WithConfiguration("Debug")
            .Execute()
            .Should().Pass();

            new DependencyToolInvokerCommand()
            .WithWorkingDirectory(testInstance.Root)
            .WithEnvironmentVariable(CommandContext.Variables.Verbose, "true")
            .ExecuteWithCapturedOutput($"tool-with-output-name", framework, "")
            .Should().HaveStdOutContaining("Tool with output name!")
            .And.NotHaveStdErr()
            .And.Pass();
        }
コード例 #29
0
        //ISSUE: https://github.com/dotnet/sdk/issues/522
        //[Fact]
        public void WhenPassedAnUnknownProjectTypeItFails()
        {
            var projectDirectory = TestAssets
                                   .Get("SlnFileWithNoProjectReferencesAndUnknownProject")
                                   .CreateInstance()
                                   .WithSourceFiles()
                                   .Root
                                   .FullName;

            var slnFullPath   = Path.Combine(projectDirectory, "App.sln");
            var contentBefore = File.ReadAllText(slnFullPath);

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

            cmd.Should().Fail();
            cmd.StdErr.Should().BeVisuallyEquivalentTo("Unsupported project type. Please check with your sdk provider.");

            File.ReadAllText(slnFullPath)
            .Should().BeVisuallyEquivalentTo(contentBefore);
        }
コード例 #30
0
        public void TestFrameworkSpecificLibraryDependencyToolsCannotBeInvoked(string identifier, string framework, string expectedDependencyToolPath, bool windowsOnly)
        {
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && windowsOnly)
            {
                return;
            }

            var testInstance = TestAssets.Get(TestAssetKinds.DesktopTestProjects, "LibWithProjTool2Fx")
                               .CreateInstance(identifier: identifier)
                               .WithSourceFiles()
                               .WithRestoreFiles();

            new BuildCommand()
            .WithWorkingDirectory(testInstance.Root)
            .WithConfiguration("Debug")
            .Execute()
            .Should().Pass();

            new DependencyToolInvokerCommand()
            .WithWorkingDirectory(testInstance.Root)
            .ExecuteWithCapturedOutput($"desktop-and-portable {framework} {identifier}")
            .Should().Fail();
        }