public async Task <NewOrderResponse> CreateOrder(NewOrderRequest request) { var customer = await _unitOfWork.CustomerRepository.FindAsync(request.CustomerId); var order = Order.Create(customer, request.Now); foreach (var orderProductRequest in request.Products) { var product = await _unitOfWork.ProductRepository.FindAsync(orderProductRequest.ProductId); var orderProduct = OrderProduct.Create(product, request.Now); orderProduct.IncreaseAmount(orderProductRequest.Amount); order.AddProduct(orderProduct); } try { _unitOfWork.OrderRepository.Attach(order); await _unitOfWork.SaveChangesAsync(); _eventDistpacher.Distpach(order); _response.Success = true; } catch (Exception e) { Console.WriteLine(e); _response.MessageError = e.Message; } return(_response); }
public void ShouldReturnOrderProduct() { var ordProduct = OrderProduct.Create(_tankId, _quantity); Assert.NotNull(ordProduct); Assert.Equal(_tankId, ordProduct.TankId); Assert.Equal(_quantity, ordProduct.Quantity); }