public given_no_conference() { using (var context = new ConferenceContext(dbName)) { if (context.Database.Exists()) context.Database.Delete(); context.Database.CreateIfNotExists(); } this.bus = new MemoryEventBus(); this.service = new ConferenceService(this.bus, this.dbName); }
public void WhenPublishingEvent_ThenInvokesCompatibleHandler() { var handler = new Mock<IEventHandler<TestEvent>>(); var e = new ManualResetEventSlim(); handler.Setup(x => x.Handle(It.IsAny<TestEvent>())) .Callback(() => e.Set()); var bus = new MemoryEventBus(handler.Object); bus.Publish(new TestEvent()); e.Wait(3000); handler.Verify(x => x.Handle(It.IsAny<TestEvent>())); }
public void WhenPublishingMultipleEvents_ThenInvokesCompatibleHandlerMultipleTimes() { var handler = new Mock<IEventHandler<TestEvent>>(); var e = new ManualResetEventSlim(); var called = 0; handler.Setup(x => x.Handle(It.IsAny<TestEvent>())) .Callback(() => { if (Interlocked.Increment(ref called) == 4) e.Set(); }); var bus = new MemoryEventBus(handler.Object); bus.Publish(new[] { new TestEvent(), new TestEvent(), new TestEvent(), new TestEvent() }); e.Wait(10000); Assert.Equal(4, called); }
public void WhenPublishingEvent_ThenDoesNotInvokeIncompatibleHandler() { var compatibleHandler = new Mock<IEventHandler<TestEvent>>(); var incompatibleHandler = new Mock<IEventHandler<FooEvent>>(); var e = new ManualResetEventSlim(); compatibleHandler.Setup(x => x.Handle(It.IsAny<TestEvent>())) .Callback(() => e.Set()); var bus = new MemoryEventBus(incompatibleHandler.Object, compatibleHandler.Object); bus.Publish(new TestEvent()); e.Wait(3000); incompatibleHandler.Verify(x => x.Handle(It.IsAny<FooEvent>()), Times.Never()); }
public given_an_existing_conference_with_a_seat() { using (var context = new ConferenceContext(dbName)) { if (context.Database.Exists()) context.Database.Delete(); context.Database.CreateIfNotExists(); } this.bus = new MemoryEventBus(); this.service = new ConferenceService(this.bus, this.dbName); this.conference = new ConferenceInfo { OwnerEmail = "*****@*****.**", OwnerName = "test owner", AccessCode = "qwerty", Name = "test conference", Description = "test conference description", Location = "redmond", Slug = "test", StartDate = DateTime.UtcNow, EndDate = DateTime.UtcNow.Add(TimeSpan.FromDays(2)), IsPublished = true, Seats = { new SeatType { Name = "general", Description = "general description", Price = 100, Quantity = 10, } } }; service.CreateConference(this.conference); }