public async Task Handle() { // arrange CommandResult result = CommandResult.Ok; var command = new CreateOrderCommand(Guid.NewGuid(), "TestUser", "Beijing", "100001", new List <OrderItemDTO> { new OrderItemDTO(1, "IPhone", 8888, 1) }); using (OrderDbContext context = DbHelper.GetInMemory()) { CreateOrderCommand.Handler handler = GetHandler(context); // act result = await handler.Handle(command); } // assert Assert.True(result.Succeed); using (OrderDbContext context = DbHelper.GetInMemory()) { Assert.Equal(1, context.Orders.Count()); Order createdOrder = context.Orders.Single(); Assert.Equal(command.UserId, createdOrder.UserId); } }
public async Task ShouldHoldStock() { // arrange CreateOrderCommand command = CreateCommand(); _stockServiceMock .Setup(m => m.HoldStock(It.IsAny <Order>())) .Verifiable(); using (OrderDbContext context = DbHelper.GetInMemory()) { CreateOrderCommand.Handler handler = GetHandler(context); // act await handler.Handle(command); } // assert _stockServiceMock.Verify(); }