public SkuStock_added_tests()// Given_sku_created_and_stock_added_messages_When_projected() { _stockCreatedEvent = new SkuStockCreated(Guid.NewGuid(), Guid.NewGuid(), 100, TimeSpan.FromDays(2)); _stockAddedEvent = new StockAdded(_stockCreatedEvent.SourceId, 15, "test pack"); ProjectionBuilder.Handle(_stockCreatedEvent).Wait(); ProjectionBuilder.Handle(_stockAddedEvent).Wait(); }
public SkuStock_taken_tests()// Given_sku_created_and_taken_messages_When_projected() { var stockId = Guid.NewGuid(); _stockCreatedEvent = new SkuStockCreated(stockId, Guid.NewGuid(), 5, TimeSpan.FromDays(2)); _stockTakenEvent = new StockTaken(stockId, 3); ProjectionBuilder.Handle(_stockCreatedEvent).Wait(); ProjectionBuilder.Handle(_stockTakenEvent).Wait(); }
public async Task Given_no_reserve_When_reserve_taken_projected_Then_error_occurs() { var stockId = Guid.NewGuid(); var stockCreatedEvent = new SkuStockCreated(stockId, Guid.NewGuid(), 1, TimeSpan.FromDays(2)); var reserveTaken = new StockReserveTaken(stockId, Guid.NewGuid()); await ProjectionBuilder.Handle(stockCreatedEvent); await Assert.ThrowsAsync <ReserveEntryNotFoundException>(() => ProjectionBuilder.Handle(reserveTaken)); }
public SkuStock_reserve_taken_tests()// Given_sku_created_and_stock_added_and_stock_reserved_messages_When_projected() { var stockId = Guid.NewGuid(); _stockCreatedEvent = new SkuStockCreated(stockId, Guid.NewGuid(), 1, TimeSpan.FromDays(2)); _stockReservedEvent = new StockReserved(stockId, Guid.NewGuid(), DateTime.Now.AddDays(1), 7); _stockReserveTakenEvent = new StockReserveTaken(stockId, _stockReservedEvent.ReserveId); ProjectionBuilder.Handle(_stockCreatedEvent).Wait(); ProjectionBuilder.Handle(_stockReservedEvent).Wait(); ProjectionBuilder.Handle(_stockReserveTakenEvent).Wait(); }
public async Task When_adding_stock_Aggregate_quantity_should_be_increased_by_command_amount() { AddToStockCommand command; SkuStockCreated created; StockAdded added; var id = Guid.NewGuid(); var scenario = await AggregateScenario.New <SkuStock, SkuStockCommandsHandler>() .Given(created = new SkuStockCreated(id, _skuId, 50, TimeSpan.FromMilliseconds(100)), added = new StockAdded(id, 10, "test batch 2")) .When(command = new AddToStockCommand(id, _skuId, 10, "test batch")) .Then(new StockAdded(id, command.Quantity, command.BatchArticle)) .Run(); Assert.Equal(command.Quantity + created.Quantity + added.Quantity, scenario.Aggregate.Quantity); }
public async Task Given_sku_created_and_stock_added_and_stock_reserved_messages_When_projected() { var stockId = Guid.NewGuid(); var stockCreatedEvent = new SkuStockCreated(stockId, Guid.NewGuid(), 1, TimeSpan.FromDays(2)); var stockReservedEvent = new StockReserved(stockId, Guid.NewGuid(), DateTime.Now.AddDays(1), 7); var stockReserveTakenEvent = new StockReserveTaken(stockId, stockReservedEvent.ReserveId); await ProjectionBuilder.Handle(stockCreatedEvent); await ProjectionBuilder.Handle(stockReservedEvent); await ProjectionBuilder.Handle(stockReserveTakenEvent); await Assert.ThrowsAsync <ReserveEntryNotFoundException>(() => ProjectionBuilder.Handle(stockReserveTakenEvent)); }
public async Task Given_sku_created_and_taken_messages_When_projected_Then_another_history_is_added() { var stockId = Guid.NewGuid(); var stockCreatedEvent = new SkuStockCreated(stockId, Guid.NewGuid(), 7, TimeSpan.FromDays(2)); var stockTaken = new StockTaken(stockId, 3); await ProjectionBuilder.Handle(stockCreatedEvent); await ProjectionBuilder.Handle(stockTaken); await ProjectionBuilder.Handle(stockTaken); using (var context = CreateContext()) { Assert.Equal(3, context.StockHistory.Count()); Assert.Equal(1, context.SkuStocks.Find(stockId).AvailableQuantity); } }
public async Task Given_sku_created_and_stock_added_and_stock_reserved_messages_When_projected_twice() { var stockId = Guid.NewGuid(); var stockCreatedEvent = new SkuStockCreated(stockId, Guid.NewGuid(), 1, TimeSpan.FromDays(2)); var stockAddedEvent = new StockAdded(stockId, 15, "test pack"); var stockReservedEvent = new StockReserved(stockId, Guid.NewGuid(), DateTime.Now.AddDays(1), 7); var reserveCanceledEvent = new ReserveCanceled(stockId, stockReservedEvent.ReserveId); await ProjectionBuilder.Handle(stockCreatedEvent); await ProjectionBuilder.Handle(stockAddedEvent); await ProjectionBuilder.Handle(stockReservedEvent); await ProjectionBuilder.Handle(reserveCanceledEvent); await ProjectionBuilder.Handle(reserveCanceledEvent) .ShouldThrow <ReserveEntryNotFoundException>(); }
public SkuStock_created_tests() // Given_sku_created_message_When_projected() { _message = new Fixture().Create <SkuStockCreated>(); ProjectionBuilder.Handle(_message).Wait(); }