public void Subscribed_event_handler_should_not_receive_events_which_are_not_supported_by_handler()
        {
            var eventBroker  = GetEventBroker();
            var eventHandler = Substitute.For <IEventHandler <EventA> >();

            eventBroker.SubscribeHandlerInstance(eventHandler);
            var eventB = new EventB(Guid.NewGuid());

            eventBroker.Publish(eventB);

            eventHandler.DidNotReceiveWithAnyArgs().Handle(null);
        }
        public void Subscribed_event_handler_should_not_receive_events_which_are_not_supported_by_handler_with_type_registration()
        {
            var objectsCreator = ObjectsCreator.CreateNew(_substituteCreatorFunction);
            var eventBroker    = new SimpleInProcEventBroker(objectsCreator.InstanceCreatorFunction);

            eventBroker.SubscribeHandlerType <IEventHandler <EventA> >();
            var eventB = new EventB(Guid.NewGuid());

            eventBroker.Publish(eventB);

            objectsCreator.CreatedInstances.Should().BeEmpty();
        }
        public void Handler_that_handles_multiple_event_types_should_receive_all_supported_events_with_type_registration()
        {
            var objectsCreator = ObjectsCreator.CreateNew();
            var eventBroker    = new SimpleInProcEventBroker(objectsCreator.InstanceCreatorFunction);

            eventBroker.SubscribeHandlerType <MultiEventHandler>();

            var eventA = new EventA(Guid.NewGuid());
            var eventB = new EventB(Guid.NewGuid());

            eventBroker.Publish(eventA);
            eventBroker.Publish(eventB);

            objectsCreator.CreatedInstances.Should().HaveCount(2);
        }
        public void Handler_that_handles_multiple_event_types_should_receive_all_supported_events()
        {
            var eventBroker  = GetEventBroker();
            var eventHandler = Substitute.For <IEventHandler <EventA>, IEventHandler <EventB> >();

            eventBroker.SubscribeHandlerInstance(eventHandler);

            var eventA = new EventA(Guid.NewGuid());
            var eventB = new EventB(Guid.NewGuid());

            eventBroker.Publish(eventA);
            eventBroker.Publish(eventB);

            eventHandler.ReceivedWithAnyArgs(2);
            eventHandler.Received(1).Handle(eventA);
            ((IEventHandler <EventB>)eventHandler).Received(1).Handle(eventB);
        }
Beispiel #5
0
        public void Handler_that_handles_base_event_should_receive_calls_with_derived_event_also() //This is currently implementation specific behavior
        {
            var eventBroker = GetEventBroker();
            var eventHandlerForBaseEvent = Substitute.For <IEventHandler <BaseTestEvent> >();

            eventBroker.SubscribeHandlerInstance(eventHandlerForBaseEvent);

            var baseEvent = new BaseTestEvent(Guid.NewGuid());
            var eventA    = new EventA(Guid.NewGuid());
            var eventB    = new EventB(Guid.NewGuid());

            eventBroker.Publish(baseEvent);
            eventBroker.Publish(eventA);
            eventBroker.Publish(eventB);

            eventHandlerForBaseEvent.ReceivedWithAnyArgs(3).Handle(null);
            eventHandlerForBaseEvent.Received(1).Handle(baseEvent);
            eventHandlerForBaseEvent.Received(1).Handle(eventA);
            eventHandlerForBaseEvent.Received(1).Handle(eventB);
        }
        public void All_subscribed_handlers_should_receive_appropriate_events_with_type_registration()
        {
            var objectsCreator = ObjectsCreator.CreateNew(_substituteCreatorFunction);
            var eventBroker    = new SimpleInProcEventBroker(objectsCreator.InstanceCreatorFunction);

            eventBroker.SubscribeHandlerType <IEventHandler <EventA> >();
            eventBroker.SubscribeHandlerType <IEventHandler <EventB> >();

            var eventA  = new EventA(Guid.NewGuid());
            var eventA2 = new EventA(Guid.NewGuid());
            var eventB  = new EventB(Guid.NewGuid());

            eventBroker.Publish(eventA);
            eventBroker.Publish(eventA2);
            eventBroker.Publish(eventB);

            objectsCreator.CreatedInstances.Should().HaveCount(3);
            ((IEventHandler <EventA>)objectsCreator.CreatedInstances.First()).Received(1).Handle(eventA);
            ((IEventHandler <EventA>)objectsCreator.CreatedInstances.Skip(1).First()).Received(1).Handle(eventA2);
            ((IEventHandler <EventB>)objectsCreator.CreatedInstances.Skip(2).First()).Received(1).Handle(eventB);
        }
        public void All_subscribed_handlers_should_receive_appropriate_events()
        {
            var eventBroker = GetEventBroker();

            var eventHandler1 = Substitute.For <IEventHandler <EventA> >();
            var eventHandler2 = Substitute.For <IEventHandler <EventA> >();
            var eventHandler3 = Substitute.For <IEventHandler <EventB> >();

            eventBroker.SubscribeHandlerInstance(eventHandler1);
            eventBroker.SubscribeHandlerInstance(eventHandler2);
            eventBroker.SubscribeHandlerInstance(eventHandler3);

            var eventA = new EventA(Guid.NewGuid());
            var eventB = new EventB(Guid.NewGuid());

            eventBroker.Publish(eventA);
            eventBroker.Publish(eventB);

            eventHandler1.Received().Handle(eventA);
            eventHandler2.Received().Handle(eventA);
            eventHandler3.Received().Handle(eventB);
        }
 public void Handle(EventB eventData)
 {
 }
 public void Handle(EventB eventData)
 {
     throw new NotImplementedException();
 }