public async Task <IActionResult> GetOrder(int orderId) { var command = new OrderByIdQuery(orderId); var result = await _mediator.Send(command); return(Ok(result)); }
public Order Select(OrderByIdQuery query) { return(termeDbContext.Orders. Where(c => c.Id == query.OrderId). Include(c => c.OrderLines). ThenInclude(c => c.MasterProduct). Include(c => c.Customer).FirstOrDefault()); }
public async Task <IActionResult> Get(long id) { var query = new OrderByIdQuery(id); var result = await DispatchAsync(query); return(result != null?Ok(result) : NotFound($"OrderId doesn't exist: {id}")); }
public async Task Consume(ConsumeContext <OrderCheckStatus> context) { var commandQuery = new OrderByIdQuery(context.Message.OrderId); var model = await _mediator.Send(commandQuery); var order = model.ToOrder(); if (order == null) { throw new InvalidOperationException("Order not found"); } await context.RespondAsync <OrderCheckStatusResult>(new { OrderId = order.Id, order.Name }); }
public async Task ShouldCancelOrder() { // 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 // Cancel Order Command var cancelOrderCommand = new CancelOrderCommand { OrderId = orderId }; await SendAsync(cancelOrderCommand); // 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.Cancelled); }
public async Task <IActionResult> GetById(OrderByIdQuery query) { var result = await Mediator.Send(query); return(Ok(result)); }
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); }