public void OrderToOrderDtoAdapter() { //Arrange var customer = new Customer(); customer.GenerateNewIdentity(); customer.FirstName = "Unai"; customer.LastName = "Zorrilla"; Product product = new Software("the product title", "the product description", "license code"); product.GenerateNewIdentity(); var order = new Order(); order.GenerateNewIdentity(); order.OrderDate = DateTime.Now; order.ShippingInformation = new ShippingInfo( "shippingName", "shippingAddress", "shippingCity", "shippingZipCode"); order.SetTheCustomerForThisOrder(customer); var orderLine = order.AddNewOrderLine(product.Id, 10, 10, 0.5M); orderLine.SetProduct(product); //Act var adapter = TypeAdapterFactory.CreateAdapter(); var orderDto = adapter.Adapt<Order, OrderDto>(order); //Assert Assert.AreEqual(orderDto.Id, order.Id); Assert.AreEqual(orderDto.OrderDate, order.OrderDate); Assert.AreEqual(orderDto.DeliveryDate, order.DeliveryDate); Assert.AreEqual(orderDto.ShippingAddress, order.ShippingInformation.ShippingAddress); Assert.AreEqual(orderDto.ShippingCity, order.ShippingInformation.ShippingCity); Assert.AreEqual(orderDto.ShippingName, order.ShippingInformation.ShippingName); Assert.AreEqual(orderDto.ShippingZipCode, order.ShippingInformation.ShippingZipCode); Assert.AreEqual(orderDto.CustomerFullName, order.Customer.FullName); Assert.AreEqual(orderDto.CustomerId, order.Customer.Id); Assert.AreEqual( orderDto.OrderNumber, string.Format("{0}/{1}-{2}", order.OrderDate.Year, order.OrderDate.Month, order.SequenceNumberOrder)); Assert.IsNotNull(orderDto.OrderLines); Assert.IsTrue(orderDto.OrderLines.Any()); Assert.AreEqual(orderDto.OrderLines[0].Id, orderLine.Id); Assert.AreEqual(orderDto.OrderLines[0].Amount, orderLine.Amount); Assert.AreEqual(orderDto.OrderLines[0].Discount, orderLine.Discount * 100); Assert.AreEqual(orderDto.OrderLines[0].UnitPrice, orderLine.UnitPrice); Assert.AreEqual(orderDto.OrderLines[0].TotalLine, orderLine.TotalLine); Assert.AreEqual(orderDto.OrderLines[0].ProductId, product.Id); Assert.AreEqual(orderDto.OrderLines[0].ProductTitle, product.Title); }
public void SoftwareToSoftwareDTOAdapter() { //Arrange var software = new Software("the title", "The description","AB001"); software.ChangeUnitPrice(10); software.IncrementStock(10); software.GenerateNewIdentity(); //Act ITypeAdapter adapter = TypeAdapterFactory.CreateAdapter(); var softwareDTO = adapter.Adapt<Software, SoftwareDTO>(software); //Assert Assert.AreEqual(software.Id, softwareDTO.Id); Assert.AreEqual(software.Title, softwareDTO.Title); Assert.AreEqual(software.Description, softwareDTO.Description); Assert.AreEqual(software.AmountInStock, softwareDTO.AmountInStock); Assert.AreEqual(software.UnitPrice, softwareDTO.UnitPrice); Assert.AreEqual(software.LicenseCode, softwareDTO.LicenseCode); }
public void ProductToProductDTOAdapter() { //Arrange var product = new Software("the title", "The description","AB001"); product.ChangeUnitPrice(10); product.IncrementStock(10); product.GenerateNewIdentity(); //Act ITypeAdapter adapter = TypeAdapterFactory.CreateAdapter(); var productDTO = adapter.Adapt<Product, ProductDTO>(product); //Assert Assert.AreEqual(product.Id, productDTO.Id); Assert.AreEqual(product.Title, productDTO.Title); Assert.AreEqual(product.Description, productDTO.Description); Assert.AreEqual(product.AmountInStock, productDTO.AmountInStock); Assert.AreEqual(product.UnitPrice, productDTO.UnitPrice); }
public void EnumerableProductToListProductDTOAdapter() { //Arrange var software = new Software("the title", "The description","AB001"); software.ChangeUnitPrice(10); software.IncrementStock(10); software.GenerateNewIdentity(); var products = new List<Software>() { software }; //Act ITypeAdapter adapter = TypeAdapterFactory.CreateAdapter(); var productsDTO = adapter.Adapt<IEnumerable<Product>, List<ProductDTO>>(products); //Assert Assert.AreEqual(products[0].Id, productsDTO[0].Id); Assert.AreEqual(products[0].Title, productsDTO[0].Title); Assert.AreEqual(products[0].Description, productsDTO[0].Description); Assert.AreEqual(products[0].AmountInStock, productsDTO[0].AmountInStock); Assert.AreEqual(products[0].UnitPrice, productsDTO[0].UnitPrice); }
/// <summary> /// <see cref="Microsoft.Samples.NLayerApp.Application.MainBoundedContext.ERPModule.Services.ISalesAppService"/> /// </summary> /// <param name="softwareDTO"><see cref="Microsoft.Samples.NLayerApp.Application.MainBoundedContext.ERPModule.Services.ISalesAppService"/></param> public SoftwareDTO AddNewSoftware(SoftwareDTO softwareDTO) { if (softwareDTO == null) throw new ArgumentException(Messages.warning_CannotAddSoftwareWithNullInformation); //Create the softare entity var newSoftware = new Software(softwareDTO.Title, softwareDTO.Description,softwareDTO.LicenseCode); //set unit price and stock newSoftware.ChangeUnitPrice(softwareDTO.UnitPrice); newSoftware.IncrementStock(softwareDTO.AmountInStock); //Assign the poid newSoftware.GenerateNewIdentity(); //save software SaveProduct(newSoftware); //return software dto return newSoftware.ProjectedAs<SoftwareDTO>(); }
public void EnumerableOrderToOrderListDtoAdapter() { //Arrange var customer = new Customer(); customer.GenerateNewIdentity(); customer.FirstName = "Unai"; customer.LastName = "Zorrilla"; Product product = new Software("the product title", "the product description", "license code"); product.GenerateNewIdentity(); var order = new Order(); order.GenerateNewIdentity(); order.OrderDate = DateTime.Now; order.ShippingInformation = new ShippingInfo( "shippingName", "shippingAddress", "shippingCity", "shippingZipCode"); order.SetTheCustomerForThisOrder(customer); var line = order.AddNewOrderLine(product.Id, 1, 200, 0); var orders = new List<Order>() { order }; //Act var adapter = TypeAdapterFactory.CreateAdapter(); var orderListDto = adapter.Adapt<IEnumerable<Order>, List<OrderListDto>>(orders); //Assert Assert.AreEqual(orderListDto[0].Id, order.Id); Assert.AreEqual(orderListDto[0].OrderDate, order.OrderDate); Assert.AreEqual(orderListDto[0].DeliveryDate, order.DeliveryDate); Assert.AreEqual(orderListDto[0].TotalOrder, order.GetOrderTotal()); Assert.AreEqual(orderListDto[0].ShippingAddress, order.ShippingInformation.ShippingAddress); Assert.AreEqual(orderListDto[0].ShippingCity, order.ShippingInformation.ShippingCity); Assert.AreEqual(orderListDto[0].ShippingName, order.ShippingInformation.ShippingName); Assert.AreEqual(orderListDto[0].ShippingZipCode, order.ShippingInformation.ShippingZipCode); Assert.AreEqual(orderListDto[0].CustomerFullName, order.Customer.FullName); Assert.AreEqual(orderListDto[0].CustomerId, order.Customer.Id); }
public void FindProductsByFilterMaterializeResults() { //Arrange var customerRepository = new StubICustomerRepository(); var productRepository = new StubIProductRepository(); var orderRepository = new StubIOrderRepository(); productRepository.AllMatchingISpecificationOfProduct = (spec) => { var book = new Book("title", "description", "publisher", "isbn"); book.ChangeUnitPrice(10); book.GenerateNewIdentity(); var software = new Software("title", "description", "license code"); software.ChangeUnitPrice(10); software.GenerateNewIdentity(); return new List<Product>() { book, software }; }; var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository); //act var result = salesManagement.FindProducts("filter text"); //Assert Assert.IsNotNull(result); Assert.IsTrue(result.Count == 2); }
public void FindProductsInPageMaterializeResults() { //Arrange var customerRepository = new StubICustomerRepository(); var productRepository = new StubIProductRepository(); var orderRepository = new StubIOrderRepository(); //productRepository.GetPagedInt32Int32ExpressionOfFuncOfProductKPropertyBoolean<string>( // (index, count, order, ascending) => // { // var book = new Book("title", "description", "publisher", "isbn"); // book.ChangeUnitPrice(10M); // book.GenerateNewIdentity(); // var software = new Software("title", "description", "license code"); // software.ChangeUnitPrice(10); // software.GenerateNewIdentity(); // return new List<Product>() // { // book, // software // }; // }); productRepository.GetPagedOf1Int32Int32ExpressionOfFuncOfProductM0Boolean<string>( (index, count, order, ascending) => { var book = new Book("title", "description", "publisher", "isbn"); book.ChangeUnitPrice(10M); book.GenerateNewIdentity(); var software = new Software("title", "description", "license code"); software.ChangeUnitPrice(10); software.GenerateNewIdentity(); return new List<Product> { book, software }; }); var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository); //act var result = salesManagement.FindProducts(0, 2); //Assert Assert.IsNotNull(result); Assert.IsTrue(result.Count == 2); }