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()); }
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(); }
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()); }
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()); }
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(); }
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()); }
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()); }
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; }
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()); }
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)); }
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); }
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()); }
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()); }
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()); }
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(); }
public void ShouldDeleteBinFolder() { 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 assemblyName = new Mock<IAssemblyName>(); var root = new ScriptServiceRoot(fs.Object, resolver.Object, executor.Object, engine.Object, filePreProcessor.Object, scriptpackResolver.Object, packageInstaller.Object, logger.Object, assemblyName.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:\\"); var factory = new CommandFactory(root); var result = factory.CreateCommand(args, new string[0]); result.Execute(); fs.Verify(i => i.DirectoryExists(It.Is<string>(x => x.Contains(Constants.BinFolder))), Times.Once()); fs.Verify(i => i.DeleteDirectory(It.Is<string>(x => x.Contains(Constants.BinFolder))), Times.Once()); }
private static int Main(string[] args) { SetProfile(); var arguments = ParseArguments(args); 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(); }
private static int Main(string[] args) { ProfileOptimization.SetProfileRoot(typeof(Program).Assembly.Location); ProfileOptimization.StartProfile(typeof(Program).Assembly.GetName().Name + ".profile"); var console = new ScriptConsole(); var parser = new ArgumentHandler(new ArgumentParser(console), new ConfigFileParser(console), new FileSystem()); var arguments = parser.Parse(args); var commandArgs = arguments.CommandArguments; var scriptArgs = arguments.ScriptArguments; var configurator = new LoggerConfigurator(commandArgs.LogLevel); configurator.Configure(console); var logger = configurator.GetLogger(); var scriptServicesBuilder = new ScriptServicesBuilder(console, logger) .Cache(commandArgs.Cache) .Debug(commandArgs.Debug) .LogLevel(commandArgs.LogLevel) .ScriptName(commandArgs.ScriptName) .Repl(commandArgs.Repl); var modules = GetModuleList(commandArgs.Modules); var extension = Path.GetExtension(commandArgs.ScriptName); if (string.IsNullOrWhiteSpace(extension) && !commandArgs.Repl) { // No extension was given, i.e we might have something like // "scriptcs foo" to deal with. We activate the default extension, // to make sure it's given to the LoadModules below. extension = ".csx"; if (!string.IsNullOrWhiteSpace(commandArgs.ScriptName)) { // If the was in fact a script specified, we'll extend it // with the default extension, assuming the user giving // "scriptcs foo" actually meant "scriptcs foo.csx". We // perform no validation here thought; let it be done by // the activated command. If the file don't exist, it's // up to the command to detect and report. commandArgs.ScriptName += extension; } } 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; }
public void ShouldCleanWhenCleanFlagIsPassed() { var args = new ScriptCsArgs { Clean = true, ScriptName = null }; var factory = new CommandFactory(CreateRoot()); var result = factory.CreateCommand(args); result.ShouldNotBeNull(); result.ShouldImplement<ICleanCommand>(); }
public void VersionCommandShouldOutputVersion([Frozen] Mock<IConsole> console, CommandFactory factory) { // Arrange var args = new ScriptCsArgs { Version = true }; var assembly = typeof(ScriptCsArgs).Assembly; var currentVersion = FileVersionInfo.GetVersionInfo(assembly.Location).ProductVersion; // Act factory.CreateCommand(args, new string[0]).Execute(); // Assert console.Verify(x => x.WriteLine(It.Is<string>(y => y.Contains(currentVersion.ToString())))); }
public void ShouldExecuteWhenBothNameAndInstallArePassed() { var args = new ScriptCsArgs { AllowPreRelease = false, Install = "", ScriptName = "test.csx" }; var factory = new CommandFactory(CreateRoot()); var result = factory.CreateCommand(args, new string[0]); result.ShouldImplement<IScriptCommand>(); }
public void ShouldExecuteWhenScriptNameIsPassed() { var args = new ScriptCsArgs { AllowPreReleaseFlag = false, Install = null, ScriptName = "test.csx" }; var factory = new CommandFactory(CreateRoot()); var result = factory.CreateCommand(args); result.ShouldImplement<IScriptCommand>(); }
public void ShouldDeletePackagesFolder([Frozen] Mock<IFileSystem> fileSystem, CommandFactory factory) { // Arrange var args = new ScriptCsArgs { Clean = true }; fileSystem.Setup(i => i.DirectoryExists(It.Is<string>(x => x.Contains(Constants.PackagesFolder)))).Returns(true); fileSystem.Setup(i => i.GetWorkingDirectory(It.IsAny<string>())).Returns("c:\\"); // Act factory.CreateCommand(args, new string[0]).Execute(); // Assert fileSystem.Verify(i => i.DirectoryExists(It.Is<string>(x => x.Contains(Constants.PackagesFolder))), Times.Once()); fileSystem.Verify(i => i.DeleteDirectory(It.Is<string>(x => x.Contains(Constants.PackagesFolder))), Times.Once()); }
public void WhenNotPassedAScript_ShouldNotCallTheEngineAutomatically( [Frozen] Mock<IScriptEngine> scriptEngine, [Frozen] Mock<IFileSystem> fileSystem, [Frozen] Mock<IConsole> console, CommandFactory factory) { // Arrange var args = new ScriptCsArgs { Repl = true }; console.Setup(x => x.ReadLine()).Returns(() => string.Empty); fileSystem.SetupGet(x => x.CurrentDirectory).Returns("C:\\"); // Act factory.CreateCommand(args, new string[0]).Execute(); // Assert scriptEngine.Verify( x => x.Execute(It.IsAny<string>(), It.IsAny<string[]>(), It.IsAny<IEnumerable<string>>(), It.IsAny<IEnumerable<string>>(), It.IsAny<ScriptPackSession>()), Times.Never()); }
public void ShouldExecuteWhenScriptNameIsPassed() { // Arrange var args = new Config { AllowPreRelease = false, PackageName = null, ScriptName = "test.csx" }; // Act var factory = new CommandFactory(CreateBuilder()); var result = factory.CreateCommand(args, new string[0]); // Assert result.ShouldImplement<IScriptCommand>(); }
public void ShouldExecuteWhenBothNameAndInstallArePassed() { // Arrange var args = new ScriptCsArgs { AllowPreRelease = false, Install = string.Empty, ScriptName = "test.csx" }; // Act var factory = new CommandFactory(CreateBuilder()); var result = factory.CreateCommand(args, new string[0]); // Assert result.ShouldImplement<IScriptCommand>(); }
private static int Main(string[] args) { var commandArgs = ParseArguments(args) ?? new ScriptCsArgs { Repl = true }; var compositionRoot = new CompositionRoot(commandArgs); compositionRoot.Initialize(); var logger = compositionRoot.GetLogger(); logger.Debug("Creating ScriptServiceRoot"); var scriptServiceRoot = compositionRoot.GetServiceRoot(); var commandFactory = new CommandFactory(scriptServiceRoot); var command = commandFactory.CreateCommand(commandArgs); var result = command.Execute(); return result == CommandResult.Success ? 0 : -1; }
public void ShouldInstallWhenInstallFlagIsOn() { var args = new ScriptCsArgs { AllowPreReleaseFlag = false, Install = "", ScriptName = null }; var factory = new CommandFactory(CreateRoot()); var result = factory.CreateCommand(args); var compositeCommand = result as ICompositeCommand; compositeCommand.ShouldNotBeNull(); (compositeCommand.Commands[0] is IInstallCommand).ShouldBeTrue(); (compositeCommand.Commands[1] is IRestoreCommand).ShouldBeTrue(); }
public void ScriptExecCommandShouldInvokeWithScriptPassedFromArgs( [Frozen] Mock<IFileSystem> fileSystem, [Frozen] Mock<IScriptExecutor> executor, CommandFactory factory) { // Arrange var args = new ScriptCsArgs { AllowPreRelease = false, Install = "", ScriptName = "test.csx" }; fileSystem.SetupGet(x => x.CurrentDirectory).Returns(CurrentDirectory); // Act factory.CreateCommand(args, new string[0]).Execute(); // Assert executor.Verify(i => i.Initialize(It.IsAny<IEnumerable<string>>(), 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()); }
public void WhenPassedAScript_ShouldPressedReplWithScript( [Frozen] Mock<IScriptEngine> scriptEngine, [Frozen] Mock<IFileSystem> fileSystem,[Frozen] Mock<IConsole> console, CommandFactory factory) { // Arrange var args = new ScriptCsArgs { Repl = true, ScriptName = "test.csx"}; console.Setup(x => x.ReadLine()).Returns(() => string.Empty); fileSystem.SetupGet(x => x.CurrentDirectory).Returns("C:\\"); scriptEngine.Setup( x => x.Execute("#load test.csx", It.IsAny<string[]>(), It.IsAny<IEnumerable<string>>(), It.IsAny<IEnumerable<string>>(), It.IsAny<ScriptPackSession>())); // Act factory.CreateCommand(args, new string[0]).Execute(); // Assert scriptEngine.Verify(); }