public async Task CreateOrder_Success() { //arrange const decimal amount = 5; var command = new CreateOrder() { Name = "New order for product 1", CustomerId = CustomerDoorsBuyer.Id, Items = new List <(Guid, decimal)> { (Product1InteriorDoor.Id, amount) }, ShipmentDeadline = DateTimeOffset.Parse("2022-01-01"), InitiatorId = GlobalAdmin.Id }; var handler = new CreateOrderHandler(EntityRepository, InventoryService, EventTransmitter); //act await handler.HandleAsync(command); //assert Assert.That(CallsTo(EntityRepository, nameof(EntityRepository.AddAsync)), Is.EqualTo(1)); var entity = GetRecordedEntities <Order>(EntityRepository, nameof(EntityRepository.AddAsync)).Single(); Assert.That(entity.Name, Is.EqualTo(command.Name)); Assert.That(entity.ItemsOrdered.Count, Is.EqualTo(1)); Assert.That(entity.ItemsProduced.Count, Is.EqualTo(1)); Assert.That(entity.ItemsOrdered.Of(Product1InteriorDoor).Amount, Is.EqualTo(amount)); Assert.That(entity.ItemsProduced.Of(Product1InteriorDoor).Amount, Is.Zero); Assert.That(entity.Customer, Is.EqualTo(CustomerDoorsBuyer)); Assert.That(entity.ParentOrder, Is.Null); Assert.That(entity.ShipmentDeadline, Is.EqualTo(command.ShipmentDeadline)); Assert.That(entity.ShippedAt, Is.Null); Assert.That(entity.Status, Is.EqualTo(OrderStatus.New)); Assert.That(entity.Type, Is.EqualTo(command.OrderType)); Assert.That(entity.Shop, Is.Null); Assert.That(entity.WorkStartedAt, Is.Null); Assert.That(entity.SubOrders, Is.Empty); Assert.That(CustomerDoorsBuyer.Orders.Contains(entity), Is.True); Assert.That(GetRecordedEvents <DomainEvent <Order> >().Count, Is.EqualTo(1)); //annul CustomerDoorsBuyer.Orders.Remove(entity); }
public void CreateOrder_FailFor_LackOfMaterials() { //arrange var command = new CreateOrder { CustomerId = CustomerDoorsBuyer.Id, Items = new List <(Guid, decimal)> { (Product1InteriorDoor.Id, 100) }, ShipmentDeadline = DateTimeOffset.Parse("2022-01-01"), InitiatorId = GlobalAdmin.Id }; var handler = new CreateOrderHandler(EntityRepository, InventoryService, EventTransmitter); //assert () => act var ex = Assert.ThrowsAsync <DomainException>(async() => await handler.HandleAsync(command)); Assert.That(ex.Message.StartsWith($"Required {100} {Product1InteriorDoor.UoM} of {Product1InteriorDoor}"), Is.True); Assert.That(GetRecordedEvents <DomainEvent <Order> >(), Is.Empty); }
public void CreateOrder_FailFor_LackOfTime() { //arrange var now = DateTimeOffset.Now; //ToDo:4 get rid of real time dependency var command = new CreateOrder() { Name = "New order", CustomerId = CustomerDoorsBuyer.Id, Items = new List <(Guid, decimal)> { (Product1InteriorDoor.Id, 5) }, ShipmentDeadline = now, InitiatorId = GlobalAdmin.Id }; var handler = new CreateOrderHandler(EntityRepository, InventoryService, EventTransmitter); //assert () => act var ex = Assert.ThrowsAsync <DomainException>(async() => await handler.HandleAsync(command)); Assert.That(ex.Message.StartsWith("Not enough time to fulfill the order"), Is.True); Assert.That(GetRecordedEvents <DomainEvent <Order> >(), Is.Empty); }