public void Dispatch_Should_Throw_MissingQueryHandlerException_When_No_Corresponding_Handler_Is_Found() { IDispatcher <IQuery> DispatcherTested = new Dispatcher <IQuery>(); TestQuery testQuery = new TestQuery(); string expectedMessage = $"No handler implementing IHandler<{testQuery.GetType().Name}, Object> has been found"; Assert.That(() => DispatcherTested.Dispatch <object>(testQuery), Throws.TypeOf <MissingHandlerException>() .With.Message.EqualTo(expectedMessage)); }
public void Dispatch_Should_Call_TryHandle_On_Corresponding_Handler_Interface() { MultiInterfaceHandler fakeHandler = new MultiInterfaceHandler(); IDispatcher <IQuery> DispatcherTested = new Dispatcher <IQuery>(fakeHandler); TestQuery testQuery = new TestQuery(); OtherTestQuery otherTestQuery = new OtherTestQuery(); DispatcherTested.Dispatch <int>(testQuery).Should().Be(42); DispatcherTested.Dispatch <string>(otherTestQuery).Should().Be("42"); }
public void Dispatch_Should_Call_TryHandle() { TestResponse expectedResult = new TestResponse { Name = "Tata" }; TestQuery testQuery = new TestQuery(); FakeHandler <TestResponse> fakeHandler = new FakeHandler <TestResponse>(expectedResult); IDispatcher <IQuery> DispatcherTested = new Dispatcher <IQuery>(fakeHandler); TestResponse result = DispatcherTested.Dispatch <TestResponse>(testQuery); result.Should().BeSameAs(expectedResult); }
public void Dispatch_Should_Call_TryHandle_On_Corresponding_Handler() { TestResponse expectedResult = new TestResponse { Name = "hjruihreigh" }; FakeHandler <string> fakeStringHandler = new FakeHandler <string>("Fake"); FakeHandler <TestResponse> fakeHandler = new FakeHandler <TestResponse>(expectedResult); IDispatcher <IQuery> DispatcherTested = new Dispatcher <IQuery>(fakeStringHandler, fakeHandler); TestQuery testQuery = new TestQuery(); TestResponse response = DispatcherTested.Dispatch <TestResponse>(testQuery); response.Should().BeSameAs(expectedResult); }
public TResult TryHandle(TestQuery dispatchable) { return(FakeResponse); }