public void Can_Subscribe_All() { //Arrange var baseCustomEventClass = new BaseCustomEventClass(); var eventClass = new CustomEventClass(); var eventClass1 = new CustomEventClass1(); IEventBus eventBus = new Infrastructure.EventBus.Implementation.EventBus(); //Act eventBus.SubscribeAll(eb => { baseCustomEventClass.Result += "Received CustomEvent"; BaseCustomEventClass.Results += "Received CustomEvent"; }); eventBus.Subscribe <CustomEventClass>(cec => eventClass.Result += "Received CustomEvent"); eventBus.Subscribe <CustomEventClass1>(cec => eventClass1.Result += "Received CustomEvent"); eventBus.Publish(eventClass); eventBus.Publish(eventClass1); //Assert Assert.True(eventClass.Result == "Received CustomEvent"); Assert.True(eventClass1.Result == "Received CustomEvent"); Assert.True(baseCustomEventClass.Result == "Received CustomEventReceived CustomEvent"); Assert.True(BaseCustomEventClass.Results == "Received CustomEventReceived CustomEvent"); }
public void Dont_Recive_Message_When_Not_Subscribing_Event() { //Arrange var eventClass = new CustomEventClass(); var eventClass1 = new CustomEventClass1(); IEventBus eventBus = new Infrastructure.EventBus.Implementation.EventBus(); //Act eventBus.Subscribe <CustomEventClass>(cec => eventClass.Result += "Received CustomEvent"); eventBus.Subscribe <CustomEventClass1>(cec => eventClass1.Result += "Received CustomEvent"); eventBus.Publish(new CustomEventClass()); //Assert Assert.True(eventClass.Result == "Received CustomEvent"); Assert.Null(eventClass1.Result); }