Exemplo n.º 1
0
        private ConsoleDebugTargetsProvider GetDebugTargetsProvider(string outputType = "exe", Dictionary <string, string> properties = null)
        {
            _mockFS.WriteAllText(@"c:\test\Project\someapp.exe", "");
            _mockFS.CreateDirectory(@"c:\test\Project");
            _mockFS.CreateDirectory(@"c:\test\Project\bin\");
            _mockFS.WriteAllText(@"c:\program files\dotnet\dotnet.exe", "");

            _mockEnvironment.Setup(s => s.GetEnvironmentVariable("Path")).Returns(() => _Path);

            var project = UnconfiguredProjectFactory.Create(filePath: _ProjectFile);

            var outputTypeEnum = new PageEnumValue(new EnumValue()
            {
                Name = outputType
            });
            var data = new PropertyPageData()
            {
                Category     = ConfigurationGeneral.SchemaName,
                PropertyName = ConfigurationGeneral.OutputTypeProperty,
                Value        = outputTypeEnum
            };
            var projectProperties = ProjectPropertiesFactory.Create(project, data);

            if (properties == null)
            {
                properties = new Dictionary <string, string>()
                {
                    { "RunCommand", @"dotnet" },
                    { "RunArguments", "exec " + "\"" + @"c:\test\project\bin\project.dll" + "\"" },
                    { "RunWorkingDirectory", @"bin\" },
                    { "TargetFrameworkIdentifier", @".NetCoreApp" },
                    { "OutDir", @"c:\test\project\bin\" }
                };
            }
            var delegatePropertiesMock = IProjectPropertiesFactory
                                         .MockWithPropertiesAndValues(properties);

            var delegateProvider = IProjectPropertiesProviderFactory.Create(null, delegatePropertiesMock.Object);

            var configuredProjectServices = Mock.Of <IConfiguredProjectServices>(o =>
                                                                                 o.ProjectPropertiesProvider == delegateProvider);

            var configuredProject = Mock.Of <ConfiguredProject>(o =>
                                                                o.UnconfiguredProject == project &&
                                                                o.Services == configuredProjectServices);

            _mockTokenReplace.Setup(s => s.ReplaceTokensInProfileAsync(It.IsAny <ILaunchProfile>())).Returns <ILaunchProfile>(p => Task.FromResult(p));

            var activeDebugFramework = Mock.Of <IActiveDebugFrameworkServices>(o =>
                                                                               o.GetConfiguredProjectForActiveFrameworkAsync() == Task.FromResult(configuredProject));
            var debugProvider = new ConsoleDebugTargetsProvider(
                configuredProject,
                _mockTokenReplace.Object,
                _mockFS,
                _mockEnvironment.Object,
                activeDebugFramework,
                projectProperties);

            return(debugProvider);
        }
        public void GetExeAndArgumentsWithNullArgs()
        {
            string exeIn      = @"c:\foo\bar.exe";
            string cmdExePath = Path.Combine(Environment.SystemDirectory, "cmd.exe");

            ConsoleDebugTargetsProvider.GetExeAndArguments(true, exeIn, null, out string finalExePath, out string finalArguments);
            Assert.Equal(cmdExePath, finalExePath);
            Assert.Equal("/c \"\"c:\\foo\\bar.exe\"  & pause\"", finalArguments);
        }
        public void GetExeAndArgumentsWithEscapedArgs()
        {
            string exeIn             = @"c:\foo\bar.exe";
            string argsInWithEscapes = "/foo /bar ^ < > &";
            string cmdExePath        = Path.Combine(Environment.SystemDirectory, "cmd.exe");

            ConsoleDebugTargetsProvider.GetExeAndArguments(true, exeIn, argsInWithEscapes, out string finalExePath, out string finalArguments);
            Assert.Equal(cmdExePath, finalExePath);
            Assert.Equal("/c \"\"c:\\foo\\bar.exe\" /foo /bar ^^ ^< ^> ^& & pause\"", finalArguments);

            ConsoleDebugTargetsProvider.GetExeAndArguments(false, exeIn, argsInWithEscapes, out finalExePath, out finalArguments);
            Assert.Equal(exeIn, finalExePath);
            Assert.Equal(argsInWithEscapes, finalArguments);
        }
 public void ConsoleDebugTargetsProvider_EscapeString_WorksCorrectly(string input, string expected)
 {
     Assert.Equal(expected, ConsoleDebugTargetsProvider.EscapeString(input, new[] { '^', '<', '>', '&' }));
 }