public void CreateNewOrderMapsDataRecorderCreatorIdToDataRecorderMetaData() { const int expectedDataRecorderCreatorId = 3; Expect.Call(_dataRecorderMetaDataFactory. CreateDataRecorderMetaData(expectedDataRecorderCreatorId)).Return(null); _mocks.ReplayAll(); _orderFactory.CreateNewOrder(OrderType.Retail, expectedDataRecorderCreatorId); _mocks.VerifyAll(); }
public void PlaceOrderSavesTwoEntitiesWhenOneItemOrdered() { const int quantity = 1; const int forOrganizationRoleUserId = 3; const int dataRecorderCreatorId = 4; const OrderType typeOfOrderToPlace = OrderType.Retail; var fakeOrderable = new FakeOrderable(); Expect.Call(_orderFactory.CreateNewOrder(typeOfOrderToPlace, dataRecorderCreatorId)). Return(new Order { OrderDetails = new List <OrderDetail>() }); Expect.Call(_orderDetailFactory.CreateNewOrderDetail(fakeOrderable, quantity, forOrganizationRoleUserId, dataRecorderCreatorId, null, null, null)). Return(new OrderDetail()); Expect.Call(_orderItemStatusFactory.CreateOrderItemStatus(0, 0)).IgnoreArguments(). Return(FakeOrderItemStatus.IncompleteFakeStatus); // Expecting persistence of two entities. Expect.Call(_orderRepository.SaveOrder(null)).IgnoreArguments(). Return(new Order()); Expect.Call(_orderItemRepository.SaveOrderItem(fakeOrderable.Id, fakeOrderable.OrderItemType)) .Return(new FakeOrderItem()); _mocks.ReplayAll(); _orderController.AddItem(fakeOrderable, quantity, forOrganizationRoleUserId, dataRecorderCreatorId); _orderController.PlaceOrder(typeOfOrderToPlace, dataRecorderCreatorId); _mocks.VerifyAll(); }
private async Task <Order> GetOrderAsync(CreateOrderRequest request) { var customerId = new CustomerIdentity(request.CustomerId); var customer = await _customerReadRepository.FindAsync(customerId); if (customer == null) { throw new InvalidRequestException($"Customer {request.CustomerId} does not exist"); } var orderDetails = new List <OrderItem>(); for (int i = 0; i < request.OrderItems.Count; i++) { var requestOrderDetail = request.OrderItems[i]; try { var orderDetail = await GetOrderItem(requestOrderDetail); orderDetails.Add(orderDetail); } catch (InvalidRequestException ex) { var position = i + 1; throw new InvalidRequestException($"Order detail at position {position} is invalid", ex); } } return(_orderFactory.CreateNewOrder(customerId, orderDetails)); }
protected async Task <List <Order> > CreateSomeOrdersAsync(List <Customer> customers, List <Product> products) { var customerId = customers[1].Id; var productId1 = products[1].Id; var productId2 = products[2].Id; var orders = new List <Order>(); for (var i = 0; i < 10; i++) { var orderItem1 = _orderFactory.CreateNewOrderItem(productId1, 56.92m, 40); var orderItem2 = _orderFactory.CreateNewOrderItem(productId2, 72.46m, 50); var orderItems = new List <OrderItem> { orderItem1, orderItem2, }; var order = _orderFactory.CreateNewOrder(customerId, orderItems); await _orderRepository.AddAsync(order); } return(orders); }
public Core.Finance.Domain.Order PlaceOrder(OrderType typeOfOrderToPlace, long dataRecorderCreatorId) { if (!_lineItems.Any()) { throw new InvalidOperationException("The order must contain at least one line item."); } Core.Finance.Domain.Order order; using (var transaction = new TransactionScope()) { order = _orderFactory.CreateNewOrder(typeOfOrderToPlace, dataRecorderCreatorId); foreach (var lineItem in _lineItems) { OrderItem orderItem = _orderItemRepository.SaveOrderItem(lineItem.SecondValue.Id, lineItem.SecondValue.OrderItemType); lineItem.FirstValue.OrderItemId = orderItem.Id; lineItem.FirstValue.OrderId = order.Id; order.OrderDetails.Add(lineItem.FirstValue); } order = _orderRepository.SaveOrder(order); transaction.Complete(); } _lineItems.Clear(); return(order); }