public void ShouldComposeScripts([Frozen] Mock<IFileSystem> fileSystem, Mock<IScriptLibraryComposer> composer) { var cmd = new ExecuteScriptCommand( null, null, fileSystem.Object, new Mock<IScriptExecutor>().Object, new Mock<IScriptPackResolver>().Object, new TestLogProvider(), new Mock<IAssemblyResolver>().Object, new Mock<IFileSystemMigrator>().Object, composer.Object); cmd.Execute(); composer.Verify(c => c.Compose(It.IsAny<string>(),null)); }
public void Execute() { if (this.CommandArgs == null) { throw new InvalidOperationException("The command args are missing."); } var services = ScriptServicesBuilderFactory.Create(this.CommandArgs, this.ScriptArgs).Build(); var command = new ExecuteScriptCommand( this.CommandArgs.ScriptName, this.ScriptArgs, services.FileSystem, services.Executor, services.ScriptPackResolver, services.Logger, services.AssemblyResolver); this.Result = command.Execute(); }
public void Execute() { if (this.Config == null) { throw new InvalidOperationException("The config is missing."); } var services = ScriptServicesBuilderFactory.Create(this.Config, this.ScriptArgs).Build(); var command = new ExecuteScriptCommand( this.Config.ScriptName, this.ScriptArgs, services.FileSystem, services.Executor, services.ScriptPackResolver, services.LogProvider, services.AssemblyResolver, services.FileSystemMigrator, services.ScriptLibraryComposer); this.Result = command.Execute(); }
public void MigratesTheFileSystem( [Frozen] Mock<IFileSystem> fileSystem, [Frozen] Mock<IFileSystemMigrator> fileSystemMigrator) { // arrange var sut = new ExecuteScriptCommand( null, null, fileSystem.Object, new Mock<IScriptExecutor>().Object, new Mock<IScriptPackResolver>().Object, new TestLogProvider(), new Mock<IAssemblyResolver>().Object, fileSystemMigrator.Object, new Mock<IScriptLibraryComposer>().Object); // act sut.Execute(); // assert fileSystemMigrator.Verify(m => m.Migrate(), Times.Once); }
public ICommand CreateCommand(ScriptCsArgs args, string[] scriptArgs) { Guard.AgainstNullArgument("args", args); if (args.Help) { return new ShowUsageCommand(_scriptServiceRoot.Logger, isValid: true); } if (args.Repl) { var replCommand = new ExecuteReplCommand( _scriptServiceRoot.FileSystem, _scriptServiceRoot.ScriptPackResolver, _scriptServiceRoot.Engine, _scriptServiceRoot.FilePreProcessor, _scriptServiceRoot.Logger, _scriptServiceRoot.Console, _scriptServiceRoot.AssemblyName); return replCommand; } if (args.ScriptName != null) { var executeCommand = new ExecuteScriptCommand( args.ScriptName, scriptArgs, _scriptServiceRoot.FileSystem, _scriptServiceRoot.Executor, _scriptServiceRoot.ScriptPackResolver, _scriptServiceRoot.Logger, _scriptServiceRoot.AssemblyName); var fileSystem = _scriptServiceRoot.FileSystem; var currentDirectory = fileSystem.CurrentDirectory; var packageFile = Path.Combine(currentDirectory, Constants.PackagesFile); var packagesFolder = Path.Combine(currentDirectory, Constants.PackagesFolder); if (fileSystem.FileExists(packageFile) && !fileSystem.DirectoryExists(packagesFolder)) { var installCommand = new InstallCommand( null, false, fileSystem, _scriptServiceRoot.PackageAssemblyResolver, _scriptServiceRoot.PackageInstaller, _scriptServiceRoot.Logger); var restoreCommand = new RestoreCommand( args.ScriptName, _scriptServiceRoot.FileSystem, _scriptServiceRoot.PackageAssemblyResolver, _scriptServiceRoot.Logger); return new CompositeCommand(installCommand, restoreCommand, executeCommand); } if (args.Restore) { var restoreCommand = new RestoreCommand( args.ScriptName, _scriptServiceRoot.FileSystem, _scriptServiceRoot.PackageAssemblyResolver, _scriptServiceRoot.Logger); return new CompositeCommand(restoreCommand, executeCommand); } return executeCommand; } if (args.Install != null) { var installCommand = new InstallCommand( args.Install, args.AllowPreRelease, _scriptServiceRoot.FileSystem, _scriptServiceRoot.PackageAssemblyResolver, _scriptServiceRoot.PackageInstaller, _scriptServiceRoot.Logger); var restoreCommand = new RestoreCommand( args.Install, _scriptServiceRoot.FileSystem, _scriptServiceRoot.PackageAssemblyResolver, _scriptServiceRoot.Logger); var currentDirectory = _scriptServiceRoot.FileSystem.CurrentDirectory; var packageFile = Path.Combine(currentDirectory, Constants.PackagesFile); if (!_scriptServiceRoot.FileSystem.FileExists(packageFile)) { var saveCommand = new SaveCommand(_scriptServiceRoot.PackageAssemblyResolver); return new CompositeCommand(installCommand, restoreCommand, saveCommand); } return new CompositeCommand(installCommand, restoreCommand); } if (args.Clean) { var saveCommand = new SaveCommand(_scriptServiceRoot.PackageAssemblyResolver); var cleanCommand = new CleanCommand( args.ScriptName, _scriptServiceRoot.FileSystem, _scriptServiceRoot.PackageAssemblyResolver, _scriptServiceRoot.Logger); return new CompositeCommand(saveCommand, cleanCommand); } if (args.Save) { return new SaveCommand(_scriptServiceRoot.PackageAssemblyResolver); } if (args.Version) { return new VersionCommand(); } return new ShowUsageCommand(_scriptServiceRoot.Logger, isValid: false); }
public ICommand CreateCommand(ScriptCsArgs args, string[] scriptArgs) { Guard.AgainstNullArgument("args", args); if (args.Help) { return(new ShowUsageCommand(_scriptServices.Logger, isValid: true)); } if (args.Global) { var currentDir = _scriptServices.FileSystem.ModulesFolder; if (!_scriptServices.FileSystem.DirectoryExists(currentDir)) { _scriptServices.FileSystem.CreateDirectory(currentDir); } _scriptServices.FileSystem.CurrentDirectory = currentDir; } _scriptServices.InstallationProvider.Initialize(); if (args.Repl) { var replCommand = new ExecuteReplCommand( args.ScriptName, scriptArgs, _scriptServices.FileSystem, _scriptServices.ScriptPackResolver, _scriptServices.Engine, _scriptServices.FilePreProcessor, _scriptServices.ReplCommandService, _scriptServices.Logger, _scriptServices.Console, _scriptServices.AssemblyResolver); return(replCommand); } if (args.ScriptName != null) { var executeCommand = new ExecuteScriptCommand( args.ScriptName, scriptArgs, _scriptServices.FileSystem, _scriptServices.Executor, _scriptServices.ScriptPackResolver, _scriptServices.Logger, _scriptServices.AssemblyResolver); var fileSystem = _scriptServices.FileSystem; var currentDirectory = fileSystem.CurrentDirectory; var packageFile = Path.Combine(currentDirectory, Constants.PackagesFile); var packagesFolder = Path.Combine(currentDirectory, Constants.PackagesFolder); if (fileSystem.FileExists(packageFile) && !fileSystem.DirectoryExists(packagesFolder)) { var installCommand = new InstallCommand( null, false, fileSystem, _scriptServices.PackageAssemblyResolver, _scriptServices.PackageInstaller, _scriptServices.Logger); return(new CompositeCommand(installCommand, executeCommand)); } return(executeCommand); } if (args.Install != null) { var installCommand = new InstallCommand( args.Install, args.AllowPreRelease, _scriptServices.FileSystem, _scriptServices.PackageAssemblyResolver, _scriptServices.PackageInstaller, _scriptServices.Logger); string currentDirectory = null; currentDirectory = _scriptServices.FileSystem.CurrentDirectory; var packageFile = Path.Combine(currentDirectory, Constants.PackagesFile); if (!_scriptServices.FileSystem.FileExists(packageFile)) { var saveCommand = new SaveCommand(_scriptServices.PackageAssemblyResolver); return(new CompositeCommand(installCommand, saveCommand)); } return(installCommand); } if (args.Clean) { var saveCommand = new SaveCommand(_scriptServices.PackageAssemblyResolver); if (args.Global) { var currentDirectory = _scriptServices.FileSystem.ModulesFolder; _scriptServices.FileSystem.CurrentDirectory = currentDirectory; if (!_scriptServices.FileSystem.DirectoryExists(currentDirectory)) { _scriptServices.FileSystem.CreateDirectory(currentDirectory); } } var cleanCommand = new CleanCommand( args.ScriptName, _scriptServices.FileSystem, _scriptServices.Logger); return(new CompositeCommand(saveCommand, cleanCommand)); } if (args.Save) { return(new SaveCommand(_scriptServices.PackageAssemblyResolver)); } if (args.Version) { return(new VersionCommand(_scriptServices.Console)); } return(new ShowUsageCommand(_scriptServices.Logger, isValid: false)); }
public ICommand CreateCommand(ScriptCsArgs args) { if (args.Help) { return(new ShowUsageCommand(_scriptServiceRoot.Logger, isValid: true)); } if (args.Repl) { var replCommand = new ExecuteReplCommand( _scriptServiceRoot.FileSystem, _scriptServiceRoot.ScriptPackResolver, _scriptServiceRoot.Engine, _scriptServiceRoot.FilePreProcessor, _scriptServiceRoot.Logger, _scriptServiceRoot.Console); return(replCommand); } if (args.ScriptName != null) { var executeCommand = new ExecuteScriptCommand( args.ScriptName, _scriptServiceRoot.FileSystem, _scriptServiceRoot.Executor, _scriptServiceRoot.ScriptPackResolver, _scriptServiceRoot.Logger); if (args.Restore) { var restoreCommand = new RestoreCommand( args.ScriptName, _scriptServiceRoot.FileSystem, _scriptServiceRoot.PackageAssemblyResolver, _scriptServiceRoot.Logger); return(new CompositeCommand(restoreCommand, executeCommand)); } return(executeCommand); } if (args.Install != null) { var installCommand = new InstallCommand( args.Install, args.AllowPreRelease, _scriptServiceRoot.FileSystem, _scriptServiceRoot.PackageAssemblyResolver, _scriptServiceRoot.PackageInstaller, _scriptServiceRoot.Logger); var restoreCommand = new RestoreCommand( args.Install, _scriptServiceRoot.FileSystem, _scriptServiceRoot.PackageAssemblyResolver, _scriptServiceRoot.Logger); var currentDirectory = _scriptServiceRoot.FileSystem.CurrentDirectory; var packageFile = Path.Combine(currentDirectory, Constants.PackagesFile); if (!_scriptServiceRoot.FileSystem.FileExists(packageFile)) { var saveCommand = new SaveCommand(_scriptServiceRoot.PackageAssemblyResolver); return(new CompositeCommand(installCommand, restoreCommand, saveCommand)); } return(new CompositeCommand(installCommand, restoreCommand)); } if (args.Clean) { var saveCommand = new SaveCommand(_scriptServiceRoot.PackageAssemblyResolver); var cleanCommand = new CleanCommand( args.ScriptName, _scriptServiceRoot.FileSystem, _scriptServiceRoot.PackageAssemblyResolver, _scriptServiceRoot.Logger); return(new CompositeCommand(saveCommand, cleanCommand)); } if (args.Save) { return(new SaveCommand(_scriptServiceRoot.PackageAssemblyResolver)); } if (args.Version) { return(new VersionCommand()); } return(new ShowUsageCommand(_scriptServiceRoot.Logger, isValid: false)); }
public ICommand CreateCommand(ScriptCsArgs args) { if (args.ScriptName != null) { var executeCommand = new ExecuteScriptCommand( args.ScriptName, _scriptServiceRoot.FileSystem, _scriptServiceRoot.Executor, _scriptServiceRoot.ScriptPackResolver); if (args.Restore) { var restoreCommand = new RestoreCommand( args.ScriptName, _scriptServiceRoot.FileSystem, _scriptServiceRoot.PackageAssemblyResolver); return new CompositeCommand(restoreCommand, executeCommand); } return executeCommand; } if (args.Install != null) { var installCommand = new InstallCommand( args.Install, args.AllowPreReleaseFlag, _scriptServiceRoot.FileSystem, _scriptServiceRoot.PackageAssemblyResolver, _scriptServiceRoot.PackageInstaller); var restoreCommand = new RestoreCommand( args.Install, _scriptServiceRoot.FileSystem, _scriptServiceRoot.PackageAssemblyResolver); var currentDirectory = _scriptServiceRoot.FileSystem.CurrentDirectory; var packageFile = Path.Combine(currentDirectory, Constants.PackagesFile); if (!_scriptServiceRoot.FileSystem.FileExists(packageFile)) { var saveCommand = new SaveCommand(_scriptServiceRoot.PackageAssemblyResolver); return new CompositeCommand(installCommand, restoreCommand, saveCommand); } return new CompositeCommand(installCommand, restoreCommand); } if (args.Clean) { var saveCommand = new SaveCommand(_scriptServiceRoot.PackageAssemblyResolver); var cleanCommand = new CleanCommand( args.ScriptName, _scriptServiceRoot.FileSystem, _scriptServiceRoot.PackageAssemblyResolver); return new CompositeCommand(saveCommand, cleanCommand); } if (args.Save) { return new SaveCommand(_scriptServiceRoot.PackageAssemblyResolver); } if (args.Version) { return new VersionCommand(); } return new InvalidCommand(); }