public void Test_IncrementVersion_Option_Major_No_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(null, 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 NextVersionOption {
                IncrementMajorVersion = true
            };
            var sut = new CommandLineService(migrationServiceFactory.Object, dataServiceFactory.Object, workspaceService.Object, environmentService.Object, traceService.Object, configurationService.Object);

            sut.RunNextVersionOption(option);

            //assert
            workspaceService.Verify(s => s.IncrementMajorVersion(@"c:\temp\yuniql", null));
        }
        public void Test_Archive_Option_Throws_Not_Implemented_Exception()
        {
            //arrange
            var traceService         = new Mock <ITraceService>();
            var environmentService   = new Mock <IEnvironmentService>();
            var workspaceService     = new Mock <IWorkspaceService>();
            var configurationService = new Mock <IConfigurationService>();

            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 ArchiveOption {
            };
            var sut        = new CommandLineService(migrationServiceFactory.Object, dataServiceFactory.Object, workspaceService.Object, environmentService.Object, traceService.Object, configurationService.Object);
            var returnCode = sut.RunArchiveOption(option);

            //assert
            returnCode.ShouldNotBe(0);
        }
Esempio n. 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,
                ListOption,
                NextVersionOption,
                VerifyOption,
                EraseOption,
                BaselineOption,
                RebaseOption>(args)
                             .MapResult(
                (InitOption opts) => Dispatch(commandLineService.RunInitOption, opts, traceService),
                (RunOption opts) => Dispatch(commandLineService.RunMigration, opts, traceService),
                (NextVersionOption opts) => Dispatch(commandLineService.IncrementVersion, opts, traceService),
                (ListOption opts) => Dispatch(commandLineService.RunListOption, opts, traceService),
                (VerifyOption opts) => Dispatch(commandLineService.RunVerify, opts, traceService),
                (EraseOption opts) => Dispatch(commandLineService.RunEraseOption, opts, traceService),
                (BaselineOption opts) => Dispatch(commandLineService.RunBaselineOption, opts, traceService),
                (RebaseOption opts) => Dispatch(commandLineService.RunRebaseOption, opts, traceService),
                (ArchiveOption opts) => Dispatch(commandLineService.RunArchiveOption, opts, traceService),
                errs => 1);

            return(resultCode);
        }
Esempio n. 4
0
        /// <summary>
        /// Run development test without delay/overhead of doing a full Mobius startup
        /// </summary>

        static void RunDevTestMethod()
        {
            bool Y = DebugMx.True;             // run code (avoid compiler warning)
            bool N = DebugMx.False;            // don't run code

            if (N)
            {
                Mobius.CdkSearchMx.CdkSimSearchMx.Test("12345 12345");
                Application.Exit();
            }

            if (N)
            {
                CommandLineService.ExecuteCommand("Test Experimental Code");
                Application.Exit();
            }

            if (N)
            {
                Environment.Exit(-1);
                //Application.Exit();
            }

            if (N)
            {
                List <string> members = Mobius.UAL.ActiveDirectoryDao.GetGroupMembers(@"<domain>\Approved_Mobius_Chemview");
                return;
            }
        }
Esempio n. 5
0
        public void ShouldExecute()
        {
            // Given
            var      processInfo = ProcessInfoExtensions.Create();
            ExitCode exitCode    = 33;

            var processListener = new Mock <IProcessListener>();

            var process = new Mock <IProcess>();

            process.Setup(i => i.Run(processListener.Object)).Returns(exitCode);

            var processFactory = new Mock <IProcessFactory>();

            processFactory.Setup(i => i.Create(processInfo)).Returns(process.Object);

            var commandLine = new CommandLineService(processFactory.Object, processListener.Object);

            // When
            var actualExitCode = commandLine.Execute(processInfo);

            // Then
            process.Verify(i => i.Run(processListener.Object));
            actualExitCode.ShouldBe(exitCode);
        }
Esempio n. 6
0
    /// <summary>
    ///  Разбор вызова. Разбор конкретного вызова приложения из файла конфигурации.
    ///  Выполнено с учетом нескольких команд в файла конфигурации.
    /// </summary>
    /// <returns>Результат разбора. Хотя бы один алгоритм нормально отработал.</returns>
    public static bool ParseAllProp(string[] args) //, out ICommandLineRun result)
    {
        bool          rc = false;
        List <string> Parameters; // Список параметров подкомманды (например режимы работы класса).

        //Разбор конкретного вызова приложения из файла конфигурации.
        if (ParseConfig()) //
        {
            rc = true;
        }
        //Разбор конкретного вызова приложения из командной строки.
        if (ParseCommandLine(args, out Parameters))//
        {
            rc = true;
        }

        // продолжаем разбор в команде(CommandLineSample).
        // Создаем исполняющий класс.
        // Присваиваем свойствам значения.
        foreach (KeyValuePair <string, Dictionary <string, string> > propSubCom in subComs)
        {
            string            subCom    = propSubCom.Key;
            CommandLineSample cmdSample = CommandLineService.GetOrAddCommand(subCom, false);
            if (cmdSample == null)  // Нет обработки
            {
                continue;
            }

            Dictionary <string, string> properties = propSubCom.Value;
            rc = cmdSample.ParseCommandLine(properties, Parameters); //Создали исполняющий класс
        }

        return(rc);
    }
Esempio n. 7
0
        static void Main()
        {
            //Perform a simple greet
            IGreeter greeter = new EnglishGreeter();
            greeter.Greet(Environment.UserName);

            //Run the command line program - this demonstrates usage of protected fields
            var service = new CommandLineService();

            //To demonstrate field access (pointless field access mind you) set the field "Name"
            service.Name = "MyService";

            //Register commands and start
            service.RegisterCommand<QuitCommand>();
            service.RegisterCommand<SayHelloCommand>();
            service.RegisterCommand<TestCommand>();
            service.Start();

            //Display the "IsRunning" property - for no reason other than to prove property access is the same
            Console.Write("The CommandLineService {0} ", service.Name);
            if (service.IsRunning)
                Console.WriteLine("is still running");
            else
                Console.WriteLine("has stopped running");
        }
Esempio n. 8
0
        public void Test_Erase_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>();

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

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

            //act
            var option = new EraseOption {
                Tokens = new List <string> {
                    "Token1=TokenValue1", "Token2=TokenValue2", "Token3=TokenValue3"
                }
            };
            var sut = new CommandLineService(migrationServiceFactory.Object, localVersionService.Object, environmentService.Object, traceService.Object);

            sut.RunEraseOption(option);

            //assert
            migrationService.Verify(s => s.Initialize("sqlserver-connection-string", DEFAULT_CONSTANTS.COMMAND_TIMEOUT_SECS));
            migrationService.Verify(s => s.Erase(@"c:\temp\yuniql",
                                                 It.Is <List <KeyValuePair <string, string> > >(x =>
                                                                                                x[0].Key == "Token1" && x[0].Value == "TokenValue1" &&
                                                                                                x[1].Key == "Token2" && x[1].Value == "TokenValue2" &&
                                                                                                x[2].Key == "Token3" && x[2].Value == "TokenValue3"
                                                                                                ), DEFAULT_CONSTANTS.COMMAND_TIMEOUT_SECS, null));
        }
Esempio n. 9
0
        public Processor(
            CommandLineService commandLineService,
            ProjectParser projectParser,
            ProcessRunner processRunner,
            ILogger <Processor> logger)
        {
            AppDomain.CurrentDomain.UnhandledException += (s, e) =>
                                                          logger.LogCritical("发生了灾难性故障。请联系开发者反馈错误。\n" +
                                                                             ((e.ExceptionObject as Exception)?.Message ?? string.Empty));

            try
            {
                switch (commandLineService.Options)
                {
                case ProcessOptions:
                    processRunner.Run(projectParser.Parse());
                    break;

                default:
                    throw new IndexOutOfRangeException("不支持的命令类型。");
                }
            }
            catch (Exception e)
            {
                logger.LogCritical(e, "处理命令时出现错误。");
                Environment.Exit(1);
            }

            logger.LogInformation("完成了所有的操作。");
        }
Esempio n. 10
0
        public void Test_Info_Option_No_Explicit_Options()
        {
            //arrange
            var traceService       = new Mock <ITraceService>();
            var environmentService = new Mock <IEnvironmentService>();

            environmentService.Setup(s => s.GetEnvironmentVariable("YUNIQL_CONNECTION_STRING")).Returns("sqlserver-connection-string");
            var localVersionService = new Mock <ILocalVersionService>();
            var migrationService    = new Mock <IMigrationService>();

            migrationService.Setup(s => s.GetAllVersions(null, null)).Returns(new List <DbVersion> {
                new DbVersion {
                    Version = "v0.00", AppliedOnUtc = DateTime.UtcNow, AppliedByUser = "******"
                }
            });
            var migrationServiceFactory = new Mock <CLI.IMigrationServiceFactory>();

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

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

            sut.RunInfoOption(option);

            //assert
            migrationService.Verify(s => s.Initialize("sqlserver-connection-string", DEFAULT_CONSTANTS.COMMAND_TIMEOUT_SECS));
            migrationService.Verify(s => s.GetAllVersions(null, null));
        }
Esempio n. 11
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));
        }
Esempio n. 12
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);
            }
        }
Esempio n. 13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandBase"/> class.
 /// </summary>
 /// <param name="commandLineService">The command line service.</param>
 /// <param name="commandName">The command name.</param>
 protected CommandBase(CommandLineService commandLineService, string commandName)
 {
     if (commandLineService == null) throw new ArgumentNullException("commandLineService");
     if (commandName == null) throw new ArgumentNullException("commandName");
     this.commandLineService = commandLineService;
     this.commandName = commandName.ToLower();
 }
Esempio n. 14
0
        static void Main()
        {
            //Perform a simple greet
            IGreeter greeter = new EnglishGreeter();

            greeter.Greet(Environment.UserName);

            //Run the command line program - this demonstrates usage of protected fields
            var service = new CommandLineService();

            //To demonstrate field access (pointless field access mind you) set the field "Name"
            service.Name = "MyService";

            //Register commands and start
            service.RegisterCommand <QuitCommand>();
            service.RegisterCommand <SayHelloCommand>();
            service.RegisterCommand <TestCommand>();
            service.Start();

            //Display the "IsRunning" property - for no reason other than to prove property access is the same
            Console.Write("The CommandLineService {0} ", service.Name);
            if (service.IsRunning)
            {
                Console.WriteLine("is still running");
            }
            else
            {
                Console.WriteLine("has stopped running");
            }
        }
Esempio n. 15
0
        public void GetBookingTypeObject_ReturnsObjectWithGivenDateAndAmount()
        {
            var args = new[] { "einzahlung", "12.12.2012", "1" };

            var sut = CommandLineService.GetBookingTypeObject(args);

            Assert.That(sut.Date.ToShortDateString(), Is.EqualTo("12.12.2012"));
        }
Esempio n. 16
0
        public void GetBookingTypeObject_ReturnsObjectWithDate()
        {
            var args = new[] { "einzahlung" };

            var sut = CommandLineService.GetBookingTypeObject(args);

            Assert.That(sut.Date.ToShortDateString(), Is.EqualTo(DateTime.Now.ToShortDateString()));
        }
Esempio n. 17
0
        public static void Main(string[] args)
        {
            var bookingObject = (Deposit)CommandLineService.GetBookingTypeObject(args);

            new AppViewModel(bookingObject.Amount);

            Console.ReadLine();
        }
Esempio n. 18
0
        public void GetBookingTypeObject_ThrowsArgumentExceptionIfWrongFirstArg()
        {
            var args = new[] { "a" };

            var ex = Assert.Throws <ArgumentException>(() => CommandLineService.GetBookingTypeObject(args));

            Assert.That(ex.Message,
                        Is.EqualTo("first argument should be a valid booking type: uebersicht|einzahlung|auszahlung"));
        }
Esempio n. 19
0
        public void GetBookingTypeObject_ThrowsArgumentExceptionIfNoArgs()
        {
            var args = new string[] { };

            var ex = Assert.Throws <ArgumentException>(() => CommandLineService.GetBookingTypeObject(args));

            Assert.That(ex.Message,
                        Is.EqualTo("at least one argument must be given: uebersicht|einzahlung|auszahlung"));
        }
Esempio n. 20
0
        public ProcessRunner(
            CommandLineService commandLineService,
            FormattingService formattingService,
            ILogger <ProcessRunner> logger)
        {
            _commandLineService = commandLineService;
            _formattingService  = formattingService;
            _logger             = logger;

            Observable
            .FromEventPattern <EventArgs>(AppDomain.CurrentDomain, nameof(AppDomain.CurrentDomain.ProcessExit))
            .ObserveOn(TaskPoolScheduler.Default)
            .Subscribe(OnProcessExit);

            Observable
            .FromEventPattern <ConsoleCancelEventArgs>(typeof(Console), nameof(Console.CancelKeyPress))
            .ObserveOn(TaskPoolScheduler.Default)
            .Subscribe(OnCancelKeyPress);

            int dynamicLinkPort = ((ProcessOptions)_commandLineService.Options).DynamicLinkPort;

            if (dynamicLinkPort != 0)
            {
                _websocketClient = new(new Uri($"ws://127.0.0.1:{dynamicLinkPort}"))
                {
                    ReconnectTimeout = TimeSpan.FromSeconds(30)
                };

#if DEBUG
                _websocketClient.ReconnectionHappened
                .Subscribe(info =>
                {
                    _logger.LogWarning($"Dynamic link reconnected because of {info.Type}");
                });
#endif

                _websocketClient.MessageReceived
                .Where(x => x.MessageType == WebSocketMessageType.Text)
                .Where(x => x.Text == DynamicLinkKillCommand)
                .Subscribe(_ => TryKillProcess());

                _websocketClient.Start();

                _pipeSubject
                .Sample(TimeSpan.FromSeconds(0.5))
                .ObserveOn(TaskPoolScheduler.Default)
                .Subscribe(PipeSend);
            }

            _unsubscribe = _formattingService.FormatData.Subscribe(
                OnNext,
                OnError);
        }
Esempio n. 21
0
        public void Test_Verify_Option_With_Tokens()
        {
            //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 workspaceService = new Mock <IWorkspaceService>();

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

            var configuration = Configuration.Instance;

            configuration.Workspace        = @"C:\temp\yuniql";
            configuration.Platform         = SUPPORTED_DATABASES.SQLSERVER;
            configuration.ConnectionString = "sqlserver-connection-string";

            var configurationService = new Mock <IConfigurationService>();

            configurationService.Setup(s => s.GetValueOrDefault(null, ENVIRONMENT_VARIABLE.YUNIQL_PLATFORM, SUPPORTED_DATABASES.SQLSERVER)).Returns(SUPPORTED_DATABASES.SQLSERVER);

            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);

            var manifest        = new Mock <ManifestData>();
            var manifestFactory = new Mock <IManifestFactory>();

            manifestFactory.Setup(s => s.Create("sqlserver")).Returns(manifest.Object);

            //act
            var option = new VerifyOption {
                Tokens = new List <string> {
                    "Token1=TokenValue1", "Token2=TokenValue2", "Token3=TokenValue3"
                }
            };
            var sut = new CommandLineService(migrationServiceFactory.Object, dataServiceFactory.Object, manifestFactory.Object, workspaceService.Object, environmentService.Object, traceService.Object, configurationService.Object);

            sut.RunVerifyOption(option);

            //assert
            migrationService.Verify(s => s.Run());
        }
        public async Task RunAsyncTest()
        {
            var path    = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop));
            var arg     = path;
            var service = new CommandLineService(executable, arg);
            var timeout = TimeSpan.FromMilliseconds(500);
            var actual  = await service.RunAsync(new Progress <string>(str => Debug.WriteLine(str)),
                                                 new Progress <string>(str => Debug.WriteLine(str)), timeout,
                                                 new CancellationToken());

            const int expected = 0;

            Assert.Equal(expected, actual);
        }
Esempio n. 23
0
        public void Test_StackTrace_Shown_Depending_On_Debug_Flag(bool debugEnabled)
        {
            //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 environmentService   = new Mock <IEnvironmentService>();
            var configurationService = new Mock <IConfigurationService>();

            configurationService.Setup(s => s.GetValueOrDefault(null, ENVIRONMENT_VARIABLE.YUNIQL_PLATFORM, SUPPORTED_DATABASES.SQLSERVER)).Returns(SUPPORTED_DATABASES.SQLSERVER);
            configurationService.Setup(s => s.GetConfiguration()).Returns(Configuration.Instance);

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

            var fakeException = new Exception("Fake exception");

            migrationServiceFactory.Setup(s => s.Create("sqlserver")).Throws(fakeException);

            var dataService        = new Mock <IDataService>();
            var dataServiceFactory = new Mock <CLI.IDataServiceFactory>();

            dataServiceFactory.Setup(s => s.Create("sqlserver")).Returns(dataService.Object);

            var manifest        = new Mock <ManifestData>();
            var manifestFactory = new Mock <IManifestFactory>();

            manifestFactory.Setup(s => s.Create("sqlserver")).Returns(manifest.Object);

            var workspaceService = new Mock <IWorkspaceService>();

            //act
            var option = new RunOption {
                IsDebug = debugEnabled
            };
            var sut        = new CommandLineService(migrationServiceFactory.Object, dataServiceFactory.Object, manifestFactory.Object, workspaceService.Object, environmentService.Object, traceService.Object, configurationService.Object);
            var returnCode = sut.RunRunOption(option);

            //assert
            if (debugEnabled)
            {
                errorTraceMsg.ShouldContain(fakeException.StackTrace);
            }
            else
            {
                errorTraceMsg.ShouldNotContain(fakeException.StackTrace);
            }
        }
Esempio n. 24
0
        public ProjectParser(
            SingleProjectParser singleProjectParser,
            QueueProjectParser queueProjectParser,
            BatchProjectParser batchProjectParser,
            CommandLineService commandLineService,
            ILogger <ProjectParser> logger)
        {
            _singleProjectParser = singleProjectParser;
            _queueProjectParser  = queueProjectParser;
            _batchProjectParser  = batchProjectParser;

            _commandLineService = commandLineService;
            _logger             = logger;
        }
Esempio n. 25
0
    /// <summary>
    /// выполнить
    /// </summary>
    public override void Run()
    {
        CommandLineSample cmdln = CommandLineService.GetOrAddCommand(this.CommandName, false);

        if (cmdln != null)
        {     // совпала
            cmdln.Help();
        }
        else     // неправильная команда help
        {
            Console.WriteLine("Error calling program {0}.  command {1} does not exist ", AppName, this.CommandNameHelp);
            RulesOfchallenge();
        }
    }
Esempio n. 26
0
        public void Test_List_Option_No_Explicit_Options()
        {
            //arrange
            var traceService       = new Mock <ITraceService>();
            var environmentService = new Mock <IEnvironmentService>();

            environmentService.Setup(s => s.GetEnvironmentVariable("YUNIQL_CONNECTION_STRING")).Returns("sqlserver-connection-string");
            var workspaceService = new Mock <IWorkspaceService>();

            var configuration = Configuration.Instance;

            configuration.Workspace        = @"C:\temp\yuniql";
            configuration.Platform         = SUPPORTED_DATABASES.SQLSERVER;
            configuration.ConnectionString = "sqlserver-connection-string";

            var configurationService = new Mock <IConfigurationService>();

            configurationService.Setup(s => s.GetValueOrDefault(null, ENVIRONMENT_VARIABLE.YUNIQL_PLATFORM, SUPPORTED_DATABASES.SQLSERVER)).Returns(SUPPORTED_DATABASES.SQLSERVER);

            var migrationService = new Mock <IMigrationService>();

            migrationService.Setup(s => s.GetAllVersions(null, null)).Returns(new List <DbVersion> {
                new DbVersion {
                    Version = "v0.00", AppliedOnUtc = DateTime.UtcNow, AppliedByUser = "******"
                }
            });
            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);

            var manifest        = new Mock <ManifestData>();
            var manifestFactory = new Mock <IManifestFactory>();

            manifestFactory.Setup(s => s.Create("sqlserver")).Returns(manifest.Object);

            //act
            var option = new ListOption {
            };
            var sut    = new CommandLineService(migrationServiceFactory.Object, dataServiceFactory.Object, manifestFactory.Object, workspaceService.Object, environmentService.Object, traceService.Object, configurationService.Object);

            sut.RunListOption(option);

            //assert
            migrationService.Verify(s => s.GetAllVersions(null, null));
        }
Esempio n. 27
0
//                 .PerformingClass("UserServices.CommandLineTest.testCommandLine");
        // :  /parse -pathbase=C:\work\test1\ -pathconfig=C:\work\my_parse -targethost=https://panel.qnits.ru/manager_mvc/offers
        // :  /test -testbase=C:\work\test1\ -testconfig=C:\work\my_parse -targethost=https://panel.qnits.ru/manager_mvc/offers

        static void Main(string[] args)
        {
            Console.WriteLine("Привет от SpecificationCommandLine.");
            if (comndline != null & CommandLineService.ParseAllProp(args))  //после обработанная
            {
                // сделать проверку спецификаций
                if (CommandLineService.IsSatisfiedByService()) // прошла проверка
                {
                    CommandLineService.Run();
                    foreach (var cc1 in CommandLineService.cmdlines)
                    {
                        foreach (var pp1 in cc1.MandatoryProperties)
                        {
                            Console.WriteLine($"MandatoryProperties: Свойство {pp1.Key }:{pp1.Value} .");
                        }
                        cc1.Parameters.ToString();
                    }

                    foreach (var cc1 in CommandLineService.cmdlines)
                    {
                        foreach (var pp1 in cc1.OptionalProperties)
                        {
                            Console.WriteLine($"OptionalProperties: Свойство {pp1.Key } :{pp1.Value} .");
                        }
                        cc1.Parameters.ToString();
                    }

                    foreach (var cc1 in CommandLineService.cmdlines)
                    {
                        cc1.Parameters.ToString();
                    }
                    //string[] st = CommandLineService.GetErrors().`  Tuple<string , string >
                    foreach (var st1 in CommandLineService.GetErrors())
                    {
                        Console.WriteLine($"Свойство {st1.Key } ошибка:{st1.Value} .");
                    }
                }
                else // вывод ошибок
                {
                    ;
                }
            }
            else
            { // если без параметров вывод  или неправильный вызов
                CommandLineService.RulesOfchallenge();
            }
            Console.WriteLine("Expect  Enter.");
            Console.ReadKey();
        }
Esempio n. 28
0
        public void Test_Rebase_Option_Throws_Not_Implemented_Exception()
        {
            //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 RebaseOption {
            };
            var sut        = new CommandLineService(migrationServiceFactory.Object, localVersionService.Object, environmentService.Object, traceService.Object);
            var returnCode = sut.RunRebaseOption(option);

            returnCode.ShouldNotBe(0);
        }
Esempio n. 29
0
        public void TestMethod1()
        {
            ILogLevelSwitchService logSwitchService   = new LogLevelSwitchService();
            ICommandLineService    commandLineService = new CommandLineService();
            IDatabaseService       db             = new DatabaseService();
            IOptionsService        optionsService = new OptionsService(logSwitchService, commandLineService);
            IThumbnailService      service        = new ThumbnailService(db, optionsService);

            service.ClearThumbCache();

            var folder = Path.Combine(FileUtils.GetUsersTempFolder(), "OnlyMIntegrationTests");

            FileUtils.CreateDirectory(folder);

            var filePath = Path.Combine(folder, "TestImage01.jpg");

            var bmp = Properties.Resources.Test01;

            bmp.Save(filePath, ImageFormat.Jpeg);

            var lastWrite = File.GetLastWriteTimeUtc(filePath);

            var dummyFfmpegFolder = string.Empty; // not needed when getting image thumbs

            var thumb1 = service.GetThumbnail(filePath, dummyFfmpegFolder, MediaClassification.Image, lastWrite.Ticks, out var foundInCache);

            Assert.IsNotNull(thumb1);
            Assert.IsFalse(foundInCache);

            // try again to check we get cached version
            var thumb2 = service.GetThumbnail(filePath, dummyFfmpegFolder, MediaClassification.Image, lastWrite.Ticks, out foundInCache);

            Assert.IsNotNull(thumb2);
            Assert.IsTrue(foundInCache);

            // now send wrong lastchanged value
            var thumb3 = service.GetThumbnail(filePath, dummyFfmpegFolder, MediaClassification.Image, 123456, out foundInCache);

            Assert.IsNotNull(thumb3);
            Assert.IsFalse(foundInCache);

            service.ClearThumbCache();
        }
Esempio n. 30
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 workspaceService = new Mock <IWorkspaceService>();

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

            var configurationService = new Mock <IConfigurationService>();

            configurationService.Setup(s => s.GetValueOrDefault(null, ENVIRONMENT_VARIABLE.YUNIQL_PLATFORM, SUPPORTED_DATABASES.SQLSERVER)).Returns(SUPPORTED_DATABASES.SQLSERVER);

            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);

            var manifest        = new Mock <ManifestData>();
            var manifestFactory = new Mock <IManifestFactory>();

            manifestFactory.Setup(s => s.Create("sqlserver")).Returns(manifest.Object);

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

            sut.RunRunOption(option);

            //assert
            migrationService.Verify(s => s.Run());
        }
Esempio n. 31
0
        public void Test_Archive_Option_Throws_Not_Implemented_Exception()
        {
            //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
            Assert.ThrowsException <NotImplementedException>(() =>
            {
                var option = new ArchiveOption {
                };
                var sut    = new CommandLineService(migrationServiceFactory.Object, localVersionService.Object, environmentService.Object, traceService.Object);
                sut.RunArchiveOption(option);
            });
        }
        public void Test_Erase_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 workspaceService = new Mock <IWorkspaceService>();

            var configuration = Configuration.Instance;

            configuration.Workspace        = @"C:\temp\yuniql";
            configuration.Platform         = SUPPORTED_DATABASES.SQLSERVER;
            configuration.ConnectionString = "sqlserver-connection-string";

            var configurationService = new Mock <IConfigurationService>();

            configurationService.Setup(s => s.GetValueOrDefault(null, ENVIRONMENT_VARIABLE.YUNIQL_PLATFORM, SUPPORTED_DATABASES.SQLSERVER)).Returns(SUPPORTED_DATABASES.SQLSERVER);
            configurationService.Setup(s => s.Initialize());

            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 EraseOption {
            };
            var sut    = new CommandLineService(migrationServiceFactory.Object, dataServiceFactory.Object, workspaceService.Object, environmentService.Object, traceService.Object, configurationService.Object);

            sut.RunEraseOption(option);

            //assert
            migrationService.Verify(s => s.Erase());
        }
Esempio n. 33
0
 public SayHelloCommand(CommandLineService commandLineService) 
     : base(commandLineService, "hello")
 {
 }
Esempio n. 34
0
 /// <summary>
 /// Initializes a new instance of the <see cref="QuitCommand"/> class.
 /// </summary>
 /// <param name="commandLineService">The command line service.</param>
 public QuitCommand(CommandLineService commandLineService) 
     : base(commandLineService, "quit")
 {
 }
Esempio n. 35
0
 public TestCommand(CommandLineService commandLineService) 
     : base(commandLineService, "test")
 {
 }