public void Handle_HasErrors_ShouldReturnValueOfErrorHandler()
        {
            var result   = new ParseResult();
            var handlers = A.Fake <ICommandHandlers>();

            A.CallTo(() => handlers.HandleError(result)).Returns(1);
            result.ErrorHandler(handlers.HandleError);

            result.AddError(new OptionMissingError("optionA"));

            result.Handle().Should().Be(1);
        }
        public void Handle_HasErrors_ShouldCallCallErrorHandler()
        {
            var result   = new ParseResult();
            var handlers = A.Fake <ICommandHandlers>();

            result.ErrorHandler(handlers.HandleError);

            result.AddError(new OptionMissingError("optionA"));

            result.Handle();

            A.CallTo(() => handlers.HandleError(result)).MustHaveHappenedOnceExactly();
        }
        public void Handle_NoCommandOptions_ShouldNotCallHandlers()
        {
            var result   = new ParseResult();
            var handlers = A.Fake <ICommandHandlers>();

            result.CommandHandler <Command1Options>(handlers.HandleCommand1);
            result.ErrorHandler(handlers.HandleError);

            result.CommandOptions = null;

            result.Handle();

            A.CallTo(() => handlers.HandleCommand1(A <Command1Options> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => handlers.HandleError(A <ParseResult> .Ignored)).MustNotHaveHappened();
        }
        public void Handle_ErrorHandlerThrows_ShouldForwardErrorHandlerException()
        {
            var result   = new ParseResult();
            var handlers = A.Fake <ICommandHandlers>();

            A.CallTo(() => handlers.HandleError(result)).Throws(new Exception("Error Handler Exception"));
            result.ErrorHandler(handlers.HandleError);

            result.AddError(new OptionMissingError("optionA"));

            result.Invoking(a => a.Handle())
            .Should()
            .Throw <Exception>()
            .WithMessage("Error Handler Exception");
        }