Exemplo n.º 1
0
        public void ErrorHandlerIsNotTriggeredForValueParsingException()
        {
            Exception?exception = null;
            var       exitCode  = new AppRunner <ExceptionApp>()
                                  .UseErrorHandler((ctx, ex) =>
            {
                exception = ex;
                return(ExitCodes.Error.Result);
            })
                                  .Run("Process -o");

            exitCode.Should().Be(1);
            exception.Should().BeNull();
        }
Exemplo n.º 2
0
        public void ErrorHandlerIsNotTriggeredForInvalidConfigurationException()
        {
            Exception?exception = null;
            var       exitCode  = new AppRunner <InvalidConfigurationApp>()
                                  .UseErrorHandler((ctx, ex) =>
            {
                exception = ex;
                return(ExitCodes.Error.Result);
            })
                                  .Run("Do");

            exitCode.Should().Be(1);
            exception.Should().BeNull();
        }
Exemplo n.º 3
0
        public void CanHandleErrorsFromConstructor()
        {
            CommandContext?context   = null;
            Exception?     exception = null;
            var            exitCode  = new AppRunner <ExceptionConstructorApp>()
                                       .UseErrorHandler((ctx, ex) =>
            {
                context   = ctx;
                exception = ex;
                return(ExitCodes.Error.Result);
            })
                                       .Run("Process");

            exitCode.Should().Be(1);
            AssertException(exception !, "Constructor is broken", "ExceptionConstructorApp", false);
            context.Should().NotBeNull();
        }
        public void CanDiscoverAllTests()
        {
            var classNames = new AppRunner <ThreeLevelsApp>()
                             .GetCommandClassTypes()
                             .Select(t => t.Name)
                             .ToList();

            classNames.Count.Should().Be(3);
            classNames.Should().ContainEquivalentOf(nameof(ThreeLevelsApp), nameof(Second), nameof(Third));

            classNames = new AppRunner <NestedThreeLevelsApp>()
                         .GetCommandClassTypes()
                         .Select(t => t.Name)
                         .ToList();
            classNames.Count.Should().Be(3);
            classNames.Should().ContainEquivalentOf(nameof(NestedThreeLevelsApp), nameof(Second), nameof(Third));
        }
Exemplo n.º 5
0
        public void CanHandleErrors(string?commandName, string?exceptionMessage = null)
        {
            var            args      = commandName == null?Array.Empty <string>() : new[] { commandName };
            CommandContext?context   = null;
            Exception?     exception = null;
            var            exitCode  = new AppRunner <ExceptionApp>()
                                       .UseErrorHandler((ctx, ex) =>
            {
                context   = ctx;
                exception = ex;
                return(ExitCodes.Error.Result);
            })
                                       .Run(args);

            exitCode.Should().Be(1);
            AssertException(exception !, exceptionMessage ?? commandName !, "ExceptionApp", false);
            context.Should().NotBeNull();
        }
Exemplo n.º 6
0
        public void CanHandleErrors(string commandName, string exceptionMessage = null)
        {
            var            args      = commandName == null ? new string[0] : new[] { commandName };
            CommandContext context   = null;
            Exception      exception = null;
            var            exitCode  = new AppRunner <ExceptionApp>()
                                       .UseErrorHandler((ctx, ex) =>
            {
                context   = ctx;
                exception = ex;
                return(ExitCodes.Error.Result);
            })
                                       .Run(args);

            exitCode.Should().Be(1);
            AssertException(exception, exceptionMessage ?? commandName, "ExceptionApp");
            context.Should().NotBeNull();
        }