Пример #1
0
        public void Test_Run_Option_No_Explicit_Options()
        {
            //arrange
            var traceService       = new Mock <ITraceService>();
            var environmentService = new Mock <IEnvironmentService>();

            environmentService.Setup(s => s.GetCurrentDirectory()).Returns(@"c:\temp\yuniql");
            environmentService.Setup(s => s.GetEnvironmentVariable("YUNIQL_CONNECTION_STRING")).Returns("sqlserver-connection-string");

            var localVersionService = new Mock <ILocalVersionService>();

            localVersionService.Setup(s => s.GetLatestVersion(@"c:\temp\yuniql")).Returns("v1.00");

            var migrationService        = new Mock <IMigrationService>();
            var migrationServiceFactory = new Mock <CLI.IMigrationServiceFactory>();

            migrationServiceFactory.Setup(s => s.Create("sqlserver")).Returns(migrationService.Object);

            //act
            var option = new RunOption {
            };
            var sut    = new CommandLineService(migrationServiceFactory.Object, localVersionService.Object, environmentService.Object, traceService.Object);

            sut.RunMigration(option);

            //assert
            var toolName    = "yuniql-cli";
            var toolVersion = typeof(CommandLineService).Assembly.GetName().Version.ToString();

            migrationService.Verify(s => s.Initialize("sqlserver-connection-string", DEFAULT_CONSTANTS.COMMAND_TIMEOUT_SECS));
            migrationService.Verify(s => s.Run(@"c:\temp\yuniql", "v1.00", false, It.Is <List <KeyValuePair <string, string> > >(x => x.Count == 0), false, DEFAULT_CONSTANTS.BULK_SEPARATOR, null, null, DEFAULT_CONSTANTS.COMMAND_TIMEOUT_SECS, 0, toolName, toolVersion, null, null, false));
        }
Пример #2
0
        public void Test_StackTrace_Shown_Depending_On_Debug_Flag(bool isDebug)
        {
            //arrange
            var errorTraceMsg = string.Empty;
            var traceService  = new Mock <ITraceService>();

            traceService.Setup(s => s.Error(It.IsAny <string>(), null))
            .Callback <string, object>((msg, o) => errorTraceMsg = msg);

            var exc = new Exception("Fake exception");
            var environmentService = new Mock <IEnvironmentService>();

            environmentService.Setup(s => s.GetCurrentDirectory()).Throws(exc);

            //act
            var option = new RunOption {
                Debug = isDebug
            };
            var sut = new CommandLineService(null, null, environmentService.Object, traceService.Object);

            var returnCode = sut.RunMigration(option);

            //assert
            if (isDebug)
            {
                errorTraceMsg.ShouldContain(exc.StackTrace);
            }
            else
            {
                errorTraceMsg.ShouldNotContain(exc.StackTrace);
            }
        }
Пример #3
0
        //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);
        }