public async Task <IActionResult> ProcessPurchaseOrder([FromBody] ProcessPurchaseOrderRequest request) { //we need to maintain a separation between the domain model and the api contract //this way we can avoid introducing breaking changes to the consumers of the api //and can enhance our domain model over time to be richer, //also the api contract will probably have dependencies on third party or technology specific //libraries as we start to add validation attributes or other metadata and this third party //dependencies should not be introduced into the domain model. //this is why we are mapping from a api contract to a domain model here var purchaseOrder = new PurchaseOrder { Id = request.Id, CustomerId = request.CustomerId, Total = request.Total, OrderItems = request.OrderItems.Select(orderItem => new OrderItem { Id = orderItem.Id, Name = orderItem.Name, OrderItemType = (OrderItemType)orderItem.OrderItemType }).ToList() }; await _purchaseOrdersService.ProcessPurchaseOrderAsync(purchaseOrder); return(Ok()); }
public async Task ProcessPurchaseOrder_WhenMembershipPurchaseIncluded_MustCreateCustomerAccountMembership() { //Arrange var request = new ProcessPurchaseOrderRequest { Id = 1, OrderItems = new List <OrderItem> { new OrderItem { Id = 1, OrderItemType = OrderItemType.Membership } } }; var content = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json"); //Act var responseMessage = await _apiFacade.HttpClient.PostAsync("purchase-orders/process", content); //Assert responseMessage.StatusCode.Should().Be(HttpStatusCode.OK); _apiFacade.CustomerAccountPurchaseOrders.Count.Should().Be(1); _apiFacade.CustomerAccountPurchaseOrders.Single().Should().BeEquivalentTo(request); _apiFacade.ShippingSlippedPurchaseOrders.Count.Should().Be(0); }