public void Test_Init_Option_With_Explicit_Workspace_Path() { //arrange var traceService = new Mock <ITraceService>(); var environmentService = new Mock <IEnvironmentService>(); environmentService.Setup(s => s.GetCurrentDirectory()).Returns(@"c:\temp\yuniql"); var workspaceService = new Mock <IWorkspaceService>(); var configurationService = new Mock <IConfigurationService>(); configurationService.Setup(s => s.GetValueOrDefault(@"c:\temp\yuniql", ENVIRONMENT_VARIABLE.YUNIQL_WORKSPACE, @"c:\temp\yuniql")).Returns(@"c:\temp\yuniql"); var migrationService = new Mock <IMigrationService>(); var migrationServiceFactory = new Mock <CLI.IMigrationServiceFactory>(); migrationServiceFactory.Setup(s => s.Create("sqlserver")).Returns(migrationService.Object); var dataService = new Mock <IDataService>(); var dataServiceFactory = new Mock <CLI.IDataServiceFactory>(); dataServiceFactory.Setup(s => s.Create("sqlserver")).Returns(dataService.Object); //act var option = new InitOption { Workspace = @"c:\temp\yuniql" }; var sut = new CommandLineService(migrationServiceFactory.Object, dataServiceFactory.Object, workspaceService.Object, environmentService.Object, traceService.Object, configurationService.Object); sut.RunInitOption(option); //assert workspaceService.Verify(s => s.Init(@"c:\temp\yuniql")); }
public void Test_Init_Option_With_Explicit_Workspace_Path() { //arrange var traceService = new Mock <ITraceService>(); var environmentService = new Mock <IEnvironmentService>(); var localVersionService = new Mock <ILocalVersionService>(); var migrationService = new Mock <IMigrationService>(); var migrationServiceFactory = new Mock <CLI.IMigrationServiceFactory>(); migrationServiceFactory.Setup(s => s.Create("sqlserver")).Returns(migrationService.Object); //act var option = new InitOption { Path = @"c:\temp\yuniql-ex" }; var sut = new CommandLineService(migrationServiceFactory.Object, localVersionService.Object, environmentService.Object, traceService.Object); sut.RunInitOption(option); //assert localVersionService.Verify(s => s.Init(@"c:\temp\yuniql-ex")); }
//https://github.com/commandlineparser/commandline //https://github.com/dotnet/command-line-api public static int Main(string[] args) { var environmentService = new EnvironmentService(); var traceService = new FileTraceService(); var localVersionService = new LocalVersionService(traceService); var migrationServiceFactory = new CLI.MigrationServiceFactory(traceService); var commandLineService = new CommandLineService(migrationServiceFactory, localVersionService, environmentService, traceService); var resultCode = Parser.Default.ParseArguments < InitOption, RunOption, NextVersionOption, InfoOption, VerifyOption, EraseOption, BaselineOption, RebaseOption>(args) .MapResult( (InitOption opts) => { traceService.IsDebugEnabled = opts.Debug; return(commandLineService.RunInitOption(opts)); }, (RunOption opts) => { traceService.IsDebugEnabled = opts.Debug; return(commandLineService.RunMigration(opts)); }, (NextVersionOption opts) => { traceService.IsDebugEnabled = opts.Debug; return(commandLineService.IncrementVersion(opts)); }, (InfoOption opts) => { traceService.IsDebugEnabled = opts.Debug; return(commandLineService.RunInfoOption(opts)); }, (VerifyOption opts) => { traceService.IsDebugEnabled = opts.Debug; return(commandLineService.RunVerify(opts)); }, (EraseOption opts) => { traceService.IsDebugEnabled = opts.Debug; return(commandLineService.RunEraseOption(opts)); }, (BaselineOption opts) => { traceService.IsDebugEnabled = opts.Debug; return(commandLineService.RunBaselineOption(opts)); }, (RebaseOption opts) => { traceService.IsDebugEnabled = opts.Debug; return(commandLineService.RunRebaseOption(opts)); }, (ArchiveOption opts) => { traceService.IsDebugEnabled = opts.Debug; return(commandLineService.RunArchiveOption(opts)); }, errs => 1); return(resultCode); }