public async Task Invoke_ExecuteFail_ReturnsFalse()
        {
            var command = Substitute.For <ICommand>();

            command.Execute().Returns(new ExecutionResult()
            {
                Success = false
            });

            var invoker = new CMDCommandInvoker(command);
            var result  = await invoker.Invoke();

            Assert.IsFalse(result.Success);
        }
        public async Task Invoke_ExecuteThrowsException_ReturnsFalse()
        {
            var command = Substitute.For <ICommand>();

            command
            .When(c => c.Execute())
            .Do(info =>
            {
                throw new Exception();
            });

            var invoker = new CMDCommandInvoker(command);
            var result  = await invoker.Invoke();

            Assert.IsFalse(result.Success);
        }
Esempio n. 3
0
        static async Task <int> Main(string[] args)
        {
            try
            {
                // Startup
                var provider = Startup.ConfigureServices(args);

                // execute
                var             command = provider.GetRequiredService <ICommand>();
                ICommandInvoker invoker = new CMDCommandInvoker(command);
                var             result  = await invoker.Invoke();

                return(result.Success ? ProgramResult.Success : ProgramResult.Fail);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);

                return(ProgramResult.Fail);
            }
        }