示例#1
0
        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));
        }
示例#2
0
        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");
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
 public TResult TryHandle(TestQuery dispatchable)
 {
     return(FakeResponse);
 }