public CustomerService(EventSourcingService eventSourcingService) { _eventSourcingService = eventSourcingService; _eventSourcingService.SubscribeEvent(OrderCreated, OrderCreatedEventArgs.Empty); _customers.Add(SolventCustomer, 1000m); _customers.Add(InsolventCustomer, 50m); }
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 AddBuildingSelectionEvent() { BuildingSelectionEventDTO buildingSelectionEventDTO = new BuildingSelectionEventDTO(MainWindow._currentUsername, (int)Id); EventSourcingService eventSourcingService = new EventSourcingService(); eventSourcingService.AddBuildingSelectionEvent(buildingSelectionEventDTO); }
public void AddFloorChangeEvent(int choosenFloorNumber) { AddBuildingSelectionEvent(); FloorChangeEventDTO floorChangeEventDTO = new FloorChangeEventDTO(MainWindow._currentUsername, (int)Id, choosenFloorNumber); EventSourcingService eventSourcingService = new EventSourcingService(); eventSourcingService.AddFloorChangeEvent(floorChangeEventDTO); }
public void IfAnEventSubscriberThrowAnExceptionTheEventMustBeUpdateTheProcessingQueueRequest() { using (var service = new EventSourcingService(_unitOfWorkFactoryMock)) { service.SubscribeEvent((sender, args) => throw new NotImplementedException()); service.AddEvent(); service.WaitEventsProcessed(); } }
public void AddRoomSelectionEvent() { RoomSelectionEventDTO roomSelectionEventDTO = new RoomSelectionEventDTO(MainWindow._currentUsername, (int)Id); MapObjectController mapObjectController = new MapObjectController(new MapObjectServices(_fileRepository)); MapObject building = mapObjectController.GetMapObjectById(BuildingId); ((Building)building.MapObjectEntity).AddBuildingSelectionEvent(); EventSourcingService eventSourcingService = new EventSourcingService(); eventSourcingService.AddRoomSelectionEvent(roomSelectionEventDTO); }
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 async Task TheListenerCanBeAlsoAsync() { int raisedCount = 0; using (var service = new EventSourcingService(_unitOfWorkFactoryMock)) { service.SubscribeEvent(async(sender, args) => await Task.FromResult(raisedCount++)); service.AddEvent(); await service.WaitEventsProcessedAsync(); } 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 AnAddedEventIsPersistedAsNewInAnUnitOfWork() { var factoryMock = new Mock <IUnitOfWorkFactory <EventArgs> >(); var unitOfWorkMock = new Mock <IUnitOfWork <EventArgs> >(); factoryMock.Setup(f => f.New()).Returns(unitOfWorkMock.Object); var e = new EventArgs(); using (var service = new EventSourcingService(factoryMock.Object)) service.AddEvent(e); factoryMock.Verify(f => f.New()); unitOfWorkMock.Verify(u => u.New(e)); unitOfWorkMock.Verify(u => u.Commit()); unitOfWorkMock.Verify(u => u.Dispose()); }
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)); } }
public OrderService(EventSourcingService eventSourcingService) { _eventSourcingService = eventSourcingService; _eventSourcingService.SubscribeEvent(CustomerCreditRervationResult, CreditReservedEventArgs.Empty); _eventSourcingService.SubscribeEvent(CustomerCreditRervationResult, CreditLimitExceededEventArgs.Empty); }