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 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); }