public void Handle_NoMatchingCommandHandler_ShouldNotCallNonMatchingCommandHandlers() { var result = new ParseResult(); var handlers = A.Fake <ICommandHandlers>(); var command1Options = new Command1Options(); result.CommandHandler <Command2Options>(handlers.HandleCommand2); result.CommandHandler <Command3Options>(handlers.HandleCommand3); result.CommandOptions = command1Options; result.Handle(); A.CallTo(() => handlers.HandleCommand2(A <Command2Options> .Ignored)).MustNotHaveHappened(); A.CallTo(() => handlers.HandleCommand3(A <Command3Options> .Ignored)).MustNotHaveHappened(); }
public void Handle_CommandHandlerThrows_ShouldForwardCommandHandlerException() { var result = new ParseResult(); var handlers = A.Fake <ICommandHandlers>(); var command1Options = new Command1Options(); A.CallTo(() => handlers.HandleCommand1(command1Options)).Throws(new Exception("Command Handler Exception")); result.CommandHandler <Command1Options>(handlers.HandleCommand1); result.CommandOptions = command1Options; result.Invoking(a => a.Handle()) .Should() .Throw <Exception>() .WithMessage("Command Handler Exception"); try { result.Handle(); } catch (Exception ex) { Console.Out.WriteLine(ex.ToString()); } }
public void Handle_NoMatchingCommandHandler_ShouldReturn0() { var result = new ParseResult(); var handlers = A.Fake <ICommandHandlers>(); var command1Options = new Command1Options(); result.CommandHandler <Command2Options>(handlers.HandleCommand2); result.CommandOptions = command1Options; result.Handle().Should().Be(0); }
public void Handle_HasErrors_ShouldNotCallAnyCommandHandler() { var result = new ParseResult(); var handlers = A.Fake <ICommandHandlers>(); result.CommandHandler <Command1Options>(handlers.HandleCommand1); result.AddError(new OptionMissingError("optionA")); result.Handle(); A.CallTo(() => handlers.HandleCommand1(A <Command1Options> .Ignored)).MustNotHaveHappened(); }
public void Handle_MatchingCommandHandlerExists_ShouldReturnValueOfCommandHandler() { var result = new ParseResult(); var handlers = A.Fake <ICommandHandlers>(); var command1Options = new Command1Options(); A.CallTo(() => handlers.HandleCommand1(command1Options)).Returns(1); result.CommandHandler <Command1Options>(handlers.HandleCommand1); result.CommandOptions = command1Options; result.Handle().Should().Be(1); }
public void Handle_MatchingCommandHandlerExists_ShouldCallMatchingCommandHandler() { var result = new ParseResult(); var handlers = A.Fake <ICommandHandlers>(); var command1Options = new Command1Options(); result.CommandHandler <Command1Options>(handlers.HandleCommand1); result.CommandOptions = command1Options; result.Handle(); A.CallTo(() => handlers.HandleCommand1(command1Options)).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(); }