public void GivenSubscriber_WhenUnregister_ShouldNoLongerReceiveEvents() { var @event = new TestEvent("One"); var subscriber = new TestEventSubscriber(); var bus = new SimpleBus(); bus.Register(subscriber); bus.Post(@event); Assert.Single(subscriber.Events); bus.Unregister(subscriber); bus.Post(@event); Assert.Single(subscriber.Events); }
public void GivenSubscriber_WhenPost_ShouldSendEventToSubscriber() { var @event = new TestEvent("One"); var subscriber = new TestEventSubscriber(); var bus = new SimpleBus(); bus.Register(subscriber); bus.Post(@event); Assert.Single(subscriber.Events); }
public void GivenMultipleSubscribers_WhenPost_ShouldSentEventToAllSubscribers() { var @event = new TestEvent("One"); var subscriber1 = new TestEventSubscriber(); var subscriber2 = new TestEventSubscriber(); var bus = new SimpleBus(); bus.Register(subscriber1) .Register(subscriber2); bus.Post(@event); Assert.Single(subscriber1.Events); Assert.Single(subscriber2.Events); }
private void Replay() { var events = new EventList(); using (var conn = _configuration.CreateConnection()) { conn.Open(); var cmd = conn.CreateCommand(); cmd.CommandText = "delete from Customer"; cmd.ExecuteNonQuery(); cmd = conn.CreateCommand(); cmd.CommandText = "select * from CustomerEvent order by eventDateTime asc"; var reader = cmd.ExecuteReader(); while (reader.Read()) { events.Add(_eventSerializer.Deserialize((string)reader["eventType"], (byte[])reader["Data"])); } } events.ForEach(x => _bus.Post(x)); }