public void TemplateRestoresAndBuildsWithoutWarnings(
            string language,
            string projectType,
            bool useNuGetConfigForAspNet)
        {
            string rootPath = TestAssetsManager.CreateTestDirectory(identifier: $"{language}_{projectType}").Path;

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

            new TestCommand("dotnet")
            .WithWorkingDirectory(rootPath)
            .Execute($"restore")
            .Should().Pass();

            var buildResult = new TestCommand("dotnet")
                              .WithWorkingDirectory(rootPath)
                              .ExecuteWithCapturedOutput("build")
                              .Should().Pass()
                              .And.NotHaveStdErr();
        }
Esempio n. 2
0
        public void ItRunsAppWhenRestoringToSpecificPackageDirectory()
        {
            var rootPath = TestAssetsManager.CreateTestDirectory().Path;

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

            new NewCommand()
            .WithWorkingDirectory(rootPath)
            .Execute()
            .Should()
            .Pass();

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

            new RunCommand()
            .WithWorkingDirectory(rootPath)
            .ExecuteWithCapturedOutput()
            .Should().Pass()
            .And.HaveStdOutContaining("Hello World");
        }
Esempio n. 3
0
        public void ItPacksAppWhenRestoringToSpecificPackageDirectory()
        {
            var rootPath = TestAssetsManager.CreateTestDirectory().Path;
            var rootDir  = new DirectoryInfo(rootPath);

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

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

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

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

            new PackCommand()
            .WithWorkingDirectory(rootPath)
            .ExecuteWithCapturedOutput()
            .Should()
            .Pass();

            rootDir
            .GetDirectory("bin")
            .Should().HaveFilesMatching("*.nupkg", SearchOption.AllDirectories);
        }
        public void WhenDotnetRunHelpIsInvokedAppArgumentsTextIsIncludedInOutput()
        {
            const string AppArgumentsText = "Arguments passed to the application that is being run.";

            var projectDirectory = TestAssetsManager.CreateTestDirectory("RunContainsAppArgumentsText");
            var result           = new TestCommand("dotnet")
                                   .WithWorkingDirectory(projectDirectory.Path)
                                   .ExecuteWithCapturedOutput("run --help");

            result.ExitCode.Should().Be(0);
            result.StdOut.Should().Contain(AppArgumentsText);
        }
        public void WhenTheProfileRootIsUndefinedThenDotnetDoesNotCrash()
        {
            var testDirectory = TestAssetsManager.CreateTestDirectory();
            var testStartTime = GetTruncatedDateTime();

            var optimizationProfileFilePath = GetOptimizationProfileFilePath(testDirectory.Path);

            new TestCommand("dotnet")
            .WithUserProfileRoot("")
            .ExecuteWithCapturedOutput("--help")
            .Should().Pass();
        }
Esempio n. 6
0
            public TestEnvironment(TestAssetsManager testAssets, string identifier = "", [CallerMemberName] string callingMethod = "")
            {
                TestDirectory = new DirectoryInfo(testAssets.CreateTestDirectory(
                                                      //  Add FrameworkDescription to identifier so that instances of tests running on different frameworks
                                                      //  (.NET Core vs .NET Framework) don't conflict
                                                      identifier: identifier + RuntimeInformation.FrameworkDescription,
                                                      testName: callingMethod).Path);

                DeleteMinimumVSDefinedSDKVersionFile();

                PathEnvironmentVariable = string.Empty;
            }
        public void When_the_profile_root_is_undefined_then_dotnet_does_not_crash()
        {
            var testDirectory = TestAssetsManager.CreateTestDirectory();
            var testStartTime = GetTruncatedDateTime();

            var optimizationProfileFilePath = GetOptimizationProfileFilePath(testDirectory.Path);

            new TestCommand("dotnet")
            .WithUserProfileRoot("")
            .ExecuteWithCapturedOutput("--help")
            .Should().Pass();
        }
Esempio n. 8
0
        static GivenThatTheUserIsRunningDotNetForTheFirstTime()
        {
            var testDirectory  = TestAssetsManager.CreateTestDirectory("Dotnet_first_time_experience_tests");
            var testNugetCache = Path.Combine(testDirectory.Path, "nuget_cache");

            var command = new DotnetCommand()
                          .WithWorkingDirectory(testDirectory.Path);

            command.Environment["NUGET_PACKAGES"] = testNugetCache;
            command.Environment["DOTNET_SKIP_FIRST_TIME_EXPERIENCE"] = "";

            _firstDotnetNonVerbUseCommandResult = command.ExecuteWithCapturedOutput("--info");
            _firstDotnetVerbUseCommandResult    = command.ExecuteWithCapturedOutput("new");
            _nugetCacheFolder = new DirectoryInfo(testNugetCache);
        }
        public void WhenInvokedWithMulticoreJitDisabledThenDotnetDoesNotWriteOptimizationDataToTheProfileRoot()
        {
            var testDirectory = TestAssetsManager.CreateTestDirectory();
            var testStartTime = GetTruncatedDateTime();

            new TestCommand("dotnet")
            .WithUserProfileRoot(testDirectory.Path)
            .WithEnvironmentVariable("DOTNET_DISABLE_MULTICOREJIT", "1")
            .ExecuteWithCapturedOutput("--help");

            var optimizationProfileFilePath = GetOptimizationProfileFilePath(testDirectory.Path);

            File.Exists(optimizationProfileFilePath)
            .Should().BeFalse("Because multicore JIT is disabled");
        }
        public void When_invoked_with_MulticoreJit_disabled_then_dotnet_does_not_writes_optimization_data_to_the_profile_root()
        {
            var testDirectory = TestAssetsManager.CreateTestDirectory();
            var testStartTime = GetTruncatedDateTime();

            new TestCommand("dotnet")
            .WithUserProfileRoot(testDirectory.Path)
            .WithEnvironmentVariable("DOTNET_DISABLE_MULTICOREJIT", "1")
            .ExecuteWithCapturedOutput("--help");

            var optimizationProfileFilePath = GetOptimizationProfileFilePath(testDirectory.Path);

            File.Exists(optimizationProfileFilePath)
            .Should().BeFalse("Because multicore JIT is disabled");
        }
        public void When_invoked_then_dotnet_writes_optimization_data_to_the_profile_root()
        {
            var testDirectory = TestAssetsManager.CreateTestDirectory();
            var testStartTime = GetTruncatedDateTime();

            new TestCommand("dotnet")
            .WithUserProfileRoot(testDirectory.Path)
            .ExecuteWithCapturedOutput("--help");

            var optimizationProfileFilePath = GetOptimizationProfileFilePath(testDirectory.Path);

            new FileInfo(optimizationProfileFilePath)
            .Should().Exist("Because dotnet CLI creates it after each run")
            .And.HaveLastWriteTimeUtc()
            .Which.Should().BeOnOrAfter(testStartTime, "Because dotnet CLI was executed after that time");
        }
Esempio n. 12
0
        public void RestoreDoesNotUseAnyCliProducedPackagesOnItsTemplates()
        {
            var cSharpTemplates = new [] { "Console", "Lib", "Web", "Mstest", "XUnittest" };

            var rootPath          = TestAssetsManager.CreateTestDirectory().Path;
            var packagesDirectory = Path.Combine(rootPath, "packages");

            foreach (var cSharpTemplate in cSharpTemplates)
            {
                var projectFolder = Path.Combine(rootPath, cSharpTemplate);
                Directory.CreateDirectory(projectFolder);
                CreateAndRestoreNewProject(cSharpTemplate, projectFolder, packagesDirectory);
            }

            Directory.EnumerateFiles(packagesDirectory, $"*.nupkg", SearchOption.AllDirectories)
            .Should().NotContain(p => p.Contains("Microsoft.DotNet.Cli.Utils"));
        }
Esempio n. 13
0
        public void RestoreDoesNotUseAnyCliProducedPackagesOnItsTemplates()
        {
            string[] cSharpTemplates = new[] { "console", "classlib", "mstest", "xunit", "web", "mvc", "webapi" };

            var rootPath          = TestAssetsManager.CreateTestDirectory(identifier: "new3").Path;
            var packagesDirectory = Path.Combine(rootPath, "packages");

            foreach (string cSharpTemplate in cSharpTemplates)
            {
                var projectFolder = Path.Combine(rootPath, cSharpTemplate + "1");
                Directory.CreateDirectory(projectFolder);
                CreateAndRestoreNewProject(cSharpTemplate, projectFolder, packagesDirectory);
            }

            Directory.EnumerateFiles(packagesDirectory, $"*.nupkg", SearchOption.AllDirectories)
            .Should().NotContain(p => p.Contains("Microsoft.DotNet.Cli.Utils"));
        }
        public void It_returns_null_when_ProjectDirectory_does_not_contain_a_project_file()
        {
            var projectToolsCommandResolver = SetupProjectToolsCommandResolver();

            var projectDirectory = TestAssetsManager.CreateTestDirectory();

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName      = "command",
                CommandArguments = new string[] { "" },
                ProjectDirectory = projectDirectory.Path
            };

            var result = projectToolsCommandResolver.Resolve(commandResolverArguments);

            result.Should().BeNull();
        }
        public void Migration_outputs_error_when_no_projects_found(bool useGlobalJson)
        {
            var projectDirectory = TestAssetsManager.CreateTestDirectory("Migration_outputs_error_when_no_projects_found");

            string argstr = string.Empty;

            string errorMessage = string.Empty;

            if (useGlobalJson)
            {
                var globalJsonPath = Path.Combine(projectDirectory.Path, "global.json");

                using (FileStream fs = File.Create(globalJsonPath))
                {
                    using (StreamWriter sw = new StreamWriter(fs))
                    {
                        sw.WriteLine("{");
                        sw.WriteLine("\"projects\": [ \".\" ]");
                        sw.WriteLine("}");
                    }
                }

                argstr = globalJsonPath;

                errorMessage = "Unable to find any projects in global.json";
            }
            else
            {
                argstr = projectDirectory.Path;

                errorMessage = $"No project.json file found in '{projectDirectory.Path}'";
            }

            var result = new TestCommand("dotnet")
                         .WithWorkingDirectory(projectDirectory.Path)
                         .ExecuteWithCapturedOutput($"migrate {argstr}");

            // Expecting an error exit code.
            result.ExitCode.Should().Be(1);

            // Verify the error messages. Note that debug builds also show the call stack, so we search
            // for the error strings that should be present (rather than an exact match).
            result.StdErr.Should().Contain(errorMessage);
            result.StdErr.Should().Contain("Migration failed.");
        }
Esempio n. 16
0
        public void When_library_created_Then_project_restores()
        {
            var rootPath = TestAssetsManager.CreateTestDirectory().Path;

            new TestCommand("dotnet")
            {
                WorkingDirectory = rootPath
            }
            .Execute("new --type lib")
            .Should().Pass();

            new TestCommand("dotnet")
            {
                WorkingDirectory = rootPath
            }
            .Execute("restore3 /p:SkipInvalidConfigurations=true")
            .Should().Pass();
        }
Esempio n. 17
0
        public async Task NewFile(bool usePolling)
        {
            var dir = _testAssetManager.CreateTestDirectory(identifier: usePolling.ToString()).Path;

            using var watcher = FileWatcherFactory.CreateWatcher(dir, usePolling);

            var changedEv    = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
            var filesChanged = new HashSet <string>();

            watcher.OnFileChange += (_, f) =>
            {
                filesChanged.Add(f.filePath);
                changedEv.TrySetResult();
            };
            watcher.EnableRaisingEvents = true;

            var testFileFullPath = Path.Combine(dir, "foo");

            File.WriteAllText(testFileFullPath, string.Empty);

            await changedEv.Task.TimeoutAfter(DefaultTimeout);

            Assert.Equal(testFileFullPath, filesChanged.Single());
        }
        public void When_help_is_invoked_Then_MSBuild_extra_options_text_is_included_in_output(string commandName, bool isMSBuildCommand)
        {
            const string MSBuildHelpText = "  Any extra options that should be passed to MSBuild. See 'dotnet msbuild -h' for available options.";

            var projectDirectory = TestAssetsManager.CreateTestDirectory("ItContainsMSBuildHelpText");
            var result           = new TestCommand("dotnet")
                                   .WithWorkingDirectory(projectDirectory.Path)
                                   .ExecuteWithCapturedOutput($"{commandName} --help");

            result.ExitCode.Should().Be(0);
            if (isMSBuildCommand)
            {
                result.StdOut.Should().Contain(MSBuildHelpText);
            }
            else
            {
                result.StdOut.Should().NotContain(MSBuildHelpText);
            }
        }
Esempio n. 19
0
        public void When_dotnet_new_is_invoked_mupliple_times_it_should_fail()
        {
            var rootPath = TestAssetsManager.CreateTestDirectory().Path;

            new NewCommand()
            .WithWorkingDirectory(rootPath)
            .Execute($"console --debug:ephemeral-hive");

            DateTime expectedState = Directory.GetLastWriteTime(rootPath);

            var result = new NewCommand()
                         .WithWorkingDirectory(rootPath)
                         .ExecuteWithCapturedOutput($"console --debug:ephemeral-hive");

            DateTime actualState = Directory.GetLastWriteTime(rootPath);

            Assert.Equal(expectedState, actualState);

            result.Should().Fail();
        }
Esempio n. 20
0
        public void When_dotnet_build_is_invoked_Then_library_builds_without_warnings()
        {
            var rootPath = TestAssetsManager.CreateTestDirectory().Path;

            new TestCommand("dotnet")
            {
                WorkingDirectory = rootPath
            }
            .Execute("new --type lib");

            new TestCommand("dotnet")
            {
                WorkingDirectory = rootPath
            }
            .Execute("restore3 /p:SkipInvalidConfigurations=true");

            var buildResult = new TestCommand("dotnet")
                              .WithWorkingDirectory(rootPath)
                              .ExecuteWithCapturedOutput("build3")
                              .Should().Pass()
                              .And.NotHaveStdErr();
        }
        public void ItPublishesAppWhenRestoringToSpecificPackageDirectory()
        {
            var rootPath = TestAssetsManager.CreateTestDirectory().Path;
            var rootDir  = new DirectoryInfo(rootPath);

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

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

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

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

            new PublishCommand()
            .WithWorkingDirectory(rootPath)
            .ExecuteWithCapturedOutput()
            .Should().Pass();

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

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

            new TestCommand(outputProgram)
            .ExecuteWithCapturedOutput()
            .Should().Pass()
            .And.HaveStdOutContaining("Hello World");
        }
Esempio n. 22
0
        public void When_dotnet_new_is_invoked_mupliple_times_it_should_fail()
        {
            var rootPath = TestAssetsManager.CreateTestDirectory(identifier: "new3").Path;

            new TestCommand("dotnet")
            {
                WorkingDirectory = rootPath
            }
            .Execute($"new3 console");

            DateTime expectedState = Directory.GetLastWriteTime(rootPath);

            var result = new TestCommand("dotnet")
            {
                WorkingDirectory = rootPath
            }
            .ExecuteWithCapturedOutput($"new3 console");

            DateTime actualState = Directory.GetLastWriteTime(rootPath);

            Assert.Equal(expectedState, actualState);

            result.Should().Fail();
        }
Esempio n. 23
0
        public TestCommand Setup(ITestOutputHelper log, TestAssetsManager testAssets, [CallerMemberName] string testName = null)
        {
            TestDirectory = testAssets.CreateTestDirectory(testName).Path;
            var testNuGetHome         = Path.Combine(TestDirectory, "nuget_home");
            var cliTestFallbackFolder = Path.Combine(testNuGetHome, ".dotnet", "NuGetFallbackFolder");
            var profiled = Path.Combine(TestDirectory, "profile.d");
            var pathsd   = Path.Combine(TestDirectory, "paths.d");

            var command = new DotnetCommand(log)
                          .WithWorkingDirectory(TestDirectory)
                          .WithEnvironmentVariable("HOME", testNuGetHome)
                          .WithEnvironmentVariable("USERPROFILE", testNuGetHome)
                          .WithEnvironmentVariable("APPDATA", testNuGetHome)
                          .WithEnvironmentVariable("DOTNET_CLI_TEST_FALLBACKFOLDER", cliTestFallbackFolder)
                          .WithEnvironmentVariable("DOTNET_CLI_TEST_LINUX_PROFILED_PATH", profiled)
                          .WithEnvironmentVariable("DOTNET_CLI_TEST_OSX_PATHSD_PATH", pathsd)
                          .WithEnvironmentVariable("SkipInvalidConfigurations", "true")
                          .WithEnvironmentVariable(CliFolderPathCalculator.DotnetHomeVariableName, "");

            NugetFallbackFolder = new DirectoryInfo(cliTestFallbackFolder);
            DotDotnetFolder     = new DirectoryInfo(Path.Combine(testNuGetHome, ".dotnet"));

            return(command);
        }
Esempio n. 24
0
 private ProjDir NewDir([System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(NewDir), string identifier = "")
 {
     return(new ProjDir(TestAssetsManager.CreateTestDirectory(callingMethod: callingMethod, identifier: identifier).Path));
 }