当前位置: 首页>>代码示例>>C#>>正文


C# Command.CommandFactory类代码示例

本文整理汇总了C#中ScriptCs.Command.CommandFactory的典型用法代码示例。如果您正苦于以下问题:C# CommandFactory类的具体用法?C# CommandFactory怎么用?C# CommandFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CommandFactory类属于ScriptCs.Command命名空间,在下文中一共展示了CommandFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ShouldCreateBinFolderIfItDoesNotExist

            public void ShouldCreateBinFolderIfItDoesNotExist()
            {
                var args = new ScriptCsArgs { Restore = true, ScriptName = "" };

                var fs = new Mock<IFileSystem>();
                var resolver = new Mock<IPackageAssemblyResolver>();
                var executor = new Mock<IScriptExecutor>();
                var scriptpackResolver = new Mock<IScriptPackResolver>();
                var packageInstaller = new Mock<IPackageInstaller>();
                var root = new ScriptServiceRoot(fs.Object, resolver.Object, executor.Object, scriptpackResolver.Object, packageInstaller.Object);

                const string CurrentDirectory = @"C:\";
                const string BinFolder = @"C:\bin";

                fs.Setup(x => x.GetWorkingDirectory(It.IsAny<string>())).Returns(CurrentDirectory);

                var binFolderCreated = false;

                fs.Setup(x => x.DirectoryExists(BinFolder)).Returns(() => binFolderCreated).Verifiable();
                fs.Setup(x => x.CreateDirectory(BinFolder)).Callback(() => binFolderCreated = true).Verifiable();

                var factory = new CommandFactory(root);
                var result = factory.CreateCommand(args);

                result.Execute();

                fs.Verify(x => x.DirectoryExists(BinFolder), Times.AtLeastOnce());
                fs.Verify(x => x.CreateDirectory(BinFolder), Times.Once());
            }
开发者ID:bangoker,项目名称:scriptcs,代码行数:29,代码来源:RestoreCommandTests.cs

示例2: Run

 public static int Run(Config config, string[] scriptArgs)
 {
     var scriptServicesBuilder = ScriptServicesBuilderFactory.Create(config, scriptArgs);
     var factory = new CommandFactory(scriptServicesBuilder);
     var command = factory.CreateCommand(config, scriptArgs);
     return (int)command.Execute();
 }
开发者ID:JamesLinus,项目名称:scriptcs,代码行数:7,代码来源:Application.cs

示例3: InstallCommandShouldInstallSinglePackageIfNamePassed

            public void InstallCommandShouldInstallSinglePackageIfNamePassed()
            {
                var args = new ScriptCsArgs
                    {
                        AllowPreReleaseFlag = false,
                        Install = "mypackage",
                        ScriptName = null
                    };

                var fs = new Mock<IFileSystem>();
                fs.Setup(x => x.GetWorkingDirectory(It.IsAny<string>())).Returns(@"C:\");

                var resolver = new Mock<IPackageAssemblyResolver>();
                var executor = new Mock<IScriptExecutor>();
                var scriptpackResolver = new Mock<IScriptPackResolver>();
                var packageInstaller = new Mock<IPackageInstaller>();
                var root = new ScriptServiceRoot(fs.Object, resolver.Object, executor.Object, scriptpackResolver.Object, packageInstaller.Object);

                var factory = new CommandFactory(root);
                var result = factory.CreateCommand(args);

                result.Execute();

                packageInstaller.Verify(i => i.InstallPackages(It.Is<IEnumerable<IPackageReference>>(x => x.Count() == 1 && x.First().PackageId == "mypackage"), It.IsAny<bool>(), It.IsAny<Action<string>>()), Times.Once());
            }
开发者ID:eendrulat,项目名称:scriptcs,代码行数:25,代码来源:InstallCommandTests.cs

示例4: InstallCommandShouldInstallFromPackagesConfigIfNoNamePassed

            public void InstallCommandShouldInstallFromPackagesConfigIfNoNamePassed()
            {
                var args = new ScriptCsArgs
                {
                    AllowPreReleaseFlag = false,
                    Install = "",
                    ScriptName = null
                };

                var fs = new Mock<IFileSystem>();
                fs.Setup(x => x.GetWorkingDirectory(It.IsAny<string>())).Returns(@"C:\");

                var resolver = new Mock<IPackageAssemblyResolver>();
                var executor = new Mock<IScriptExecutor>();
                var scriptpackResolver = new Mock<IScriptPackResolver>();
                var packageInstaller = new Mock<IPackageInstaller>();
                var root = new ScriptServiceRoot(fs.Object, resolver.Object, executor.Object, scriptpackResolver.Object, packageInstaller.Object);

                resolver.Setup(i => i.GetPackages(It.IsAny<string>())).Returns(new List<IPackageReference>
                    {
                        new PackageReference("a", new FrameworkName(".NETFramework,Version=v4.0"), new Version()),
                        new PackageReference("b", new FrameworkName(".NETFramework,Version=v4.0"), new Version())
                    });

                var factory = new CommandFactory(root);
                var result = factory.CreateCommand(args);

                result.Execute();

                packageInstaller.Verify(i => i.InstallPackages(It.Is<IEnumerable<IPackageReference>>(x => x.Count() == 2), It.IsAny<bool>(), It.IsAny<Action<string>>()), Times.Once());
            }
开发者ID:eendrulat,项目名称:scriptcs,代码行数:31,代码来源:InstallCommandTests.cs

示例5: WhenPassedAScript_ShouldPressedReplWithScript

            public void WhenPassedAScript_ShouldPressedReplWithScript(
                [Frozen] Mock<IScriptEngine> scriptEngine, 
                [Frozen] Mock<IFileSystem> fileSystem, 
                [Frozen] Mock<IConsole> console,
                [Frozen] Mock<IScriptServicesBuilder> servicesBuilder,
                [Frozen] Mock<IInitializationServices> initializationServices,
                ScriptServices services)
            {
                // Arrange
                var args = new ScriptCsArgs { Repl = true, ScriptName = "test.csx" };

                console.Setup(x => x.ReadLine()).Returns(() =>
                {
                    console.Setup(x => x.ReadLine()).Throws(new Exception());
                    return string.Empty;
                });
                fileSystem.SetupGet(x => x.CurrentDirectory).Returns("C:\\");
                servicesBuilder.Setup(b => b.Build()).Returns(services);
                //initializationServices.Setup(i => i.GetFileSystem()).Returns(fileSystem.Object);
                scriptEngine.Setup(
                    x => x.Execute("#load test.csx", It.IsAny<string[]>(), It.IsAny<AssemblyReferences>(), It.IsAny<IEnumerable<string>>(), It.IsAny<ScriptPackSession>()));

                servicesBuilder.SetupGet(b => b.InitializationServices).Returns(initializationServices.Object);
                initializationServices.Setup(i => i.GetFileSystem()).Returns(fileSystem.Object);

                var factory = new CommandFactory(servicesBuilder.Object);

                // Act
                factory.CreateCommand(args, new string[0]).Execute();

                // Assert
                scriptEngine.Verify();
            }
开发者ID:selony,项目名称:scriptcs,代码行数:33,代码来源:ExecuteReplCommandTests.cs

示例6: ShouldCreateMissingBinFolder

            public void ShouldCreateMissingBinFolder()
            {
                const string WorkingDirectory = @"C:\";

                var binFolder = Path.Combine(WorkingDirectory, "bin");

                var args = new ScriptCsArgs { ScriptName = "test.csx" };

                var fs = new Mock<IFileSystem>();
                fs.Setup(x => x.GetWorkingDirectory(It.IsAny<string>())).Returns(WorkingDirectory);
                fs.Setup(x => x.DirectoryExists(binFolder)).Returns(false);

                var resolver = new Mock<IPackageAssemblyResolver>();
                var executor = new Mock<IScriptExecutor>();
                var engine = new Mock<IScriptEngine>();
                var scriptpackResolver = new Mock<IScriptPackResolver>();
                var packageInstaller = new Mock<IPackageInstaller>();
                var logger = new Mock<ILog>();
                var filePreProcessor = new Mock<IFilePreProcessor>();
                var root = new ScriptServiceRoot(fs.Object, resolver.Object, executor.Object, engine.Object, filePreProcessor.Object, scriptpackResolver.Object, packageInstaller.Object, logger.Object);

                var factory = new CommandFactory(root);
                var result = factory.CreateCommand(args);

                result.Execute();

                fs.Verify(x => x.CreateDirectory(binFolder), Times.Once());
            }
开发者ID:ChowZenki,项目名称:scriptcs,代码行数:28,代码来源:ExecuteScriptCommandTests.cs

示例7: VersionCommandShouldOutputVersion

            public void VersionCommandShouldOutputVersion()
            {
                var args = new ScriptCsArgs
                    {
                        Version = true
                    };

                var fs = new Mock<IFileSystem>();
                var resolver = new Mock<IPackageAssemblyResolver>();
                var executor = new Mock<IScriptExecutor>();
                var engine = new Mock<IScriptEngine>();
                var scriptpackResolver = new Mock<IScriptPackResolver>();
                var packageInstaller = new Mock<IPackageInstaller>();
                var logger = new Mock<ILog>();
                var filePreProcessor = new Mock<IFilePreProcessor>();
                var root = new ScriptServiceRoot(fs.Object, resolver.Object, executor.Object, engine.Object, filePreProcessor.Object, scriptpackResolver.Object, packageInstaller.Object, logger.Object);

                var factory = new CommandFactory(root);
                var result = factory.CreateCommand(args);

                // clear the fake console output
                _outputText.Clear();

                result.Execute();

                Assert.Contains("scriptcs version " + _currentVersion.ToString(), _outputText.ToString());
            }
开发者ID:ChowZenki,项目名称:scriptcs,代码行数:27,代码来源:VersionCommandTests.cs

示例8: Main

        private static int Main(string[] args)
        {
            string[] scriptArgs;
            ScriptCsArgs.SplitScriptArgs(ref args, out scriptArgs);

            var commandArgs = ParseArguments(args);
            var configurator = new LoggerConfigurator(commandArgs.LogLevel);
            var console = new ScriptConsole();
            configurator.Configure(console);
            var logger = configurator.GetLogger();

            var scriptServicesBuilder = new ScriptServicesBuilder(console, logger)   .
                Debug(commandArgs.Debug).
                LogLevel(commandArgs.LogLevel).
                ScriptName(commandArgs.ScriptName).
                Repl(commandArgs.Repl);

            var modules = GetModuleList(commandArgs.Modules);
            var extension = Path.GetExtension(commandArgs.ScriptName);
            if (extension != null)
                extension = extension.Substring(1);

            scriptServicesBuilder.LoadModules(extension, modules);
            var scriptServiceRoot = scriptServicesBuilder.Build();

            var commandFactory = new CommandFactory(scriptServiceRoot);
            var command = commandFactory.CreateCommand(commandArgs, scriptArgs);

            var result = command.Execute();

            return result == CommandResult.Success ? 0 : -1;
        }
开发者ID:johnduhart,项目名称:scriptcs,代码行数:32,代码来源:Program.cs

示例9: InstallCommandShouldInstallFromPackagesConfigIfNoNamePassed

            public void InstallCommandShouldInstallFromPackagesConfigIfNoNamePassed(
                [Frozen] Mock<IPackageInstaller> packageInstaller,
                [Frozen] Mock<IFileSystem> fileSystem,
                [Frozen] Mock<IPackageAssemblyResolver> resolver,
                [Frozen] Mock<IInitializationServices> initializationServices,
                [Frozen] Mock<IScriptServicesBuilder> servicesBuilder,
                ScriptServices services)
            {
                // Arrange
                var args = new Config { AllowPreRelease = false, PackageName = string.Empty, };

                initializationServices.Setup(i => i.GetFileSystem()).Returns(fileSystem.Object);
                initializationServices.Setup(i => i.GetPackageInstaller()).Returns(packageInstaller.Object);
                initializationServices.Setup(i => i.GetPackageAssemblyResolver()).Returns(resolver.Object);

                servicesBuilder.Setup(b => b.Build()).Returns(services);
                servicesBuilder.SetupGet(b => b.InitializationServices).Returns(initializationServices.Object);

                resolver.Setup(i => i.GetPackages(It.IsAny<string>())).Returns(new List<IPackageReference>
                    {
                        new PackageReference("a", new FrameworkName(".NETFramework,Version=v4.0"), new Version()),
                        new PackageReference("b", new FrameworkName(".NETFramework,Version=v4.0"), new Version())
                    });

                var factory = new CommandFactory(servicesBuilder.Object);
                var sut = factory.CreateCommand(args, new string[0]);

                // act
                sut.Execute();

                // Assert
                packageInstaller.Verify(i => i.InstallPackages(It.Is<IEnumerable<IPackageReference>>(x => x.Count() == 2), It.IsAny<bool>()), Times.Once());
            }
开发者ID:JamesLinus,项目名称:scriptcs,代码行数:33,代码来源:InstallCommandTests.cs

示例10: ShouldDeleteAllFilesResolvedFromPackages

            public void ShouldDeleteAllFilesResolvedFromPackages()
            {
                var args = new ScriptCsArgs { Clean = true };

                var fs = new Mock<IFileSystem>();
                var resolver = new Mock<IPackageAssemblyResolver>();
                var executor = new Mock<IScriptExecutor>();
                var engine = new Mock<IScriptEngine>();
                var scriptpackResolver = new Mock<IScriptPackResolver>();
                var packageInstaller = new Mock<IPackageInstaller>();
                var logger = new Mock<ILog>();
                var filePreProcessor = new Mock<IFilePreProcessor>();
                var root = new ScriptServiceRoot(fs.Object, resolver.Object, executor.Object, engine.Object, filePreProcessor.Object, scriptpackResolver.Object, packageInstaller.Object, logger.Object);

                fs.Setup(i => i.DirectoryExists(It.Is<string>(x => x.Contains(Constants.BinFolder)))).Returns(true);
                fs.Setup(i => i.GetWorkingDirectory(It.IsAny<string>())).Returns("c:\\");
                fs.Setup(i => i.FileExists(It.IsAny<string>())).Returns(true);
                resolver.Setup(i => i.GetAssemblyNames(It.IsAny<string>(), It.IsAny<Action<string>>())).Returns(new[] { "c:\\file.dll", "c:\\file2.dll" });

                var factory = new CommandFactory(root);
                var result = factory.CreateCommand(args);

                result.Execute();

                fs.Verify(i => i.FileDelete(It.IsAny<string>()), Times.Exactly(2));
            }
开发者ID:ChowZenki,项目名称:scriptcs,代码行数:26,代码来源:CleanCommandTests.cs

示例11: ShouldPromptForInput

            public void ShouldPromptForInput(
                [Frozen] Mock<IFileSystem> fileSystem,
                [Frozen] Mock<IConsole> console,
                [Frozen] Mock<IScriptServicesBuilder> servicesBuilder,
                [Frozen] Mock<IInitializationServices> initializationServices,
                ScriptServices services)
            {
                // Arrange
                var readLines = 0;
                var builder = new StringBuilder();
                var args = new ScriptCsArgs { Repl = true };

                fileSystem.SetupGet(x => x.CurrentDirectory).Returns("C:\\");
                servicesBuilder.Setup(b => b.Build()).Returns(services);
                servicesBuilder.SetupGet(b => b.ConsoleInstance).Returns(console.Object);
                servicesBuilder.SetupGet(b => b.InitializationServices).Returns(initializationServices.Object);
                initializationServices.Setup(i => i.GetFileSystem()).Returns(fileSystem.Object);

                console.Setup(x => x.ReadLine()).Callback(() => readLines++).Throws(new Exception());
                console.Setup(x => x.Write(It.IsAny<string>())).Callback<string>(value => builder.Append(value));

                var factory = new CommandFactory(servicesBuilder.Object);

                // Act
                factory.CreateCommand(args, new string[0]).Execute();

                // Assert
                builder.ToString().EndsWith("> ").ShouldBeTrue();
                readLines.ShouldEqual(1);
            }
开发者ID:selony,项目名称:scriptcs,代码行数:30,代码来源:ExecuteReplCommandTests.cs

示例12: ScriptExecCommandShouldInvokeWithScriptPassedFromArgs

            public void ScriptExecCommandShouldInvokeWithScriptPassedFromArgs()
            {
                var args = new ScriptCsArgs
                    {
                        AllowPreRelease = false,
                        Install = "",
                        ScriptName = "test.csx"
                    };

                var fs = new Mock<IFileSystem>();
                var resolver = new Mock<IPackageAssemblyResolver>();
                var executor = new Mock<IScriptExecutor>();
                var engine = new Mock<IScriptEngine>();
                var scriptpackResolver = new Mock<IScriptPackResolver>();
                var packageInstaller = new Mock<IPackageInstaller>();
                var logger = new Mock<ILog>();
                var filePreProcessor = new Mock<IFilePreProcessor>();
                var root = new ScriptServiceRoot(fs.Object, resolver.Object, executor.Object, engine.Object, filePreProcessor.Object, scriptpackResolver.Object, packageInstaller.Object, logger.Object);

                var factory = new CommandFactory(root);
                var result = factory.CreateCommand(args);

                result.Execute();

                executor.Verify(i => i.Execute(It.Is<string>(x => x == "test.csx"), It.IsAny<IEnumerable<string>>(), It.IsAny<IEnumerable<IScriptPack>>()), Times.Once());
            }
开发者ID:ChowZenki,项目名称:scriptcs,代码行数:26,代码来源:ExecuteScriptCommandTests.cs

示例13: ShouldCopyFilesInPathIfLastWriteTimeDiffersFromLastWriteTimeOfFileInBin

            public void ShouldCopyFilesInPathIfLastWriteTimeDiffersFromLastWriteTimeOfFileInBin()
            {
                var args = new ScriptCsArgs { Restore = true, ScriptName = "" };

                var fs = new Mock<IFileSystem>();
                var resolver = new Mock<IPackageAssemblyResolver>();
                var executor = new Mock<IScriptExecutor>();
                var scriptpackResolver = new Mock<IScriptPackResolver>();
                var packageInstaller = new Mock<IPackageInstaller>();
                var root = new ScriptServiceRoot(fs.Object, resolver.Object, executor.Object, scriptpackResolver.Object, packageInstaller.Object);

                const string CurrentDirectory = @"C:\";

                var sourceFilePath = Path.Combine(CurrentDirectory, "fileName.cs");
                var sourceWriteTime = new DateTime(2013, 3, 7);

                var destFilePath = Path.Combine(CurrentDirectory, "bin", "fileName.cs");
                var destWriteTime = new DateTime(2013, 2, 7);

                fs.Setup(x => x.GetWorkingDirectory(It.IsAny<string>())).Returns(CurrentDirectory);

                fs.Setup(x => x.GetLastWriteTime(sourceFilePath)).Returns(sourceWriteTime).Verifiable();
                fs.Setup(x => x.GetLastWriteTime(destFilePath)).Returns(destWriteTime).Verifiable();

                resolver.Setup(i => i.GetAssemblyNames(CurrentDirectory, It.IsAny<Action<string>>())).Returns(new[] { sourceFilePath });

                var factory = new CommandFactory(root);
                var result = factory.CreateCommand(args);

                result.Execute();

                fs.Verify(x => x.Copy(sourceFilePath, destFilePath, true), Times.Once());
                fs.Verify(x => x.GetLastWriteTime(sourceFilePath), Times.Once());
                fs.Verify(x => x.GetLastWriteTime(destFilePath), Times.Once());
            }
开发者ID:bangoker,项目名称:scriptcs,代码行数:35,代码来源:RestoreCommandTests.cs

示例14: NonManagedAssembliesAreExcluded

            public void NonManagedAssembliesAreExcluded(
                [Frozen] Mock<IFileSystem> fileSystem,
                [Frozen] Mock<IAssemblyUtility> assemblyUtility,
                [Frozen] Mock<IScriptExecutor> executor,
                CommandFactory factory)
            {
                // Arrange
                const string NonManaged = "non-managed.dll";

                var args = new ScriptCsArgs { AllowPreRelease = false, Install = "", ScriptName = "test.csx" };

                fileSystem.SetupGet(x => x.CurrentDirectory).Returns(CurrentDirectory);
                fileSystem.Setup(x => x.EnumerateFiles(It.IsAny<string>(), It.IsAny<string>(), SearchOption.AllDirectories))
                          .Returns(new[] { "managed.dll", NonManaged });

                assemblyUtility.Setup(x => x.IsManagedAssembly(It.Is<string>(y => y == NonManaged))).Returns(false);

                // Act
                factory.CreateCommand(args, new string[0]).Execute();

                // Assert
                executor.Verify(i => i.Initialize(It.Is<IEnumerable<string>>(x => !x.Contains(NonManaged)), It.IsAny<IEnumerable<IScriptPack>>()), Times.Once());
                executor.Verify(i => i.Execute(It.Is<string>(x => x == "test.csx"), It.IsAny<string[]>()), Times.Once());
                executor.Verify(i => i.Terminate(), Times.Once());
            }
开发者ID:jden,项目名称:scriptcs,代码行数:25,代码来源:ExecuteScriptCommandTests.cs

示例15: Main

        private static int Main(string[] args)
        {
            SetProfile();

            ArgumentParseResult arguments;
            var console = new ScriptConsole();
            try
            {
                var parser = new ArgumentHandler(new ArgumentParser(), new ConfigFileParser(console), new FileSystem());
                arguments = parser.Parse(args);
            }
            catch(Exception ex)
            {
                console.WriteLine(ex.Message);
                var options = new ArgUsageOptions { ShowPosition = false, ShowType = false };
                var usage = ArgUsage.GetUsage<ScriptCsArgs>(options: options);
                console.WriteLine(usage);
                return 1;
            }

            var scriptServicesBuilder = ScriptServicesBuilderFactory.Create(arguments.CommandArguments, arguments.ScriptArguments);
            var factory = new CommandFactory(scriptServicesBuilder);
            var command = factory.CreateCommand(arguments.CommandArguments, arguments.ScriptArguments);
            return (int)command.Execute();
        }
开发者ID:nagyistoce,项目名称:scriptcs,代码行数:25,代码来源:Program.cs


注:本文中的ScriptCs.Command.CommandFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。