public async Task <IActionResult> AddItemToVan([FromBody] AddItemToVanCommand command) { var uid = _currentUserService.UserId; var result = await Mediator.Send(command); return(Ok(result)); }
public void ShouldRequireMinimumFields() { var command = new AddItemToVanCommand(); FluentActions.Invoking(() => SendAsync(command)) .Should() .Throw <BaseValidationException>(); }
public void ShouldThrowProductNotFoundException() { // AddItem To Shopping Van var command = new AddItemToVanCommand { ProductId = Guid.NewGuid().ToString(), UnitId = Guid.NewGuid().ToString() }; // Act FluentActions.Invoking(() => SendAsync(command)).Should().Throw <ProductNotFoundException>(); }
public async Task ShouldThrowUnitNotFoundExceptionAsync() { // Arrange await RunAsDefaultUserAsync(); // 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); // AddItem To Shopping Van var command = new AddItemToVanCommand { ProductId = productId, UnitId = Guid.NewGuid().ToString() }; // Act FluentActions.Invoking(() => SendAsync(command)).Should().Throw <UnitNotFoundException>(); }
public async Task ShouldListAllOrders() { // 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(); await SendAsync(placeOrderCommand); // Act // Get Order By Id Query var listOrdersQuery = new ListOrdersQuery { OrderStatuses = new List <OrderStatus> { OrderStatus.Placed } }; var listOrders = await SendAsync(listOrdersQuery); // Assert listOrders.Data.Should().NotBeNull(); listOrders.Data.Count.Should().Be(1); }
public async Task ShouldThrowCancelConfirmedOrderException() { // 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 confirmOrderCommand = new ConfirmOrderCommand { OrderId = orderId }; await SendAsync(confirmOrderCommand); var cancelOrderCommand = new CancelOrderCommand { OrderId = orderId }; // Assert // Cancel Order Command FluentActions.Invoking(() => SendAsync(cancelOrderCommand)).Should().Throw <CancelConfirmedOrderException>(); }
public async Task ShouldGetCurrentCustomerVan() { // Arrange var currentCustomerId = await RunAsDefaultUserAsync(); // 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 command = new AddItemToVanCommand { ProductId = productId, UnitId = unitId }; await SendAsync(command); // Act var getCurrentCustomerVanQuery = new CurrentCustomerVanQuery(); var currentCustomerVan = await SendAsync(getCurrentCustomerVanQuery); // Assert currentCustomerVan.TotalItemsCount.Should().Be(1); currentCustomerVan.TotalPrice.Should().Be(addUnitToCommand.SellingPrice + (addUnitToCommand.SellingPrice * 0.14f)); currentCustomerVan.CustomerId.Should().Be(currentCustomerId); }
public async Task ShouldAddItemToVan() { // Arrange await RunAsDefaultUserAsync(); // 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 command = new AddItemToVanCommand { ProductId = productId, UnitId = unitId }; // Act await SendAsync(command); var shoppingVanItemCount = await SendAsync(command); // Assert shoppingVanItemCount.Should().Be(2); }
public async Task ShouldUpdateOrder() { // 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 first unit to product var addFirstUnitCommand = new AddUnitCommand { ProductId = productId, SellingPrice = 92, ContentCount = 2, Price = 33, Count = 6, IsAvailable = true, Name = "Test First Unit", Weight = 44 }; var firstUnitId = await SendAsync(addFirstUnitCommand); // Add first unit to product var addSecondUnitCommand = new AddUnitCommand { ProductId = productId, SellingPrice = 342, ContentCount = 24, Price = 323, Count = 64, IsAvailable = true, Name = "Test Second Unit", Weight = 94 }; var secondUnitId = await SendAsync(addSecondUnitCommand); // AddItem To Shopping Van var addItemToVanCommand = new AddItemToVanCommand { ProductId = productId, UnitId = firstUnitId }; await SendAsync(addItemToVanCommand); await SendAsync(addItemToVanCommand); // Place Order Command var placeOrderCommand = new PlaceOrderCommand(); var orderId = await SendAsync(placeOrderCommand); // Get Order By Id Query var orderByIdQuery = new OrderByIdQuery { OrderId = orderId }; var order = await SendAsync(orderByIdQuery); // Act var updateOrderCommand = new UpdateOrderCommand { OrderId = orderId, OrderItemId = order.OrderItems.FirstOrDefault(x => x.UnitId == firstUnitId).Id, UnitId = secondUnitId, UnitCount = 10, UnitName = addSecondUnitCommand.Name }; await SendAsync(updateOrderCommand); // Get Order By Id Query var orderAfterUpdate = await SendAsync(orderByIdQuery); // Assert order.Should().NotBeNull(); order.OrderItems.Count.Should().Be(1); order.OrderItems.FirstOrDefault(x => x.UnitId == firstUnitId).UnitName.Should().Be(addFirstUnitCommand.Name); orderAfterUpdate.OrderItems.FirstOrDefault(x => x.UnitId == secondUnitId).UnitName.Should().Be(addSecondUnitCommand.Name); }
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); }