public void ShouldRequireMinimumFields() { var command = new DeliverOrderCommand(); FluentActions.Invoking(() => SendAsync(command)) .Should() .Throw <BaseValidationException>(); }
public void ShouldThrowOrderNotFoundException() { // Cancel Order Command var deliverOrderCommand = new DeliverOrderCommand { OrderId = Guid.NewGuid().ToString() }; FluentActions.Invoking(() => SendAsync(deliverOrderCommand)).Should().Throw <OrderNotFoundException>(); }
public async Task <IActionResult> DeliverOrder([FromBody] DeliverOrderCommand command) { var result = await Mediator.Send(command); return(Ok(new { result })); }
public async Task ShouldDeliverOrder() { // Arrange var accountId = await RunAsDefaultUserAsync(); var createCustomerCommand = new CreateCustomerCommand { AccountId = accountId, ShopName = "Test Shop Name", ShopAddress = "Test Shop address", LocationOnMap = "Test LocationOnMap" }; await SendAsync(createCustomerCommand); // Create product brand var brandCommand = new CreateBrandCommand { Name = "Test Brand" }; var brandId = await SendAsync(brandCommand); // Create product category var productCategoryCommand = new CreateProductCategoryCommand { Name = "Test Product Category" }; var productCategoryId = await SendAsync(productCategoryCommand); // Create product var createProductCommand = new CreateProductCommand { AvailableToSell = true, // created brand id BrandId = brandId, // created product category id ProductCategoryId = productCategoryId, Name = "Test Product", PhotoUrl = "Test Product", Barcode = "Test Product" }; var productId = await SendAsync(createProductCommand); // Add unit to product var addUnitToCommand = new AddUnitCommand { ProductId = productId, SellingPrice = 92, ContentCount = 2, Price = 33, Count = 6, IsAvailable = true, Name = "Test Unit", Weight = 44 }; var unitId = await SendAsync(addUnitToCommand); // AddItem To Shopping Van var addItemToVanCommand = new AddItemToVanCommand { ProductId = productId, UnitId = unitId }; await SendAsync(addItemToVanCommand); await SendAsync(addItemToVanCommand); // Place Order Command var placeOrderCommand = new PlaceOrderCommand(); var orderId = await SendAsync(placeOrderCommand); // Confirm Order Command var confirmOrderCommand = new ConfirmOrderCommand { OrderId = orderId }; await SendAsync(confirmOrderCommand); // Shipp Order Command var shippOrderCommand = new ShippOrderCommand { OrderId = orderId }; await SendAsync(shippOrderCommand); // Act // Deliver Order Command var deliverOrderCommand = new DeliverOrderCommand { OrderId = orderId }; await SendAsync(deliverOrderCommand); // Get Order By Id Query var orderByIdQuery = new OrderByIdQuery { OrderId = orderId }; var order = await SendAsync(orderByIdQuery); // Assert order.Should().NotBeNull(); order.OrderStatus.Should().Be(OrderStatus.Delivered); }
public async Task ShouldThrowOrderNotShippedException() { // Arrange var accountId = await RunAsDefaultUserAsync(); var createCustomerCommand = new CreateCustomerCommand { AccountId = accountId, ShopName = "Test Shop Name", ShopAddress = "Test Shop address", LocationOnMap = "Test LocationOnMap" }; await SendAsync(createCustomerCommand); // Create product brand var brandCommand = new CreateBrandCommand { Name = "Test Brand" }; var brandId = await SendAsync(brandCommand); // Create product category var productCategoryCommand = new CreateProductCategoryCommand { Name = "Test Product Category" }; var productCategoryId = await SendAsync(productCategoryCommand); // Create product var createProductCommand = new CreateProductCommand { AvailableToSell = true, // created brand id BrandId = brandId, // created product category id ProductCategoryId = productCategoryId, Name = "Test Product", PhotoUrl = "Test Product", Barcode = "Test Product" }; var productId = await SendAsync(createProductCommand); // Add unit to product var addUnitToCommand = new AddUnitCommand { ProductId = productId, SellingPrice = 92, ContentCount = 2, Price = 33, Count = 6, IsAvailable = true, Name = "Test Unit", Weight = 44 }; var unitId = await SendAsync(addUnitToCommand); // AddItem To Shopping Van var addItemToVanCommand = new AddItemToVanCommand { ProductId = productId, UnitId = unitId }; await SendAsync(addItemToVanCommand); await SendAsync(addItemToVanCommand); // Place Order Command var placeOrderCommand = new PlaceOrderCommand(); var orderId = await SendAsync(placeOrderCommand); // Act var cancelOrderCommand = new CancelOrderCommand { OrderId = orderId }; await SendAsync(cancelOrderCommand); var deliverOrderCommand = new DeliverOrderCommand { OrderId = orderId }; // Assert // Shipp Order Command FluentActions.Invoking(() => SendAsync(deliverOrderCommand)).Should().Throw <OrderNotShippedException>(); }