public async Task ChangePrice() { var(_, repository, mediator) = TestSetup.Init(); var handler = new ProductCommandHandlers(repository, mediator); var id = Guid.NewGuid(); var productCreateCommand = new ProductCreateCommand { Id = id, Name = "mock name", Price = 500 }; await handler.Handle(productCreateCommand, CancellationToken.None); const int newPrice = 600; var priceChangeCommand = new ProductChangePriceCommand { ProductId = id, Price = newPrice }; await handler.Handle(priceChangeCommand, CancellationToken.None); var agg = await repository.GetHydratedAggregate <Kanayri.Domain.Product.Product>(id, CancellationToken.None); Assert.Equal(newPrice, agg.Price); }
public async Task QueryChangePrice() { var(_, repository, mediator) = TestSetup.Init(); var handler = new ProductCommandHandlers(repository, mediator); var id = Guid.NewGuid(); const int price1 = 500; const int price2 = 600; const int price3 = 700; var productCreateCommand = new ProductCreateCommand { Id = id, Name = "mock name", Price = price1 }; await handler.Handle(productCreateCommand, CancellationToken.None); var priceChange1 = new ProductChangePriceCommand { ProductId = id, Price = price2 }; await handler.Handle(priceChange1, CancellationToken.None); var priceChange2 = new ProductChangePriceCommand { ProductId = id, Price = price3 }; await handler.Handle(priceChange2, CancellationToken.None); var events = await repository.GetEventsOfType <ProductPriceChangedEvent>(id, CancellationToken.None); var changedEvents = events as ProductPriceChangedEvent[] ?? events.ToArray(); Assert.Equal(2, changedEvents.Count()); Assert.Equal(price2, changedEvents.ElementAt(0).Price); Assert.Equal(price3, changedEvents.ElementAt(1).Price); }
private void RegisterEDA() { ISubscriber subscriber = ServiceLocator.Subscriber; // Commands var productCommandHandlers = new ProductCommandHandlers(ServiceLocator.EventBus, ServiceLocator.EventStore); subscriber.RegisterHandler(WrapLogger <AddProductCommand>(productCommandHandlers.Execute)); subscriber.RegisterHandler(WrapLogger <RemoveProductCommand>(productCommandHandlers.Execute)); subscriber.RegisterHandler(WrapLogger <SubmitOrderCommand>(productCommandHandlers.Execute)); subscriber.RegisterHandler(WrapLogger <EmptyCardCommand>(productCommandHandlers.Execute)); // Events var productEventHandlers = new ProductEventHandlers(); subscriber.RegisterHandler(WrapLogger <ProductAddedEvent>(productEventHandlers.Handle)); subscriber.RegisterHandler(WrapLogger <ProductRemovedEvent>(productEventHandlers.Handle)); var logProductAdd = new LogForProduct(); subscriber.RegisterHandler(WrapLogger <ProductAddedEvent>(logProductAdd.Handle)); subscriber.RegisterHandler(WrapLogger <ProductRemovedEvent>(logProductAdd.Handle)); var notifyWareHouse = new NotifyWareHouse(); subscriber.RegisterHandler(WrapLogger <OrderSubmittedEvent>(notifyWareHouse.Handle)); var sendConfirmationOrderShipped = new SendConfirmationOrderShipped(); subscriber.RegisterHandler(WrapLogger <OrderSubmittedEvent>(sendConfirmationOrderShipped.Handle)); var smailOrderConfirmation = new EmailOrderConfirmation(); subscriber.RegisterHandler(WrapLogger <OrderSubmittedEvent>(smailOrderConfirmation.Handle)); var notifySignalR = new NotifySignalR(); subscriber.RegisterHandler(WrapLogger <OrderSubmittedEvent>(notifySignalR.Handle)); subscriber.RegisterHandler(WrapLogger <ProductAddedEvent>(notifySignalR.Handle)); subscriber.RegisterHandler(WrapLogger <ProductRemovedEvent>(notifySignalR.Handle)); }
public async Task CreateProduct() { var(context, repository, mediator) = TestSetup.Init(); var handler = new ProductCommandHandlers(repository, mediator); var command = new ProductCreateCommand { Id = Guid.NewGuid(), Name = "New Product", Price = 500 }; await handler.Handle(command, new CancellationToken(false)); var aggregates = await context.Aggregate.ToListAsync(); var events = await context.Events.ToListAsync(); Assert.Single(aggregates); Assert.Single(events); }
public ProductsController(ProductCommandHandlers handler) { this.handler = handler; }