public ProductBO Create(ProductBO product) { using (var uow = facade.UnitOfWork) { newProduct = uow.ProductRepository.Create(prodConv.Convert(product)); uow.Complete(); return prodConv.Convert(newProduct); } }
public void EnttoProductBO() { Product prod = new Product { Id = 2, Name = "Milk" }; ProductBO PB = pc.Convert(prod); Assert.Equal(prod.Id, PB.Id); Assert.Equal(prod.Name, PB.Name); Assert.NotNull(PB); }
public async Task <Guid> AddProductAsync(AddProductDto productDtos) { //Automapper var product = ProductConverter.Convert(productDtos); return(await _productRepository.AddProductAsync(product)); }
public void GetResult_ShouldReturnProduct_WithSameTagAssociations_AsProductEntity_WhenUsedAfter_BuildTags() { /* ARRANGE */ ProductEntity basicProps = new ProductEntity { Id = 100, Name = "Name", Price = 10.00M, Sku = "Sku" }; int[] expectedTagIds = { 111, 222, 333 }; SetBasicPropertiesInMockProductEntity(basicProps); SetProductTagsInMockProductEntity(expectedTagIds); SetupMockDomainFactoryToReturnProduct(); SetupMockRepositoryFactoryToReturnTags(); /* ACT */ ProductConverter builder = CreateProductBuilderWithMocks(); //builder.BuildTags(); IProduct product = builder.Convert(mockProductEntity.Object, (a, b) => { }); /* ASSERT */ for (int i = 0; i < expectedTagIds.Length; i++) { int actual = product.Tags[i].Id; Assert.AreEqual(expectedTagIds[i], actual); } }
public async Task <bool> Update(ProductDto item) { _context.Products.Update(ProductConverter.Convert(item)); await _context.SaveChangesAsync(); return(true); }
public async Task <IEnumerable <ProductDTO> > GetListByFilters(Params param = null) { var dtos = await GetProductList(); if (param != null) { if (param.BrandId != null) { dtos = dtos.Where(x => x.BrandId == param.BrandId); } if (param.CategoryId != null) { dtos = dtos.Where(x => x.CategoryId == param.CategoryId); } if (param.PriceFrom != null) { dtos = dtos.Where(x => x.Price >= param.PriceFrom); } if (param.PriceTo != null) { dtos = dtos.Where(x => x.Price <= param.PriceTo); } } return(ProductConverter.Convert(dtos)); }
public async Task <List <ProductViewModel> > GetAllProductsAsync(CancellationToken ct = default) { // retrieve all products that are available List <Product> products = await this._productRepository.GetAllAsync(ct); List <ProductViewModel> productsView = new List <ProductViewModel>(); // check if item has any sales foreach (Product product in products) { ProductViewModel productView = ProductConverter.Convert(product); if (product.IsOnSale == true) { List <SaleItem> sales = await this._saleItemRepository.GetByProductId(product.Id); List <SaleItemViewModel> saleViews = new List <SaleItemViewModel>(); foreach (SaleItem sale in sales) { // if sale is valid if (sale.ExpireDate > DateTime.Now) { SaleItemViewModel saleView = SaleItemConverter.Convert(sale); saleViews.Add(saleView); } } productView.Sales = saleViews; } productsView.Add(productView); } return(productsView); }
public async Task <IEnumerable <ProductDto> > GetProductsAsync(int top) { var products = await _productRepository.GetProductsAsync(top); var currentCulture = _applicationContext.CurrentCulture; return(products.Select(product => ProductConverter.Convert(product, currentCulture))); }
public void ProductBuilder_ShouldHaveEmpty_Tags_List_WhenCreated() { int expected = 0; ProductConverter builder = CreateProductBuilderWithMocks(); int actual = builder.Convert(mockProductEntity.Object, (a, b) => { }).Tags.Count; Assert.AreEqual(expected, actual); }
public async Task <ProductDto> GetProductAsync(Guid id) { var currentCulture = _applicationContext.CurrentCulture; var product = await _productRepository.GetProductAsync(id); //Autompper; return(ProductConverter.Convert(product, currentCulture)); }
public async Task <Guid> AddProductAsync(AddProductInfoDto productDto) { var currentCulture = _applicationContext.CurrentCulture; // Automapper var product = ProductConverter.Convert(productDto, currentCulture); return(await _productRepository.AddProductAsync(product)); }
public async Task <Guid> AddProductAsync(Product product) { var dbProduct = ProductConverter.Convert(product); _dbContext.Products.Add(dbProduct); await _dbContext.SaveChangesAsync(); return(dbProduct.Id); }
public async Task <ProductDTO> Get(long id) { var product = await GetProductEntity(id); if (product == null) { return(null); } return(ProductConverter.Convert(product)); }
public void ProductBuilder_ShouldHaveSame_Price_AsEntity_WhenCreated() { Decimal expected = 12.50M; mockProductEntity.Setup(pe => pe.Price).Returns(expected); ProductConverter builder = CreateProductBuilderWithMocks(); Decimal actual = builder.Convert(mockProductEntity.Object, (a, b) => { }).Price; Assert.AreEqual(expected, actual); }
public void ProductBuilder_ShouldHaveSame_Sku_AsEntity_WhenCreated() { string expected = "Sku123"; mockProductEntity.Setup(pe => pe.Sku).Returns(expected); ProductConverter builder = CreateProductBuilderWithMocks(); string actual = builder.Convert(mockProductEntity.Object, (a, b) => { }).Sku; Assert.AreEqual(expected, actual); }
public void ProductBuilder_ShouldHaveSame_Id_AsEntity_WhenCreated() { int expected = 123; mockProductEntity.Setup(pe => pe.Id).Returns(expected); ProductConverter builder = CreateProductBuilderWithMocks(); int actual = builder.Convert(mockProductEntity.Object, (a, b) => { }).Id; Assert.AreEqual(expected, actual); }
public async Task <List <ProductDTO> > GetProducts() { var products = await GetProductList(); if (products == null) { return(null); } return(ProductConverter.Convert(products)); }
public async Task <ProductDTO> Add(CreateProductDTO productDTO) { if (productDTO == null) { return(null); } var p = ProductConverter.Convert(productDTO); var product = await unitOfWork.Repository <Product>().Add(p); return(ProductConverter.Convert(product)); }
public async Task <ProductDTO> Get(long id) { var product = await unitOfWork.ProductRepository.GetFull(id); //if (product.Category == null) product.Category = await unitOfWork.Repository<Category>().Get(product.CategoryId); if (product == null) { return(null); } return(ProductConverter.Convert(product)); }
public async Task <List <ProductDTO> > GetProducts() { var dtos = await unitOfWork.ProductRepository.GetFullList(); //foreach(var d in dtos) //{ // if (d.Category == null) d.Category = await unitOfWork.Repository<Category>().Get(d.CategoryId); //} return(ProductConverter.Convert(dtos)); }
public async Task <IEnumerable <ProductDTO> > GetListBySearchQuery(string searchQuery) { var entity = await unitOfWork.Repository <Product>().GetQueryable() .Where(x => x.Title.Contains(searchQuery)) .Where(x => x.IsDeleted != true) .ToListAsync(); if (entity == null) { return(null); } return(ProductConverter.Convert(entity)); }
public async Task <ProductDTO> Update(UpdateProductDTO updateDto) { if (updateDto == null) { return(null); } var dto = ProductConverter.Convert(updateDto); var product = ProductConverter.Convert(dto); product = await unitOfWork.Repository <Product>().Update(product); return(ProductConverter.Convert(product)); }
public async Task <ProductDTO> Update(UpdateProductDTO updateDto) { if (updateDto == null) { return(null); } var dto = ProductConverter.Convert(updateDto); dto.Category = await unitOfWork.Repository <Category>().Get(dto.CategoryId); //var product = ProductConverter.Convert(dto); var product = ProductConverter.Convert(await unitOfWork.Repository <Product>().Update(dto)); //product = ProductConverter.Convert(await unitOfWork.ProductRepository.GetFull(dto.Id)); return(product); }
public void BuildStocks_ShouldSet_IdsInStocks_ToMatch_IdsInStockEntities() { /* ARRANGE */ int[] expected = { 111, 222, 333 }; GiveStockEntitiesToMockProductEntity(expected); SetupMockRepositoryFactoryToReturnStocks(); /* ACT */ ProductConverter builder = CreateProductBuilderWithMocks(); //builder.BuildStocks(); /* ASSERT */ for (int i = 0; i < expected.Length; i++) { int actual = builder.Convert(mockProductEntity.Object, (a, b) => { }).Stocks[i].Id; Assert.AreEqual(expected[i], actual); } }
public void GetResult_ShouldReturnProduct_WithSameBasicProperties_AsProductEntity() { /* ARRANGE */ ProductEntity expectedProps = new ProductEntity { Id = 100, Name = "Name", Price = 10.00M, Sku = "Sku" }; SetBasicPropertiesInMockProductEntity(expectedProps); SetupMockDomainFactoryToReturnProduct(); /* ACT */ ProductConverter builder = CreateProductBuilderWithMocks(); IProduct product = builder.Convert(expectedProps, (a, b) => { }); /* ASSERT */ Assert.AreEqual(product.Id, expectedProps.Id); Assert.AreEqual(product.Name, expectedProps.Name); Assert.AreEqual(product.Price, expectedProps.Price); Assert.AreEqual(product.Sku, expectedProps.Sku); }
public CartItemBO Update(CartItemBO cartItem) { using (var uow = facade.UnitOfWork) { var cartItemFromDb = uow.CartItemRepository.Get(cartItem.Id); if (cartItemFromDb == null) { throw new InvalidOperationException("Cart not found"); } cartItemFromDb.Id = cartItem.Id; cartItemFromDb.Cart = cartConv.Convert(cartItem.Cart); cartItemFromDb.CartId = cartItem.CartId; cartItemFromDb.Product = prodConv.Convert(cartItem.Product); cartItemFromDb.ProductId = cartItem.ProductId; uow.Complete(); return(cartItemConv.Convert(cartItemFromDb)); } }
public async Task <Product> GetProductAsync(Guid id) { var product = await _dbContext.Products.FindAsync(id); return(ProductConverter.Convert(product)); }