Order CreateNewOrder(OrderDTO dto, Customer associatedCustomer) { //Create a new order entity from factory Order newOrder = OrderFactory.CreateOrder(associatedCustomer, dto.ShippingName, dto.ShippingCity, dto.ShippingAddress, dto.ShippingZipCode); //set the poid newOrder.Id = IdentityGenerator.NewSequentialGuid(); //if have lines..add if (dto.OrderLines != null) { foreach (var line in dto.OrderLines) { var orderLine = newOrder.CreateOrderLine(line.ProductId, line.Amount, line.UnitPrice, line.Discount); newOrder.AddOrderLine(orderLine); } } return newOrder; }
/// <summary> /// <see cref="Microsoft.Samples.NLayerApp.Application.MainBoundedContext.ERPModule.Services.ISalesAppService"/> /// </summary> /// <param name="orderDto"><see cref="Microsoft.Samples.NLayerApp.Application.MainBoundedContext.ERPModule.Services.ISalesAppService"/></param> public OrderDTO AddNewOrder(OrderDTO orderDto) { //if orderdto data is not valid if (orderDto == null || orderDto.CustomerId== Guid.Empty) { LoggerFactory.CreateLog().LogWarning(Messages.warning_CannotAddOrderWithNullInformation); return null; } var customer = _customerRepository.Get(orderDto.CustomerId); if (customer == null)//if customer is null cannot create a new order { LoggerFactory.CreateLog().LogWarning(Messages.warning_CannotCreateOrderForNonExistingCustomer); return null; } //Create a new order entity var newOrder = CreateNewOrder(orderDto,customer); if (newOrder.IsCreditValidForOrder()) //if total order is less than credit { //save order SaveOrder(newOrder); return _typeAdapter.Adapt<Order, OrderDTO>(newOrder); } else //total order is greater than credit { LoggerFactory.CreateLog().LogInfo(Messages.info_OrderTotalIsGreaterCustomerCredit); return null; } }
public void AddNewValidOrderReturnAddedOrder() { //Arrange var adapter = PrepareTypeAdapter(); var productRepository = new SIProductRepository(); var orderRepository = new SIOrderRepository(); var customerRepository = new SICustomerRepository(); customerRepository.GetGuid = (guid) => { //default credit limit is 1000 var customer = CustomerFactory.CreateCustomer("Jhon", "El rojo", Guid.NewGuid(), new Address("city", "zipCode", "addressline1", "addressline2")); customer.Id = IdentityGenerator.NewSequentialGuid(); return customer; }; orderRepository.UnitOfWorkGet = () => { var uow = new SIUnitOfWork(); uow.Commit = () => { }; return uow; }; orderRepository.AddOrder = (order) => { }; var salesManagement = new SalesAppService(adapter, productRepository, orderRepository,customerRepository); var dto = new OrderDTO() { CustomerId = Guid.NewGuid(), ShippingAddress = "Address", ShippingCity = "city", ShippingName = "name", ShippingZipCode = "zipcode", OrderLines = new List<OrderLineDTO>() { new OrderLineDTO(){ProductId = Guid.NewGuid(),Amount = 1,Discount = 0,UnitPrice = 20} } }; //act var result = salesManagement.AddNewOrder(dto); //assert Assert.IsNotNull(result); Assert.IsTrue(result.Id != Guid.Empty); Assert.AreEqual(result.ShippingAddress, dto.ShippingAddress); Assert.AreEqual(result.ShippingCity, dto.ShippingCity); Assert.AreEqual(result.ShippingName, dto.ShippingName); Assert.AreEqual(result.ShippingZipCode, dto.ShippingZipCode); Assert.IsTrue(result.OrderLines.Count == 1); Assert.IsTrue(result.OrderLines.All(ol=>ol.Id != Guid.Empty)); }
/// <summary> /// <see cref="Microsoft.Samples.NLayerApp.Application.MainBoundedContext.BankingModule.Services.IMainBoundedContextService"/> /// </summary> /// <param name="order"><see cref="Microsoft.Samples.NLayerApp.Application.MainBoundedContext.BankingModule.Services.IMainBoundedContextService"/></param> /// <returns><see cref="Microsoft.Samples.NLayerApp.Application.MainBoundedContext.BankingModule.Services.IMainBoundedContextService"/></returns> public OrderDTO AddNewOrder(OrderDTO order) { return _salesAppService.AddNewOrder(order); }
public void AddNewOrderWithNotValidDataReturnNull() { //Arrange var adapter = PrepareTypeAdapter(); var customerRepository = new SICustomerRepository(); var productRepository = new SIProductRepository(); var orderRepository = new SIOrderRepository(); var salesManagement = new SalesAppService(adapter, productRepository, orderRepository,customerRepository); var order = new OrderDTO() // order is not valid when customer id is empty { CustomerId = Guid.Empty }; //act var result = salesManagement.AddNewOrder(order); //assert Assert.IsNull(result); }