public void TwoServiceSubriscribeAnEventReceivedEventOnTheirListener() { int raisedCount1 = 0; int raisedCount2 = 0; using (var service = new EventSourcingService(_unitOfWorkFactoryMock)) { service.SubscribeEvent((sender, args) => ++ raisedCount1); service.SubscribeEvent((sender, args) => ++ raisedCount2); var th1 = new Thread(() => { // ReSharper disable once AccessToDisposedClosure service.WaitEventsProcessed(); }); var th2 = new Thread(() => { // ReSharper disable once AccessToDisposedClosure service.WaitEventsProcessed(); }); service.AddEvent(); th1.Start(); th2.Start(); th1.Join(); th2.Join(); } Assert.Equal(1, raisedCount1); Assert.Equal(1, raisedCount2); }
public void IfAnEventSubscriberThrowAnExceptionTheEventMustBeUpdateTheProcessingQueueRequest() { using (var service = new EventSourcingService(_unitOfWorkFactoryMock)) { service.SubscribeEvent((sender, args) => throw new NotImplementedException()); service.AddEvent(); service.WaitEventsProcessed(); } }
public void WhenAnEventIsRaisedTheListenerReceiveTheEvent() { int raisedCount = 0; using (var service = new EventSourcingService(_unitOfWorkFactoryMock)) { service.SubscribeEvent((sender, args) => { raisedCount++; }); service.AddEvent(); service.WaitEventsProcessed(); } Assert.Equal(1, raisedCount); }
public void AStallOnAListenerOnEventCantBlockOtherListener() { int raisedCount = 0; using (var service = new EventSourcingService(_unitOfWorkFactoryMock)) { service.SubscribeEvent((sender, args) => { Thread.Sleep(int.MaxValue); }); service.SubscribeEvent((sender, args) => { raisedCount++; }); service.AddEvent(); service.WaitEventsProcessed(100); } Assert.Equal(1, raisedCount); }
public void TheEventRaisedToSusbscriberIsExactlyTheSameAddedToEventSourcing() { using (var service = new EventSourcingService(_unitOfWorkFactoryMock)) { var @event = new CustomEventArgs(); EventArgs receivedEvent = null; service.SubscribeEvent((sender, args) => { receivedEvent = args; }, new CustomEventArgs()); service.AddEvent(@event); service.WaitEventsProcessed(); Assert.Same(receivedEvent, @event); } }
public void TryOrderApprovedSuccessfully() { using (var eventSourcingService = new EventSourcingService(_unitOfWorkFactoryMock)) { var orderService = new OrderService(eventSourcingService); var customerService = new CustomerService(eventSourcingService); var customerCredit = customerService.GetCredit(SolventCustomer); bool?approved = null; orderService.OrderChekouted += (sender, args) => approved = args.Customer == SolventCustomer && args.Result; orderService.CreateOrder(SolventCustomer, 100m); eventSourcingService.WaitEventsProcessed(); Assert.True(approved); Assert.Equal(customerCredit - 100m, customerService.GetCredit(SolventCustomer)); } }