public async void DeleteProductOrderCommand_DeletesProductOrder() { // Arrange var createCustomer = _fixture.Build <CreateCustomerCommand>().Create(); var customerId = await new CreateCustomerCommandHandler(_petShopContext).Handle(createCustomer, CancellationToken.None); var createProduct = _fixture.Build <CreateProductCommand>().Create(); var productId = await new CreateProductCommandHandler(_petShopContext).Handle(createProduct, CancellationToken.None); var createProductOrderHandler = new CreateProductsOrderCommandHandler(_petShopContext); var newProductOrderId = await createProductOrderHandler.Handle(new CreateProductOrderCommand { Quantity = 3, CustomerId = customerId, ProductId = productId }, CancellationToken.None); // Act var mockHandler = new DeleteProductOrderCommandHandler(_petShopContext); var result = await mockHandler.Handle( new DeleteProductOrderCommand { Id = newProductOrderId }, CancellationToken.None); // Assert var listOfProductOrders = await new ListProductOrdersQueryHandler(_petShopContext).Handle(new ListProductOrdersQuery(), CancellationToken.None); Assert.True(result); Assert.Empty(listOfProductOrders); }
public async void ListProductOrdersQuery_ListsAllProductOrders() { const int numberOfProductOrdersToCreate = 5; // Arrange var createCustomer = _fixture.Build <CreateCustomerCommand>().Create(); var customerId = await new CreateCustomerCommandHandler(_petShopContext).Handle(createCustomer, CancellationToken.None); var createProduct = _fixture.Build <CreateProductCommand>().Create(); var productId = await new CreateProductCommandHandler(_petShopContext).Handle(createProduct, CancellationToken.None); var mockProductOrders = _fixture.Build <CreateProductOrderCommand>() .With(p => p.CustomerId, customerId) .With(p => p.ProductId, productId) .CreateMany(numberOfProductOrdersToCreate); var createProductOrderCommandHandler = new CreateProductsOrderCommandHandler(_petShopContext); foreach (var productOrder in mockProductOrders) { await createProductOrderCommandHandler.Handle(productOrder, CancellationToken.None); } // Act var mockHandler = new ListProductOrdersQueryHandler(_petShopContext); var handlerResult = await mockHandler.Handle(new ListProductOrdersQuery(), CancellationToken.None); // Assert Assert.Equal(numberOfProductOrdersToCreate, handlerResult.Count()); }
public async void CreateProductOrderCommand_NegativeQuantity_DoesNotCreateProductOrder() { // Arrange var createCustomer = _fixture.Build <CreateCustomerCommand>().Create(); var customerId = await new CreateCustomerCommandHandler(_petShopContext).Handle(createCustomer, CancellationToken.None); var createProduct = _fixture.Build <CreateProductCommand>().Create(); var productId = await new CreateProductCommandHandler(_petShopContext).Handle(createProduct, CancellationToken.None); var mockProductOrder = _fixture.Build <CreateProductOrderCommand>() .With(p => p.CustomerId, customerId) .With(p => p.ProductId, productId) .With(p => p.Quantity, -1) .Create(); // Act var mockHandler = new CreateProductsOrderCommandHandler(_petShopContext); var newProductOrderId = await mockHandler.Handle(mockProductOrder, CancellationToken.None); // Assert Assert.Equal(0, _petShopContext.ProductOrders.Count()); Assert.Equal(Guid.Empty, newProductOrderId); }