public void WhenInstantiated_ThenShouldBeOfCorrectType() { var handler = new ShipOrderHandler(_repositoryMoq.Object); Assert.NotNull(handler); Assert.IsType <ShipOrderHandler>(handler); }
public async Task ShipOrder_Success() { //adhere var initialInventory = ProductStockpileShop.Inventory.DeepCopy(); //arrange var command = new ShipOrder { Id = OrderReadyForShipment.Id, InitiatorId = GlobalAdmin.Id }; var handler = new ShipOrderHandler(EntityRepository, OrderService, InventoryService, EventTransmitter); //act await handler.HandleAsync(command); //assert var orderAmount = OrderReadyForShipment.ItemsProduced.Of(Product1InteriorDoor).Amount; var inventoryDiff = initialInventory.Of(Product1InteriorDoor).Amount - ProductStockpileShop.Inventory.Of(Product1InteriorDoor).Amount; Assert.That(orderAmount, Is.EqualTo(inventoryDiff)); Assert.That(RecordedEventCount <OrderShipped>(), Is.EqualTo(1)); Assert.That(RecordedEventCount <DomainEvent <Order> >(), Is.EqualTo(1)); //annul ProductStockpileShop.Inventory = initialInventory; }
public async Task WhenOrderDoesNotExist_ThenShouldReturnNotFound() { _repositoryMoq.Setup(x => x.GetAsync(It.IsAny <Guid>())) .ReturnsAsync((Order)null !); var handler = new ShipOrderHandler(_repositoryMoq.Object); var result = await handler.Handle(new ShipOrder(Guid.Empty), default); Assert.NotNull(result); Assert.Equal(CommandOutcome.NotFound, result.Outcome); }
public async Task WhenConcurrencyExceptionOccurs_ThenShouldReturnConflict() { var order = _mapper.Map <Order>(Orders.Order1); _repositoryMoq.Setup(x => x.GetAsync(It.IsAny <Guid>())) .ReturnsAsync(order); _repositoryMoq.Setup(x => x.UpdateOrderStateAsync(It.IsAny <Order>(), It.IsAny <OrderState>())) .ThrowsAsync(new ConcurrencyException()); var handler = new ShipOrderHandler(_repositoryMoq.Object); var result = await handler.Handle(new ShipOrder(Guid.Empty), default); Assert.NotNull(result); Assert.Equal(CommandOutcome.Conflict, result.Outcome); }
public async Task WhenOrderFailsToUpdate_ThenShouldReturnNotFound() { var order = _mapper.Map <Order>(Orders.Order1); _repositoryMoq.Setup(x => x.GetAsync(It.IsAny <Guid>())) .ReturnsAsync(order); _repositoryMoq.Setup(x => x.UpdateOrderStateAsync(It.IsAny <Order>(), It.IsAny <OrderState>())) .ReturnsAsync((Order)null !); var handler = new ShipOrderHandler(_repositoryMoq.Object); var result = await handler.Handle(new ShipOrder(Guid.Empty), default); Assert.NotNull(result); Assert.Equal(CommandOutcome.NotFound, result.Outcome); }