public void Subscribed_event_handler_should_receive_published_event_of_same_type() { var eventBroker = GetEventBroker(); var eventHandler = Substitute.For <IEventHandler <EventA> >(); eventBroker.SubscribeHandlerInstance(eventHandler); var eventA = new EventA(Guid.NewGuid()); eventBroker.Publish(eventA); eventHandler.Received(1).Handle(eventA); }
public void Subscribing_same_event_handler_instance_multiple_times_shouldnt_result_in_multiple_handle_calls_to_the_same_instance() { var eventBroker = GetEventBroker(); var eventHandler = Substitute.For <IEventHandler <EventA> >(); eventBroker.SubscribeHandlerInstance(eventHandler); eventBroker.SubscribeHandlerInstance(eventHandler); var eventA = new EventA(Guid.NewGuid()); eventBroker.Publish(eventA); eventHandler.Received(1).Handle(eventA); }
public void Subscribed_event_handler_should_receive_published_event_of_same_type_with_type_registration() { var objectsCreator = ObjectsCreator.CreateNew(_substituteCreatorFunction); var eventBroker = new SimpleInProcEventBroker(objectsCreator.InstanceCreatorFunction); 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 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); }
public void After_unsubscribing_events_shouldnt_be_passed_to_handler() { var eventBroker = GetEventBroker(); var eventHandler = Substitute.For <IEventHandler <EventA> >(); eventBroker.SubscribeHandlerInstance(eventHandler); var eventA = new EventA(Guid.NewGuid()); eventBroker.Publish(eventA); eventHandler.Received(1).Handle(eventA); eventBroker.Publish(eventA); eventHandler.Received(2).Handle(eventA); eventBroker.UnsubscribeHandlerInstance(eventHandler); eventBroker.Publish(eventA); eventHandler.Received(2).Handle(eventA); }
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); }