public void Subscribing_same_event_handler_instance_multiple_times_shouldnt_result_in_multiple_handle_calls_to_the_same_instance_with_type_registration() { var objectsCreator = ObjectsCreator.CreateNew(_substituteCreatorFunction); var eventBroker = new SimpleInProcEventBroker(objectsCreator.InstanceCreatorFunction); eventBroker.SubscribeHandlerType <IEventHandler <EventA> >(); eventBroker.SubscribeHandlerType <IEventHandler <EventA> >(); var eventA = new EventA(Guid.NewGuid()); eventBroker.Publish(eventA); objectsCreator.CreatedInstances.Should().HaveCount(1); objectsCreator.CreatedInstances.Cast <IEventHandler <EventA> >().Single().Received(1).Handle(eventA); }
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 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 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); }