Пример #1
0
 public CommandSpec Resolve(CommandResolverArguments commandResolverArguments)
 {
     if (commandResolverArguments.CommandName == Muxer.MuxerName)
     {
         var muxer = new Muxer();
         var escapedArgs = ArgumentEscaper.EscapeAndConcatenateArgArrayForProcessStart(
             commandResolverArguments.CommandArguments.OrEmptyIfNull());
         return new CommandSpec(muxer.MuxerPath, escapedArgs, CommandResolutionStrategy.RootedPath);
     }
     return null;
 }
        internal override string ResolveCommandPath(CommandResolverArguments commandResolverArguments)
        {
            if (commandResolverArguments.ProjectDirectory == null)
            {
                return null;
            }

            return _environment.GetCommandPathFromRootPath(
                commandResolverArguments.ProjectDirectory,
                commandResolverArguments.CommandName,
                commandResolverArguments.InferredExtensions.OrEmptyIfNull());
        }
        public void It_returns_null_when_CommandName_does_not_exist_applocal()
        {
            var appBaseCommandResolver = SetupPlatformAppBaseCommandResolver(forceGeneric: true);

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName = "nonexistent-command",
                CommandArguments = null
            };

            var result = appBaseCommandResolver.Resolve(commandResolverArguments);

            result.Should().BeNull();
        }
        public void It_returns_null_when_CommandName_is_not_rooted()
        {
            var rootedCommandResolver = new RootedCommandResolver();

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName = "some/relative/path",
                CommandArguments = null
            };

            var result = rootedCommandResolver.Resolve(commandResolverArguments);

            result.Should().BeNull();
        }
        public void It_returns_null_when_CommandName_is_null()
        {
            var appBaseCommandResolver = SetupPlatformAppBaseCommandResolver(forceGeneric: true);

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName = null,
                CommandArguments = null
            };

            var result = appBaseCommandResolver.Resolve(commandResolverArguments);

            result.Should().BeNull();
        }
        public void It_returns_null_when_CommandName_is_null()
        {
            var projectToolsCommandResolver = SetupProjectToolsCommandResolver();

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName = null,
                CommandArguments = new string[] { "" },
                ProjectDirectory = "/some/directory"
            };

            var result = projectToolsCommandResolver.Resolve(commandResolverArguments);

            result.Should().BeNull();
        }
        public void It_returns_null_when_CommandName_does_not_exist_in_ProjectTools()
        {
            var projectToolsCommandResolver = SetupProjectToolsCommandResolver();

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName = "nonexistent-command",
                CommandArguments = null,
                ProjectDirectory = s_liveProjectDirectory
            };

            var result = projectToolsCommandResolver.Resolve(commandResolverArguments);

            result.Should().BeNull();
        }
        public void It_returns_a_CommandSpec_with_CommandName_as_Path_when_CommandName_is_rooted()
        {
            var rootedCommandResolver = new RootedCommandResolver();

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName = "/some/rooted/path",
                CommandArguments = null
            };

            var result = rootedCommandResolver.Resolve(commandResolverArguments);

            result.Should().NotBeNull();
            result.Path.Should().Be(commandResolverArguments.CommandName);
        }
        public void It_returns_null_when_ProjectDirectory_is_null()
        {
            var projectPathCommandResolver = SetupPlatformProjectPathCommandResolver(forceGeneric: true);

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

            var result = projectPathCommandResolver.Resolve(commandResolverArguments);

            result.Should().BeNull();
        }
        public void It_returns_null_when_CommandName_does_not_exist_in_ProjectDirectory()
        {
            var projectPathCommandResolver = SetupPlatformProjectPathCommandResolver(forceGeneric: true);

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName = "nonexistent-command",
                CommandArguments = null,
                ProjectDirectory = s_testProjectDirectory
            };

            var result = projectPathCommandResolver.Resolve(commandResolverArguments);

            result.Should().BeNull();
        }
        public void It_escapes_CommandArguments_when_returning_a_CommandSpec()
        {
            var rootedCommandResolver = new RootedCommandResolver();

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName = "/some/rooted/path",
                CommandArguments = new[] { "arg with space" }
            };

            var result = rootedCommandResolver.Resolve(commandResolverArguments);

            result.Should().NotBeNull();
            result.Path.Should().Be(commandResolverArguments.CommandName);

            result.Args.Should().Be("\"arg with space\"");
        }
        public void It_returns_null_when_Framework_is_null()
        {
            var projectDependenciesCommandResolver = SetupProjectDependenciesCommandResolver();

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName = "command",
                CommandArguments = new string[] { "" },
                ProjectDirectory = s_liveProjectDirectory,
                Configuration = "Debug",
                Framework = null
            };

            var result = projectDependenciesCommandResolver.Resolve(commandResolverArguments);

            result.Should().BeNull();
        }
        public void It_returns_null_when_ProjectDirectory_is_null()
        {
            var projectDependenciesCommandResolver = SetupProjectDependenciesCommandResolver();

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName = "command",
                CommandArguments = new string[] { "" },
                ProjectDirectory = null,
                Configuration = "Debug",
                Framework = FrameworkConstants.CommonFrameworks.NetCoreApp10
            };

            var result = projectDependenciesCommandResolver.Resolve(commandResolverArguments);

            result.Should().BeNull();
        }
        public void It_returns_null_when_CommandName_exists_applocal_in_a_subdirectory()
        {
            var environment = CommandResolverTestUtils.SetupEnvironmentProviderWhichFindsExtensions(".exe");
            var appBaseCommandResolver = SetupPlatformAppBaseCommandResolver(environment, forceGeneric: true);

            var testDir = Path.Combine(AppContext.BaseDirectory, "appbasetestsubdir");
            CommandResolverTestUtils.CreateNonRunnableTestCommand(testDir, "appbasetestsubdircommand", ".exe");

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName = "appbasetestsubdircommand",
                CommandArguments = null
            };

            var result = appBaseCommandResolver.Resolve(commandResolverArguments);

            result.Should().BeNull();
        }
        public void It_returns_null_when_CommandName_exists_in_a_subdirectory_of_ProjectDirectory()
        {
            var environment = CommandResolverTestUtils.SetupEnvironmentProviderWhichFindsExtensions(".exe");
            var projectPathCommandResolver = SetupPlatformProjectPathCommandResolver(environment, forceGeneric: true);

            var testDir = Path.Combine(s_testProjectDirectory, "projectpathtestsubdir");
            CommandResolverTestUtils.CreateNonRunnableTestCommand(testDir, "projectpathtestsubdircommand", ".exe");

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName = "projectpathtestsubdircommand",
                CommandArguments = null,
                ProjectDirectory = s_testProjectDirectory
            };

            var result = projectPathCommandResolver.Resolve(commandResolverArguments);

            result.Should().BeNull();
        }
Пример #16
0
        public void It_returns_a_CommandSpec_with_CommandName_as_FileName_when_CommandName_exists_applocal()
        {
            var environment            = CommandResolverTestUtils.SetupEnvironmentProviderWhichFindsExtensions(".exe");
            var appBaseCommandResolver = SetupPlatformAppBaseCommandResolver(environment, forceGeneric: true);

            CommandResolverTestUtils.CreateNonRunnableTestCommand(AppContext.BaseDirectory, "appbasetestcommand1", ".exe");

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName      = "appbasetestcommand1",
                CommandArguments = null
            };

            var result = appBaseCommandResolver.Resolve(commandResolverArguments);

            result.Should().NotBeNull();

            var commandFile = Path.GetFileNameWithoutExtension(result.Path);

            commandFile.Should().Be("appbasetestcommand1");
        }
Пример #17
0
        public void It_returns_a_CommandSpec_with_Args_as_CommandPath_when_returning_a_CommandSpec_and_CommandArguments_are_null()
        {
            var projectToolsCommandResolver = SetupProjectToolsCommandResolver();

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName      = "dotnet-hello",
                CommandArguments = null,
                ProjectDirectory = s_liveProjectDirectory
            };

            var result = projectToolsCommandResolver.Resolve(commandResolverArguments);

            result.Should().NotBeNull();

            var commandPath = result.Args.Trim('"');

            commandPath.Should().Contain("dotnet-hello");

            File.Exists(commandPath).Should().BeTrue();
        }
Пример #18
0
        public void It_returns_a_CommandSpec_with_CoreHost_as_FileName_and_CommandName_in_Args_when_CommandName_exists_in_ProjectTools()
        {
            var projectToolsCommandResolver = SetupProjectToolsCommandResolver();

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName      = "dotnet-hello",
                CommandArguments = null,
                ProjectDirectory = s_liveProjectDirectory
            };

            var result = projectToolsCommandResolver.Resolve(commandResolverArguments);

            result.Should().NotBeNull();

            var commandFile = Path.GetFileNameWithoutExtension(result.Path);

            commandFile.Should().Be("corehost");

            result.Args.Should().Contain(commandResolverArguments.CommandName);
        }
Пример #19
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\"");
        }
        public void It_returns_a_CommandSpec_with_DOTNET_as_FileName_and_CommandName_in_Args_when_CommandName_exists_in_ProjectTools()
        {
            var projectToolsCommandResolver = SetupProjectToolsCommandResolver();

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName = "dotnet-portable",
                CommandArguments = null,
                ProjectDirectory = s_liveProjectDirectory
            };

            var result = projectToolsCommandResolver.Resolve(commandResolverArguments);

            result.Should().NotBeNull();

            var commandFile = Path.GetFileNameWithoutExtension(result.Path);

            commandFile.Should().Be("dotnet");

            result.Args.Should().Contain(commandResolverArguments.CommandName);
        }
        public void It_returns_a_CommandSpec_with_CommandName_as_FileName_when_CommandName_exists_applocal()
        {
            var environment = CommandResolverTestUtils.SetupEnvironmentProviderWhichFindsExtensions(".exe");
            var appBaseCommandResolver = SetupPlatformAppBaseCommandResolver(environment, forceGeneric: true);

            CommandResolverTestUtils.CreateNonRunnableTestCommand(AppContext.BaseDirectory, "appbasetestcommand1", ".exe");

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName = "appbasetestcommand1",
                CommandArguments = null
            };

            var result = appBaseCommandResolver.Resolve(commandResolverArguments);

            result.Should().NotBeNull();

            var commandFile = Path.GetFileNameWithoutExtension(result.Path);

            commandFile.Should().Be("appbasetestcommand1");
        }
Пример #22
0
        public void It_returns_a_CommandSpec_with_CommandName_as_FileName_when_CommandName_exists_in_ProjectDirectory()
        {
            var environment = CommandResolverTestUtils.SetupEnvironmentProviderWhichFindsExtensions(".exe");
            var projectPathCommandResolver = SetupPlatformProjectPathCommandResolver(environment, forceGeneric: true);

            CommandResolverTestUtils.CreateNonRunnableTestCommand(s_testProjectDirectory, "projectpathtestcommand1", ".exe");

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName      = "projectpathtestcommand1",
                CommandArguments = null,
                ProjectDirectory = s_testProjectDirectory
            };

            var result = projectPathCommandResolver.Resolve(commandResolverArguments);

            result.Should().NotBeNull();

            var commandFile = Path.GetFileNameWithoutExtension(result.Path);

            commandFile.Should().Be("projectpathtestcommand1");
        }
        public void ItSetsDepsfileToOutputInCommandspecForMSBuild()
        {
            var testAsset =
                _testAssetsManager.CopyTestAsset("TestAppWithProjDepTool")
                .WithSource();

            NuGetConfigWriter.Write(testAsset.Path, TestContext.Current.TestPackages);

            new RestoreCommand(testAsset)
            .Execute()
            .Should()
            .Pass();

            var projectDependenciesCommandResolver = SetupProjectDependenciesCommandResolver();

            var outputDir = Path.Combine(testAsset.Path, "out");

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName      = "dotnet-portable",
                Configuration    = "Debug",
                ProjectDirectory = testAsset.Path,
                Framework        = NuGet.Frameworks.FrameworkConstants.CommonFrameworks.NetCoreApp30,
                OutputPath       = outputDir
            };

            new DotnetBuildCommand(Log)
            .WithWorkingDirectory(testAsset.Path)
            .Execute($"-o", outputDir)
            .Should()
            .Pass();

            var result = projectDependenciesCommandResolver.Resolve(commandResolverArguments);

            var depsFilePath = Path.Combine(outputDir, "TestAppWithProjDepTool.deps.json");

            result.Should().NotBeNull();
            result.Args.Should().Contain($"--depsfile {depsFilePath}");
        }
Пример #24
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");
        }
Пример #25
0
        public void ItReturnsNullWhenCommandNameDoesNotExistInProjectTools()
        {
            var projectToolsCommandResolver = SetupProjectToolsCommandResolver();

            var testInstance = _testAssetsManager.CopyTestAsset(TestProjectName)
                               .WithSource();

            NuGetConfigWriter.Write(testInstance.Path, TestContext.Current.TestPackages);

            testInstance.Restore(Log);

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName      = "nonexistent-command",
                CommandArguments = null,
                ProjectDirectory = testInstance.Path
            };

            var result = projectToolsCommandResolver.Resolve(commandResolverArguments);

            result.Should().BeNull();
        }
        public void It_passes_depsfile_arg_to_host_when_returning_a_CommandSpec()
        {
            var projectDependenciesCommandResolver = SetupProjectDependenciesCommandResolver();

            var testInstance = TestAssetsManager.CreateTestInstance(ProjectJsonTestProjectName)
                               .WithBuildArtifacts()
                               .WithLockFiles();

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName      = "dotnet-hello",
                CommandArguments = null,
                ProjectDirectory = testInstance.Path,
                Configuration    = "Debug",
                Framework        = FrameworkConstants.CommonFrameworks.NetCoreApp10
            };

            var result = projectDependenciesCommandResolver.Resolve(commandResolverArguments);

            result.Should().NotBeNull();
            result.Args.Should().Contain("--depsfile");
        }
        public void ItReturnsNullWhenCommandNameDoesNotExistInProjectDependenciesForMSBuildProject()
        {
            MSBuildTestProjectInstance =
                TestAssets.Get("TestAppWithProjDepTool")
                .CreateInstance()
                .WithSourceFiles()
                .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();
        }
        public void It_returns_a_CommandSpec_with_Args_containing_CommandPath_when_returning_a_CommandSpec_and_CommandArguments_are_null()
        {
            var projectToolsCommandResolver = SetupProjectToolsCommandResolver();

            var testInstance = TestAssetsManager.CreateTestInstance(TestProjectName)
                               .WithLockFiles();

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

            var result = projectToolsCommandResolver.Resolve(commandResolverArguments);

            result.Should().NotBeNull();

            var commandPath = result.Args.Trim('"');

            commandPath.Should().Contain("dotnet-portable.dll");
        }
        public void It_does_not_add_fx_version_as_a_param_when_the_tool_does_not_have_the_prefercliruntime_file()
        {
            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");
        }
        public void It_sets_depsfile_in_build_base_path_in_commandspec()
        {
            var projectDependenciesCommandResolver = SetupProjectDependenciesCommandResolver();

            var testInstance = TestAssetsManager.CreateTestInstance(ProjectJsonTestProjectName)
                               .WithLockFiles();

            var buildBasePath = Path.Combine(testInstance.Path, "basedir");

            var commandResolverArguments = new CommandResolverArguments
            {
                CommandName      = "dotnet-hello",
                CommandArguments = null,
                ProjectDirectory = testInstance.Path,
                Configuration    = "Debug",
                Framework        = FrameworkConstants.CommonFrameworks.NetCoreApp10,
                BuildBasePath    = buildBasePath
            };

            var buildCommand = new BuildCommand(
                Path.Combine(testInstance.Path, "project.json"),
                buildBasePath: buildBasePath,
                framework: FrameworkConstants.CommonFrameworks.NetCoreApp10.ToString())
                               .Execute().Should().Pass();

            var projectContext = ProjectContext.Create(
                testInstance.Path,
                FrameworkConstants.CommonFrameworks.NetCoreApp10,
                DotnetRuntimeIdentifiers.InferCurrentRuntimeIdentifiers(DotnetFiles.VersionFileObject));

            var depsFilePath =
                projectContext.GetOutputPaths("Debug", buildBasePath).RuntimeFiles.DepsJson;

            var result = projectDependenciesCommandResolver.Resolve(commandResolverArguments);

            result.Should().NotBeNull();
            result.Args.Should().Contain($"--depsfile {depsFilePath}");
        }
Пример #31
0
        public void It_sets_depsfile_in_output_path_in_commandspec()
        {
            var projectDependenciesCommandResolver = SetupProjectDependenciesCommandResolver();

            var testInstance = TestAssetsManager.CreateTestInstance(TestProjectName)
                               .WithLockFiles();

            var outputDir = Path.Combine(testInstance.Path, "outdir");

            var commandResolverArguments = new CommandResolverArguments
            {
                CommandName      = "dotnet-hello",
                CommandArguments = null,
                ProjectDirectory = testInstance.Path,
                Configuration    = "Debug",
                Framework        = FrameworkConstants.CommonFrameworks.NetCoreApp10,
                OutputPath       = outputDir
            };

            var buildCommand = new BuildCommand(
                Path.Combine(testInstance.Path, "project.json"),
                output: outputDir,
                framework: FrameworkConstants.CommonFrameworks.NetCoreApp10.ToString())
                               .Execute().Should().Pass();

            var projectContext = ProjectContext.Create(
                testInstance.Path,
                FrameworkConstants.CommonFrameworks.NetCoreApp10,
                RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers());

            var depsFilePath =
                projectContext.GetOutputPaths("Debug", outputPath: outputDir).RuntimeFiles.DepsJson;

            var result = projectDependenciesCommandResolver.Resolve(commandResolverArguments);

            result.Should().NotBeNull();
            result.Args.Should().Contain($"--depsfile {depsFilePath}");
        }
Пример #32
0
        public void ItEscapesCommandArgumentsWhenReturningACommandSpec()
        {
            var projectToolsCommandResolver = SetupProjectToolsCommandResolver();

            var testInstance = _testAssetsManager.CopyTestAsset(TestProjectName)
                               .WithSource();

            NuGetConfigWriter.Write(testInstance.Path, TestContext.Current.TestPackages);

            testInstance.Restore(Log);

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

            var result = projectToolsCommandResolver.Resolve(commandResolverArguments);

            result.Should().NotBeNull("Because the command is a project tool dependency");
            result.Args.Should().Contain("\"arg with space\"");
        }
Пример #33
0
        public void ItReturnsACommandSpecWithDotnetAsFileNameAndCommandNameInArgsWhenCommandNameExistsInMSBuildProjectDependencies()
        {
            var projectDependenciesCommandResolver = SetupProjectDependenciesCommandResolver();

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName      = "dotnet-portable",
                CommandArguments = null,
                ProjectDirectory = MSBuildTestProjectInstance.Path,
                Configuration    = _configuration,
                Framework        = FrameworkConstants.CommonFrameworks.NetCoreApp10
            };

            var result = projectDependenciesCommandResolver.Resolve(commandResolverArguments);

            result.Should().NotBeNull();

            var commandFile = Path.GetFileNameWithoutExtension(result.Path);

            commandFile.Should().Be("dotnet");

            result.Args.Should().Contain(commandResolverArguments.CommandName);
        }
Пример #34
0
        public void It_returns_a_CommandSpec_with_CoreHost_as_FileName_and_CommandName_in_Args_when_CommandName_exists_in_ProjectDependencies()
        {
            var projectDependenciesCommandResolver = SetupProjectDependenciesCommandResolver();

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName      = "dotnet-hello",
                CommandArguments = null,
                ProjectDirectory = s_liveProjectDirectory,
                Configuration    = "Debug",
                Framework        = FrameworkConstants.CommonFrameworks.NetStandardApp15
            };

            var result = projectDependenciesCommandResolver.Resolve(commandResolverArguments);

            result.Should().NotBeNull();

            var commandFile = Path.GetFileNameWithoutExtension(result.Path);

            commandFile.Should().Be("corehost");

            result.Args.Should().Contain(commandResolverArguments.CommandName);
        }
Пример #35
0
        public void ItSetsDepsfileToOutputInCommandspecForMSBuild()
        {
            var projectDependenciesCommandResolver = SetupProjectDependenciesCommandResolver();

            var testInstance = TestAssetsManager.CreateTestInstance("MSBuildTestAppWithToolInDependencies");

            var outputDir = Path.Combine(testInstance.Path, "out");

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName      = "dotnet-portable",
                CommandArguments = null,
                ProjectDirectory = testInstance.Path,
                Configuration    = _configuration,
                Framework        = FrameworkConstants.CommonFrameworks.NetCoreApp10,
                OutputPath       = outputDir
            };

            new Restore3Command()
            .WithWorkingDirectory(testInstance.Path)
            .Execute($"-s {_repoDirectoriesProvider.TestPackages}")
            .Should()
            .Pass();

            new Build3Command()
            .WithWorkingDirectory(testInstance.Path)
            .Execute($"-c {_configuration} -o {outputDir}")
            .Should()
            .Pass();

            var result = projectDependenciesCommandResolver.Resolve(commandResolverArguments);

            var depsFilePath = Path.Combine(outputDir, "MSBuildTestAppWithToolInDependencies.deps.json");

            result.Should().NotBeNull();
            result.Args.Should().Contain($"--depsfile {depsFilePath}");
        }
Пример #36
0
        public void ItDoesNotAddFxVersionAsAParamWhenTheToolDoesNotHaveThePrefercliruntimeFile()
        {
            var projectToolsCommandResolver = SetupProjectToolsCommandResolver();

            var testInstance = _testAssetsManager.CopyTestAsset(TestProjectName)
                               .WithSource();

            NuGetConfigWriter.Write(testInstance.Path, TestContext.Current.TestPackages);

            testInstance.Restore(Log);

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

            var result = projectToolsCommandResolver.Resolve(commandResolverArguments);

            result.Should().NotBeNull();

            result.Args.Should().NotContain("--fx-version");
        }
Пример #37
0
        public void It_prefers_EXE_over_CMD_when_two_command_candidates_exist_and_using_WindowsExePreferredCommandSpecFactory()
        {
            var environment = CommandResolverTestUtils.SetupEnvironmentProviderWhichFindsExtensions(".exe");
            var platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory();

            var appBaseCommandResolver = new AppBaseCommandResolver(environment, platformCommandSpecFactory);

            CommandResolverTestUtils.CreateNonRunnableTestCommand(AppContext.BaseDirectory, "appbasetestcommand1", ".exe");
            CommandResolverTestUtils.CreateNonRunnableTestCommand(AppContext.BaseDirectory, "appbasetestcommand1", ".cmd");

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName      = "appbasetestcommand1",
                CommandArguments = null
            };

            var result = appBaseCommandResolver.Resolve(commandResolverArguments);

            result.Should().NotBeNull();

            var commandFile = Path.GetFileName(result.Path);

            commandFile.Should().Be("appbasetestcommand1.exe");
        }
Пример #38
0
        public void It_prefers_EXE_over_CMD_when_two_command_candidates_exist_and_using_WindowsExePreferredCommandSpecFactory()
        {
            var environment = new EnvironmentProvider(new [] { ".exe", ".cmd" }, new[] { s_testDirectory });
            var platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory();

            var pathCommandResolver = new PathCommandResolver(environment, platformCommandSpecFactory);

            CommandResolverTestUtils.CreateNonRunnableTestCommand(s_testDirectory, "extensionPreferenceCommand", ".exe");
            CommandResolverTestUtils.CreateNonRunnableTestCommand(s_testDirectory, "extensionPreferenceCommand", ".cmd");

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName      = "extensionPreferenceCommand",
                CommandArguments = null
            };

            var result = pathCommandResolver.Resolve(commandResolverArguments);

            result.Should().NotBeNull();

            var commandFile = Path.GetFileName(result.Path);

            commandFile.Should().Be("extensionPreferenceCommand.exe");
        }
        public void It_returns_a_CommandSpec_with_DOTNET_as_FileName_and_CommandName_in_Args_when_CommandName_exists_in_ProjectTools()
        {
            var projectToolsCommandResolver = SetupProjectToolsCommandResolver();

            var testInstance = TestAssetsManager.CreateTestInstance(TestProjectName)
                               .WithLockFiles();

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

            var result = projectToolsCommandResolver.Resolve(commandResolverArguments);

            result.Should().NotBeNull();

            var commandFile = Path.GetFileNameWithoutExtension(result.Path);

            commandFile.Should().Be("dotnet");

            result.Args.Should().Contain(commandResolverArguments.CommandName);
        }
Пример #40
0
        public void ItReturnsACommandSpecWithArgsContainingCommandPathWhenInvokingAToolReferencedWithADifferentCasing()
        {
            var projectToolsCommandResolver = SetupProjectToolsCommandResolver();

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

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

            var result = projectToolsCommandResolver.Resolve(commandResolverArguments);

            result.Should().NotBeNull();

            var commandPath = result.Args.Trim('"');

            commandPath.Should().Contain("dotnet-prefercliruntime.dll");
        }
        public void It_returns_a_CommandSpec_with_Args_containing_CommandPath_when_returning_a_CommandSpec_and_CommandArguments_are_null()
        {
            var projectToolsCommandResolver = SetupProjectToolsCommandResolver();

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName = "dotnet-portable",
                CommandArguments = null,
                ProjectDirectory = s_liveProjectDirectory
            };

            var result = projectToolsCommandResolver.Resolve(commandResolverArguments);

            result.Should().NotBeNull();

            var commandPath = result.Args.Trim('"');
            commandPath.Should().Contain("dotnet-portable.dll");
        }
        public void It_writes_a_deps_json_file_next_to_the_lockfile()
        {
            var projectToolsCommandResolver = SetupProjectToolsCommandResolver();

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName = "dotnet-portable",
                CommandArguments = null,
                ProjectDirectory = s_liveProjectDirectory
            };

            var context = ProjectContext.Create(Path.Combine(s_liveProjectDirectory, "project.json"), s_toolPackageFramework);

            var nugetPackagesRoot = context.PackagesDirectory;
            var toolPathCalculator = new ToolPathCalculator(nugetPackagesRoot);

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

            var directory = Path.GetDirectoryName(lockFilePath);

            var depsJsonFile = Directory
                .EnumerateFiles(directory)
                .FirstOrDefault(p => Path.GetFileName(p).EndsWith(FileNameSuffixes.DepsJson));

            if (depsJsonFile != null)
            {
                File.Delete(depsJsonFile);
            }

            var result = projectToolsCommandResolver.Resolve(commandResolverArguments);
            result.Should().NotBeNull();


            depsJsonFile = Directory
                .EnumerateFiles(directory)
                .FirstOrDefault(p => Path.GetFileName(p).EndsWith(FileNameSuffixes.DepsJson));

            depsJsonFile.Should().NotBeNull();
        }
        public void It_returns_a_CommandSpec_with_CommandName_as_FileName_when_CommandName_exists_in_ProjectDirectory()
        {
            var environment = CommandResolverTestUtils.SetupEnvironmentProviderWhichFindsExtensions(".exe");
            var projectPathCommandResolver = SetupPlatformProjectPathCommandResolver(environment, forceGeneric: true);

            CommandResolverTestUtils.CreateNonRunnableTestCommand(s_testProjectDirectory, "projectpathtestcommand1", ".exe");

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName = "projectpathtestcommand1",
                CommandArguments = null,
                ProjectDirectory = s_testProjectDirectory
            };

            var result = projectPathCommandResolver.Resolve(commandResolverArguments);

            result.Should().NotBeNull();

            var commandFile = Path.GetFileNameWithoutExtension(result.Path);

            commandFile.Should().Be("projectpathtestcommand1");
        }
        public void It_sets_depsfile_in_build_base_path_in_commandspec()
        {
            var projectDependenciesCommandResolver = SetupProjectDependenciesCommandResolver();
            var buildBasePath = Path.Combine(AppContext.BaseDirectory, "basedir");

            var commandResolverArguments = new CommandResolverArguments
            {
                CommandName = "dotnet-hello",
                CommandArguments = null,
                ProjectDirectory = s_liveProjectDirectory,
                Configuration = "Debug",
                Framework = FrameworkConstants.CommonFrameworks.NetCoreApp10,
                BuildBasePath = buildBasePath
            };

            var buildCommand = new BuildCommand(
                Path.Combine(s_liveProjectDirectory, "project.json"),
                buildBasePath: buildBasePath,
                framework: FrameworkConstants.CommonFrameworks.NetCoreApp10.ToString())
                .Execute().Should().Pass();

            var projectContext = ProjectContext.Create(
                s_liveProjectDirectory,
                FrameworkConstants.CommonFrameworks.NetCoreApp10,
                RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers());

            var depsFilePath =
                projectContext.GetOutputPaths("Debug", buildBasePath).RuntimeFiles.DepsJson;

            var result = projectDependenciesCommandResolver.Resolve(commandResolverArguments);

            result.Should().NotBeNull();
            result.Args.Should().Contain($"--depsfile {depsFilePath}");
        }
        public void It_returns_a_CommandSpec_with_CommandName_in_Args_when_returning_a_CommandSpec_and_CommandArguments_are_null()
        {
            var projectDependenciesCommandResolver = SetupProjectDependenciesCommandResolver();

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName = "dotnet-hello",
                CommandArguments = null,
                ProjectDirectory = s_liveProjectDirectory,
                Configuration = "Debug",
                Framework = FrameworkConstants.CommonFrameworks.NetCoreApp10
            };

            var result = projectDependenciesCommandResolver.Resolve(commandResolverArguments);

            result.Should().NotBeNull();

            result.Args.Should().Contain("dotnet-hello");
        }
        public void It_escapes_CommandArguments_when_returning_a_CommandSpec()
        {
            var projectToolsCommandResolver = SetupProjectToolsCommandResolver();

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

            var result = projectToolsCommandResolver.Resolve(commandResolverArguments);

            result.Should().NotBeNull();
            result.Args.Should().Contain("\"arg with space\"");
        }
        public void It_wraps_command_with_CMD_EXE_when_command_has_CMD_Extension_and_using_WindowsExePreferredCommandSpecFactory()
        {
            var environment = new EnvironmentProvider(new[] { ".cmd" });
            var platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory();

            var pathCommandResolver = new PathCommandResolver(environment, platformCommandSpecFactory);

            var testCommandPath =
                CommandResolverTestUtils.CreateNonRunnableTestCommand(s_testProjectDirectory, "cmdWrapCommand", ".cmd");

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName = "cmdWrapCommand",
                CommandArguments = null
            };

            var result = pathCommandResolver.Resolve(commandResolverArguments);

            result.Should().NotBeNull();

            var commandFile = Path.GetFileName(result.Path);
            commandFile.Should().Be("cmd.exe");

            result.Args.Should().Contain(testCommandPath);
        }
        public void It_prefers_EXE_over_CMD_when_two_command_candidates_exist_and_using_WindowsExePreferredCommandSpecFactory()
        {
            var environment = CommandResolverTestUtils.SetupEnvironmentProviderWhichFindsExtensions(".exe");
            var platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory();

            var projectPathCommandResolver = new ProjectPathCommandResolver(environment, platformCommandSpecFactory);

            CommandResolverTestUtils.CreateNonRunnableTestCommand(s_testProjectDirectory, "projectpathtestcommand1", ".exe");
            CommandResolverTestUtils.CreateNonRunnableTestCommand(s_testProjectDirectory, "projectpathtestcommand1", ".cmd");

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName = "projectpathtestcommand1",
                CommandArguments = null,
                ProjectDirectory = s_testProjectDirectory
            };

            var result = projectPathCommandResolver.Resolve(commandResolverArguments);

            result.Should().NotBeNull();

            var commandFile = Path.GetFileName(result.Path);
            commandFile.Should().Be("projectpathtestcommand1.exe");
        }
        public void It_returns_a_CommandSpec_with_Args_as_stringEmpty_when_returning_a_CommandSpec_and_CommandArguments_are_null()
        {
            var environment = CommandResolverTestUtils.SetupEnvironmentProviderWhichFindsExtensions(".exe");
            var projectPathCommandResolver = SetupPlatformProjectPathCommandResolver(environment, forceGeneric: true);

            CommandResolverTestUtils.CreateNonRunnableTestCommand(s_testProjectDirectory, "projectpathtestcommand1", ".exe");

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName = "projectpathtestcommand1",
                CommandArguments = null,
                ProjectDirectory = s_testProjectDirectory
            };

            var result = projectPathCommandResolver.Resolve(commandResolverArguments);

            result.Should().NotBeNull();
            result.Args.Should().Be(string.Empty);
        }
        public void It_resolves_commands_with_extensions_defined_in_InferredExtensions()
        {
            var extensions = new string[] { ".sh", ".cmd", ".foo", ".exe" };
            var projectPathCommandResolver = SetupPlatformProjectPathCommandResolver(forceGeneric: true);

            foreach (var extension in extensions)
            {
                var extensionTestDir = Path.Combine(s_testProjectDirectory, "testext" + extension);

                CommandResolverTestUtils.CreateNonRunnableTestCommand(extensionTestDir, "projectpathexttest", extension);

                var commandResolverArguments = new CommandResolverArguments()
                {
                    CommandName = "projectpathexttest",
                    CommandArguments = null,
                    ProjectDirectory = extensionTestDir,
                    InferredExtensions = extensions
                };

                var result = projectPathCommandResolver.Resolve(commandResolverArguments);

                result.Should().NotBeNull();

                var commandFileName = Path.GetFileName(result.Path);
                commandFileName.Should().Be("projectpathexttest" + extension);
            }
        }
        public void It_escapes_CommandArguments_when_returning_a_CommandSpec()
        {
            var environment = CommandResolverTestUtils.SetupEnvironmentProviderWhichFindsExtensions(".exe");
            var projectPathCommandResolver = SetupPlatformProjectPathCommandResolver(environment, forceGeneric: true);

            CommandResolverTestUtils.CreateNonRunnableTestCommand(s_testProjectDirectory, "projectpathtestcommand1", ".exe");

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName = "projectpathtestcommand1",
                CommandArguments = new[] { "arg with space" },
                ProjectDirectory = s_testProjectDirectory
            };

            var result = projectPathCommandResolver.Resolve(commandResolverArguments);

            result.Should().NotBeNull();
            result.Args.Should().Be("\"arg with space\"");
        }
Пример #52
0
 internal override string ResolveCommandPath(CommandResolverArguments commandResolverArguments)
 {
     return(_environment.GetCommandPath(commandResolverArguments.CommandName));
 }
Пример #53
0
 public CommandSpec Resolve(CommandResolverArguments arguments)
 {
     return(null);
 }
        public void It_returns_null_when_CommandName_does_not_exist_in_ProjectDependencies()
        {
            var projectDependenciesCommandResolver = SetupProjectDependenciesCommandResolver();

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName = "nonexistent-command",
                CommandArguments = null,
                ProjectDirectory = s_liveProjectDirectory,
                Configuration = "Debug",
                Framework = FrameworkConstants.CommonFrameworks.NetCoreApp10
            };

            var result = projectDependenciesCommandResolver.Resolve(commandResolverArguments);

            result.Should().BeNull();
        }
        public void It_returns_a_CommandSpec_with_Args_as_stringEmpty_when_returning_a_CommandSpec_and_CommandArguments_are_null()
        {
            var rootedCommandResolver = new RootedCommandResolver();

            var commandResolverArguments = new CommandResolverArguments()
            {
                CommandName = "/some/rooted/path",
                CommandArguments = null
            };

            var result = rootedCommandResolver.Resolve(commandResolverArguments);

            result.Should().NotBeNull();
            result.Path.Should().Be(commandResolverArguments.CommandName);

            result.Args.Should().Be(string.Empty);
        }