public void ItRunsAppWhenRestoringToSpecificPackageDirectory()
        {
            var rootPath = TestAssets.CreateTestDirectory().FullName;

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

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

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

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

            new RunCommand()
            .WithWorkingDirectory(rootPath)
            .ExecuteWithCapturedOutput("--no-restore")
            .Should().Pass()
            .And.HaveStdOutContaining("Hello World");
        }
Exemplo n.º 2
0
        public void NewClassLibRestoresCorrectNetStandardLibraryVersion()
        {
            var rootPath          = TestAssets.CreateTestDirectory().FullName;
            var packagesDirectory = Path.Combine(rootPath, "packages");
            var projectName       = "Library";
            var projectFileName   = $"{projectName}.csproj";

            new NewCommand()
            .WithWorkingDirectory(rootPath)
            .Execute($"classlib --name {projectName} -o .")
            .Should().Pass();

            new RestoreCommand()
            .WithWorkingDirectory(rootPath)
            .Execute($"--packages {packagesDirectory}")
            .Should().Pass();

            var expectedVersion = XDocument.Load(Path.Combine(rootPath, projectFileName))
                                  .Elements("Project")
                                  .Elements("PropertyGroup")
                                  .Elements("NetStandardImplicitPackageVersion")
                                  .FirstOrDefault()
                                  ?.Value;

            expectedVersion.Should().NotBeNullOrEmpty("Could not find NetStandardImplicitPackageVersion property in a new classlib.");

            new DirectoryInfo(Path.Combine(packagesDirectory, "netstandard.library"))
            .Should().Exist()
            .And.HaveDirectory(expectedVersion);
        }
Exemplo n.º 3
0
        public void ItRunsWhenRestoringToSpecificPackageDir()
        {
            var rootPath = TestAssets.CreateTestDirectory().FullName;

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

            string newArgs = $"console -o \"{rootPath}\" --debug:ephemeral-hive";

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

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

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

            var outputDll = Directory.EnumerateFiles(Path.Combine(rootPath, "bin"), "*.dll", SearchOption.AllDirectories).Single();

            var outputRunCommand = new TestCommand("dotnet");

            outputRunCommand.ExecuteWithCapturedOutput(outputDll)
            .Should().Pass()
            .And.HaveStdOutContaining("Hello World");
        }
Exemplo n.º 4
0
        public void ItPacksAppWhenRestoringToSpecificPackageDirectory()
        {
            var rootPath = TestAssets.CreateTestDirectory().FullName;
            var rootDir  = new DirectoryInfo(rootPath);

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

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

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

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

            new PackCommand()
            .WithWorkingDirectory(rootPath)
            .ExecuteWithCapturedOutput("--no-restore")
            .Should()
            .Pass();

            rootDir
            .GetDirectory("bin")
            .Should().HaveFilesMatching("*.nupkg", SearchOption.AllDirectories);
        }
        public void WeCoverLatestAspNetCoreAppRollForward()
        {
            var    directory        = TestAssets.CreateTestDirectory();
            string projectDirectory = directory.FullName;

            //  Run "dotnet new web", get TargetFramework property, and make sure it's covered in SupportedAspNetCoreAppVersions

            new NewCommandShim()
            .WithWorkingDirectory(projectDirectory)
            .Execute("web --no-restore")
            .Should().Pass();

            string projectPath = Path.Combine(projectDirectory, Path.GetFileName(projectDirectory) + ".csproj");

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

            string targetFramework = project.Root.Element(ns + "PropertyGroup")
                                     .Element(ns + "TargetFramework")
                                     .Value;

            TargetFrameworkHelper.GetNetAppTargetFrameworks(SupportedAspNetCoreVersions.Versions)
            .Should().Contain(targetFramework, $"the {nameof(SupportedAspNetCoreVersions)} should include the default version " +
                              "of Microsoft.AspNetCore.App used by the templates created by \"dotnet new web\"");
        }
Exemplo n.º 6
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();

            //  Work-around for MVC template test until ASP.Net publishes Preview 5 'Microsoft.AspNetCore.Mvc.NewtonsoftJson' to NuGet.org
            string restoreArgs = string.Equals(templateName, "mvc", StringComparison.OrdinalIgnoreCase) ? "/p:RestoreAdditionalProjectSources=https://dotnetfeed.blob.core.windows.net/aspnet-aspnetcore/index.json" : "";

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

            new BuildCommand()
            .WithWorkingDirectory(projectDirectory)
            .Execute()
            .Should().Pass();
        }
Exemplo n.º 7
0
        public void ItRestoresLibToSpecificDirectory()
        {
            var rootPath = TestAssets.CreateTestDirectory().FullName;

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

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

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

            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);
        }
Exemplo n.º 8
0
        public void ItRestoresWithTheSpecifiedVerbosity()
        {
            var rootPath = TestAssets.CreateTestDirectory().FullName;

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

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

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

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

            new RestoreCommand()
            .WithWorkingDirectory(rootPath)
            .ExecuteWithCapturedOutput(args)
            .Should()
            .Pass()
            .And.NotHaveStdErr()
            .And.NotHaveStdOut();
        }
Exemplo n.º 9
0
        public void MigrationOutputsErrorWhenNoProjectsFounduseGlobalJson()
        {
            var projectDirectory = TestAssets.CreateTestDirectory("Migration_outputs_error_when_no_projects_found");

            string argstr = string.Empty;

            string errorMessage = string.Empty;


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

            using (StreamWriter sw = globalJson.CreateText())
            {
                sw.WriteLine("{");
                sw.WriteLine("\"projects\": [ \".\" ]");
                sw.WriteLine("}");
            }

            argstr = globalJson.FullName;

            errorMessage = "Unable to find any projects in global.json";

            Action runCommand = () => new MigrateTestCommand()
                                .WithWorkingDirectory(projectDirectory)
                                .ExecuteWithCapturedOutput($"{argstr}");

            runCommand.ShouldThrow <GracefulException>()
            .And
            .Message
            .Should()
            .Contain("Unable to find any projects in global.json.");
        }
Exemplo n.º 10
0
 public TestEnvironment(string identifier = "", [CallerMemberName] string callingMethod = "")
 {
     TestDirectory = TestAssets.CreateTestDirectory(
         "temp",
         identifier: identifier,
         callingMethod: callingMethod);
 }
Exemplo n.º 11
0
        public void GivenARootWithNonAsciiCharacterInstallSucceeds()
        {
            var nugetConfigPath = GenerateRandomNugetConfigFilePath();

            var    surrogate = char.ConvertFromUtf32(int.Parse("2A601", NumberStyles.HexNumber));
            string nonAscii  = "ab Ṱ̺̺̕o 田中さん åä," + surrogate;

            var root       = TestAssets.CreateTestDirectory(testProjectName: nonAscii, identifier: "root");
            var reporter   = new BufferedReporter();
            var fileSystem = new FileSystemWrapper();
            var store      = new ToolPackageStoreAndQuery(new DirectoryPath(root.FullName));

            WriteNugetConfigFileToPointToTheFeed(fileSystem, nugetConfigPath);
            var installer = new ToolPackageInstaller(
                store: store,
                projectRestorer: new Stage2ProjectRestorer(reporter),
                tempProject: GetUniqueTempProjectPathEachTest(),
                offlineFeed: new DirectoryPath("does not exist"));

            var package = installer.InstallPackage(new PackageLocation(nugetConfig: nugetConfigPath),
                                                   packageId: TestPackageId,
                                                   versionRange: VersionRange.Parse(TestPackageVersion),
                                                   targetFramework: _testTargetframework);

            AssertPackageInstall(reporter, fileSystem, package, store, store);

            new ToolPackageUninstaller(store).Uninstall(package.PackageDirectory);
        }
        public void ItFailsToPublishWithNoBuildIfPreviouslyBuiltWithoutRid()
        {
            var rootPath = TestAssets.CreateTestDirectory().FullName;
            var rootDir  = new DirectoryInfo(rootPath);

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

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

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

            new PublishCommand()
            .WithWorkingDirectory(rootPath)
            .ExecuteWithCapturedOutput("-r win-x64 --no-build")
            .Should()
            .Fail();
        }
Exemplo n.º 13
0
        public void ItRestoresAppToSpecificDirectory()
        {
            var rootPath = TestAssets.CreateTestDirectory().FullName;

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

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

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

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

            Directory.Exists(fullPath).Should().BeTrue();
            Directory.EnumerateFiles(fullPath, "*.dll", SearchOption.AllDirectories).Count().Should().BeGreaterThan(0);
        }
        static GivenThatTheUserIsRunningDotNetForTheFirstTime()
        {
            _testDirectory = TestAssets.CreateTestDirectory("Dotnet_first_time_experience_tests").FullName;
            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()
                          .WithWorkingDirectory(_testDirectory);

            command.Environment["HOME"]        = testNuGetHome;
            command.Environment["USERPROFILE"] = testNuGetHome;
            command.Environment["APPDATA"]     = testNuGetHome;
            command.Environment["DOTNET_CLI_TEST_FALLBACKFOLDER"]      = cliTestFallbackFolder;
            command.Environment["DOTNET_CLI_TEST_LINUX_PROFILED_PATH"] = profiled;
            command.Environment["DOTNET_CLI_TEST_OSX_PATHSD_PATH"]     = pathsd;
            command.Environment["SkipInvalidConfigurations"]           = "true";

            _firstDotnetNonVerbUseCommandResult = command.ExecuteWithCapturedOutput("--info");
            _firstDotnetVerbUseCommandResult    = command.ExecuteWithCapturedOutput("new --debug:ephemeral-hive");

            _nugetFallbackFolder = new DirectoryInfo(cliTestFallbackFolder);
            _dotDotnetFolder     = new DirectoryInfo(Path.Combine(testNuGetHome, ".dotnet"));
        }
        public void TemplateRestoresAndBuildsWithoutWarnings(
            string language,
            string projectType,
            bool skipSpaWebpackSteps)
        {
            string rootPath           = TestAssets.CreateTestDirectory(identifier: $"{language}_{projectType}").FullName;
            string noRestoreDirective = "--no-restore";

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

            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"));
                Directory.CreateDirectory(Path.Combine(rootPath, "ClientApp", "node_modules"));
                Directory.CreateDirectory(Path.Combine(rootPath, "node_modules"));
            }

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

            var buildResult = new TestCommand("dotnet")
                              .WithWorkingDirectory(rootPath)
                              .ExecuteWithCapturedOutput("build --no-restore")
                              .Should().Pass()
                              .And.NotHaveStdErr();
        }
Exemplo n.º 16
0
        public void TemplateRestoresAndBuildsWithoutWarnings(
            string language,
            string projectType,
            bool useNuGetConfigForAspNet)
        {
            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"));
            }

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

            var buildResult = new TestCommand("dotnet")
                              .WithWorkingDirectory(rootPath)
                              .ExecuteWithCapturedOutput("build")
                              .Should().Pass()
                              .And.NotHaveStdErr();
        }
Exemplo n.º 17
0
        public void ItCanPublishArm64Wpf(string TargetFramework)
        {
            DirectoryInfo directory                = TestAssets.CreateTestDirectory();
            string        projectDirectory         = directory.FullName;
            string        TargetFrameworkParameter = "";

            if (TargetFramework != "current")
            {
                TargetFrameworkParameter = $"-f {TargetFramework}";
            }

            string newArgs = $"wpf {TargetFrameworkParameter} --no-restore";

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

            string publishArgs = "-r win-arm64";

            new PublishCommand()
            .WithWorkingDirectory(projectDirectory)
            .Execute(publishArgs)
            .Should().Pass();

            var selfContainedPublishDir = new DirectoryInfo(projectDirectory)
                                          .Sub("bin").Sub("Debug").GetDirectories().FirstOrDefault()
                                          .Sub("win-arm64").Sub("publish");

            selfContainedPublishDir.Should().HaveFilesMatching("PresentationCore.dll", SearchOption.TopDirectoryOnly);
            selfContainedPublishDir.Should().HaveFilesMatching("PresentationNative_*.dll", SearchOption.TopDirectoryOnly);
            selfContainedPublishDir.Should().HaveFilesMatching($"{directory.Name}.dll", SearchOption.TopDirectoryOnly);
        }
        public void ItCanPublishArm64Winforms()
        {
            DirectoryInfo directory        = TestAssets.CreateTestDirectory();
            string        projectDirectory = directory.FullName;

            string newArgs = "winforms --no-restore";

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

            string publishArgs = "-r win-arm64";

            new PublishCommand()
            .WithWorkingDirectory(projectDirectory)
            .Execute(publishArgs)
            .Should().Pass();

            var selfContainedPublishDir = new DirectoryInfo(projectDirectory)
                                          .Sub("bin").Sub("Debug").GetDirectories().FirstOrDefault()
                                          .Sub("win-arm64").Sub("publish");

            selfContainedPublishDir.Should().HaveFilesMatching("System.Windows.Forms.dll", SearchOption.TopDirectoryOnly);
            selfContainedPublishDir.Should().HaveFilesMatching($"{directory.Name}.dll", SearchOption.TopDirectoryOnly);
        }
        public void ItCanRunAnAppUsingTheWebSdk()
        {
            var    directory        = TestAssets.CreateTestDirectory();
            string projectDirectory = directory.FullName;

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

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

            string projectPath = Path.Combine(projectDirectory, directory.Name + ".csproj");

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

            project.Root.Attribute("Sdk").Value = "Microsoft.NET.Sdk.Web";

            project.Save(projectPath);

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

            var runCommand = new RunCommand()
                             .WithWorkingDirectory(projectDirectory)
                             .ExecuteWithCapturedOutput()
                             .Should().Pass().And.HaveStdOutContaining("Hello World!");
        }
Exemplo n.º 20
0
        public void ItCanRunAnAppUsingTheWebSdk()
        {
            var    directory        = TestAssets.CreateTestDirectory();
            string projectDirectory = directory.FullName;

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

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

            string projectPath = Path.Combine(projectDirectory, directory.Name + ".csproj");

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

            project.Root.Attribute("Sdk").Value = "Microsoft.NET.Sdk.Web";

            project.Save(projectPath);

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

            var runCommand = new RunCommand()
                             .WithWorkingDirectory(projectDirectory);

            runCommand.ExecuteWithCapturedOutput()
            // Templates are still at 3.0 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-download");
        }
Exemplo n.º 21
0
        public void WhenRunOnNonWindowsReturnFalse()
        {
            var testFile = Path.Combine(TestAssets.CreateTestDirectory().FullName, Path.GetRandomFileName());

            File.WriteAllText(testFile, string.Empty);

            new DangerousFileDetector().IsDangerous(testFile).Should().BeFalse();
        }
        private string CreateFile([CallerMemberName] string callerName = null)
        {
            var folder   = TestAssets.CreateTestDirectory(callingMethod: callerName, testProjectName: "tempfile");
            var filename = Path.Combine(folder.FullName, Guid.NewGuid().ToString() + ".tmp");

            using (new FileStream(filename, FileMode.CreateNew)) { }
            return(filename);
        }
Exemplo n.º 23
0
        public void ItCanNewRestoreBuildRunCleanMSBuildProject()
        {
            var    directory        = TestAssets.CreateTestDirectory();
            string projectDirectory = directory.FullName;

            string newArgs   = "console --debug:ephemeral-hive --no-restore";
            var    newResult = new NewCommandShim()
                               .WithWorkingDirectory(projectDirectory)
                               .ExecuteWithCapturedOutput(newArgs);

            newResult.Should().Pass();

            string projectPath = Directory.GetFiles(projectDirectory, "*.csproj").Single();

            //  Override TargetFramework since there aren't .NET Core 3 templates yet
            //  https://github.com/dotnet/core-sdk/issues/24 tracks removing this workaround
            XDocument project = XDocument.Load(projectPath);
            var       ns      = project.Root.Name.Namespace;

            project.Root.Element(ns + "PropertyGroup")
            .Element(ns + "TargetFramework")
            .Value = "netcoreapp3.0";
            project.Save(projectPath);


            new RestoreCommand()
            .WithWorkingDirectory(projectDirectory)
            .Execute("/p:SkipInvalidConfigurations=true")
            .Should().Pass();

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

            var runCommand = new RunCommand()
                             .WithWorkingDirectory(projectDirectory);

            //  Set DOTNET_ROOT as workaround for https://github.com/dotnet/cli/issues/10196
            runCommand = runCommand.WithEnvironmentVariable(Environment.Is64BitProcess ? "DOTNET_ROOT": "DOTNET_ROOT(x86)",
                                                            Path.GetDirectoryName(DotnetUnderTest.FullName));

            runCommand.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);
        }
Exemplo n.º 24
0
            public TestPackagesFixture()
            {
                TestPackagesDirectory = SetupTestPackages();

                TestNuGetCache = TestAssets.CreateTestDirectory(testProjectName: string.Empty,
                                                                callingMethod: "packages",
                                                                identifier: string.Empty)
                                 .FullName;
            }
Exemplo n.º 25
0
        private static void TestTemplateCreateAndBuild(string templateName, bool build = true, bool selfContained = false, string language = "", string framework = "")
        {
            DirectoryInfo directory        = TestAssets.CreateTestDirectory(identifier: string.IsNullOrWhiteSpace(language) ? templateName : $"{templateName}[{language}]");
            string        projectDirectory = directory.FullName;

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

            if (!string.IsNullOrWhiteSpace(language))
            {
                newArgs += $" --language {language}";
            }

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

            if (!string.IsNullOrWhiteSpace(framework))
            {
                //check if MSBuild TargetFramework property for *proj is set to expected framework
                string expectedExtension = language switch
                {
                    "C#" => "*.csproj",
                    "F#" => "*.fsproj",
                    "VB" => "*.vbproj",
                    _ => "*.csproj"
                };
                string     projectFile = Directory.GetFiles(projectDirectory, expectedExtension).Single();
                XDocument  projectXml  = XDocument.Load(projectFile);
                XNamespace ns          = projectXml.Root.Name.Namespace;
                Assert.Equal(framework, projectXml.Root.Element(ns + "PropertyGroup").Element(ns + "TargetFramework").Value);
            }

            if (build)
            {
                string buildArgs = selfContained ? "" : $"-r {RuntimeInformation.RuntimeIdentifier}";
                if (!string.IsNullOrWhiteSpace(framework))
                {
                    buildArgs += $" --framework {framework}";
                }

                // Remove this (or formalize it) after https://github.com/dotnet/installer/issues/12479 is resolved.
                if (language == "F#")
                {
                    buildArgs += $" /p:_NETCoreSdkIsPreview=true";
                }

                string 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();
            }
        }
    }
Exemplo n.º 26
0
                        ) Setup(
            bool useMock,
            List <MockFeed> feeds     = null,
            FilePath?tempProject      = null,
            DirectoryPath?offlineFeed = null)
        {
            var root     = new DirectoryPath(TestAssets.CreateTestDirectory("root").FullName);
            var reporter = new BufferedReporter();

            IFileSystem             fileSystem;
            IToolPackageStore       store;
            IToolPackageStoreQuery  storeQuery;
            IToolPackageInstaller   installer;
            IToolPackageUninstaller uninstaller;

            if (useMock)
            {
                var packagedShimsMap = new Dictionary <PackageId, IReadOnlyList <FilePath> >
                {
                    [TestPackageId] = new FilePath[] { new FilePath("path/demo.exe") }
                };

                fileSystem = new FileSystemMockBuilder().Build();
                var toolPackageStoreMock = new ToolPackageStoreMock(root, fileSystem);
                store      = toolPackageStoreMock;
                storeQuery = toolPackageStoreMock;
                installer  = new ToolPackageInstallerMock(
                    fileSystem: fileSystem,
                    store: toolPackageStoreMock,
                    projectRestorer: new ProjectRestorerMock(
                        fileSystem: fileSystem,
                        reporter: reporter,
                        feeds: feeds),
                    packagedShimsMap: packagedShimsMap);
                uninstaller = new ToolPackageUninstallerMock(fileSystem, toolPackageStoreMock);
            }
            else
            {
                fileSystem = new FileSystemWrapper();
                var toolPackageStore = new ToolPackageStoreAndQuery(root);
                store      = toolPackageStore;
                storeQuery = toolPackageStore;
                installer  = new ToolPackageInstaller(
                    store: store,
                    projectRestorer: new Stage2ProjectRestorer(reporter),
                    tempProject: tempProject ?? GetUniqueTempProjectPathEachTest(),
                    offlineFeed: offlineFeed ?? new DirectoryPath("does not exist"));
                uninstaller = new ToolPackageUninstaller(store);
            }

            store.Root.Value.Should().Be(Path.GetFullPath(root.Value));

            return(store, storeQuery, installer, uninstaller, reporter, fileSystem);
        }
Exemplo n.º 27
0
                        ) Setup(
            bool useMock,
            List <MockFeed> feeds                   = null,
            FilePath?tempProject                    = null,
            DirectoryPath?offlineFeed               = null,
            FilePath?writeLocalFeedToNugetConfig    = null,
            [CallerMemberName] string callingMethod = "")
        {
            var root     = new DirectoryPath(TestAssets.CreateTestDirectory("root", callingMethod, identifier: useMock.ToString()).FullName);
            var reporter = new BufferedReporter();

            IFileSystem             fileSystem;
            IToolPackageStore       store;
            IToolPackageStoreQuery  storeQuery;
            IToolPackageInstaller   installer;
            IToolPackageUninstaller uninstaller;

            if (useMock)
            {
                fileSystem = new FileSystemMockBuilder().Build();
                WriteNugetConfigFileToPointToTheFeed(fileSystem, writeLocalFeedToNugetConfig);
                var toolPackageStoreMock = new ToolPackageStoreMock(root, fileSystem);
                store      = toolPackageStoreMock;
                storeQuery = toolPackageStoreMock;
                installer  = new ToolPackageInstallerMock(
                    fileSystem: fileSystem,
                    store: toolPackageStoreMock,
                    projectRestorer: new ProjectRestorerMock(
                        fileSystem: fileSystem,
                        reporter: reporter,
                        feeds: feeds == null
                            ? GetMockFeedsForConfigFile(writeLocalFeedToNugetConfig)
                            : feeds.Concat(GetMockFeedsForConfigFile(writeLocalFeedToNugetConfig)).ToList()));
                uninstaller = new ToolPackageUninstallerMock(fileSystem, toolPackageStoreMock);
            }
            else
            {
                fileSystem = new FileSystemWrapper();
                WriteNugetConfigFileToPointToTheFeed(fileSystem, writeLocalFeedToNugetConfig);
                var toolPackageStore = new ToolPackageStoreAndQuery(root);
                store      = toolPackageStore;
                storeQuery = toolPackageStore;
                installer  = new ToolPackageInstaller(
                    store: store,
                    projectRestorer: new Stage2ProjectRestorer(reporter),
                    tempProject: tempProject ?? GetUniqueTempProjectPathEachTest(),
                    offlineFeed: offlineFeed ?? new DirectoryPath("does not exist"));
                uninstaller = new ToolPackageUninstaller(store);
            }

            store.Root.Value.Should().Be(Path.GetFullPath(root.Value));

            return(store, storeQuery, installer, uninstaller, reporter, fileSystem);
        }
Exemplo n.º 28
0
            public TestEnvironment(string identifier = "", [CallerMemberName] string callingMethod = "")
            {
                TestDirectory = TestAssets.CreateTestDirectory(
                    "temp",
                    identifier: identifier,
                    callingMethod: callingMethod);

                DeleteMinimumVSDefinedSDKVersionFile();

                PathEnvironmentVariable = string.Empty;
            }
Exemplo n.º 29
0
        public void WhenDotnetRunHelpIsInvokedAppArgumentsTextIsIncludedInOutput()
        {
            const string AppArgumentsText = "Arguments passed to the application that is being run.";

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

            result.ExitCode.Should().Be(0);
            result.StdOut.Should().Contain(AppArgumentsText);
        }
Exemplo n.º 30
0
        public void When_help_is_invoked_Then_MSBuild_extra_options_text_is_included_in_output(string commandName)
        {
            const string MSBuildHelpText = " Any extra options that should be passed to MSBuild. See 'dotnet msbuild -h' for available options.";

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

            result.ExitCode.Should().Be(0);
            result.StdOut.Should().Contain(MSBuildHelpText);
        }