public void TestSetup() { converter = new ProductConverter(); fakeProduct = new Product { Id = NumberFaker.Number(1, int.MaxValue), Name = StringFaker.Alpha(20), ReleaseDate = DateTime.Now, Notes = TextFaker.Sentences(5), LicenseEncryptionType = EncryptionType.RSA_4096, PrivateKey = StringFaker.AlphaNumeric(50), PublicKey = StringFaker.AlphaNumeric(50), DefaultLockProperties = LockPropertyType.CPU | LockPropertyType.BIOS, FailOnNullHardwareIdentifier = BooleanFaker.Boolean(), PermittedActivationTypes = ActivationMethodType.Manual | ActivationMethodType.Email, PermittedExpirationTypes = LicenseType.Service, VersionLeeway = VersionLeewayType.Strict, }; fakeViewmodel = new ProductViewModel { Id = NumberFaker.Number(1, int.MaxValue), Name = StringFaker.Alpha(20), ReleaseDate = DateTime.Now, Notes = TextFaker.Sentences(5), SelectedDefaultLockProperties = new List<string> { ((int)LockPropertyType.CPU).ToString(), ((int)LockPropertyType.BIOS).ToString() }, FailOnNullHardwareIdentifier = BooleanFaker.Boolean(), PermittedActivationTypes = new List<string> { ((int)ActivationMethodType.Manual).ToString(), ((int)ActivationMethodType.Email).ToString() }, // randomly selects a versionleewaytype VersionLeeway = ((int)VersionLeewayType.Strict).ToString() }; }
public async Task <Guid> AddProductAsync(Product product) { var dbProduct = ProductConverter.Convert(product); _dbContext.Products.Add(dbProduct); await _dbContext.SaveChangesAsync(); return(dbProduct.Id); }
private List <Product> ConvertOffers(IEnumerable <Offer> offers, int shopWeight) { var calculation = new RatingCalculation(shopWeight); var products = new ProductConverter(_dbHelper, calculation).GetProductsContainer(offers); SetProgress(80); AddMessage("Convert to products complete"); return(products); }
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); }
List <ProductDTO> IService1.GetProducts() { List <Product> products = new List <Product>(); // Ürün Mapper ProductMapper productMapper = new ProductMapper(); // Tüm ürünleri yükle products = productMapper.GetAllProducts(); // Ürünleri dönüştür ve geri gönder return(ProductConverter.CretateProductDto(products)); }
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 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 static ProductDTO Add(ProductDTO product) { Product p = ProductConverter.DTOToDAL(product); using (GetCoffeeDBEntities db = new GetCoffeeDBEntities()) { db.Products.Add(p); db.SaveChanges(); } return(ProductConverter.DALToDTO(p)); }
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 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 <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 ActionResult <IEnumerable <ProductResponse> > GeProducts() { try { IEnumerable <Product> res = new ProductAdapter(_loggerFactory, _context).findAll(); return(new OkObjectResult(ProductConverter.getObjectEntity(res))); } catch (DomainException) { return(new List <ProductResponse>()); } }
public ActionResult <ProductResponse> PostProduct(PostProductRequest entity) { try { Product res = new ProductAdapter(_loggerFactory, _context).add(ProductConverter.getObjectEntity(entity)); return(new OkObjectResult(ProductConverter.getObjectEntity(res))); } catch (DomainException) { return(NoContent()); } }
public ActionResult <IEnumerable <ProductResponse> > GeProduct(Guid id) { try { IEnumerable <Product> res = new ProductAdapter(_loggerFactory, _context).findById(id); return(new OkObjectResult(ProductConverter.getObjectEntity(res))); } catch (DomainException) { return(NotFound()); } }
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 ConverterFactory(IDomainFactory domainFactory, IEntityFactory entityFactory, IRepositoryFactory repositoryFactory, IDAOFactory daoFactory) { this.domainFactory = domainFactory; this.entityFactory = entityFactory; this.repositoryFactory = repositoryFactory; this.daoFactory = daoFactory; productConverter = new ProductConverter(this.domainFactory, this.repositoryFactory); productEntityConverter = new ProductEntityConverter(entityFactory, daoFactory); stockConverter = new StockConverter(domainFactory, repositoryFactory); stockEntityConverter = new StockEntityConverter(entityFactory, daoFactory); tagConverter = new TagConverter(domainFactory, repositoryFactory); tagEntityConverter = new TagEntityConverter(entityFactory, daoFactory); }
public ActionResult <ProductResponse> PutProduct(Guid id, PutProductRequest entity) { if (id != entity.Id) { return(BadRequest()); } try { Product res = new ProductAdapter(_loggerFactory, _context).update(id, ProductConverter.getObjectEntity(entity)); return(new OkObjectResult(ProductConverter.getObjectEntity(res))); } catch (DomainException) { return(NoContent()); } }
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 PipelineExecutionResult Execute(Product subject) { var config = KachingConfiguration.Get(); var url = config.ProductsIntegrationURL; if (!url.StartsWith("https://", StringComparison.Ordinal)) { return(PipelineExecutionResult.Success); } // In case a product is initially being created, it will not yet have a // category configured. In this case delay the synchronization slightly // in order to let the database save the product<->category relationship. Func <PipelineExecutionResult> synchronize = () => { var converter = new ProductConverter(logging); var product = converter.ConvertProduct(subject); KachingProduct[] products = new KachingProduct[1]; products[0] = product; var metadata = converter.GetMetadata(); return(Synchronizer.Post(new ProductsRequest(products, metadata), url)); }; if (subject.GetCategories().Count == 0) { Task.Delay(2000).ContinueWith((task) => { synchronize(); }); return(PipelineExecutionResult.Success); } return(synchronize()); }
private int ImportProducts(IEnumerable <Product> products) { var config = KachingConfiguration.Get(); var url = config.ProductsIntegrationURL; if (!url.StartsWith("https://", StringComparison.Ordinal)) { return(0); } var converter = new ProductConverter(logger); List <KachingProduct> kachingProducts = new List <KachingProduct>(); foreach (var product in products) { kachingProducts.Add(converter.ConvertProduct(product)); } var metadata = converter.GetMetadata(); Synchronizer.Post(new ProductsRequest(kachingProducts.ToArray(), metadata), url); return(kachingProducts.Count); }
public void TestSetup() { converter = new ProductConverter(); fakeProduct = new Product { Id = NumberFaker.Number(1, int.MaxValue), Name = StringFaker.Alpha(20), ReleaseDate = DateTime.Now, Notes = TextFaker.Sentences(5), LicenseEncryptionType = EncryptionType.RSA_4096, PrivateKey = StringFaker.AlphaNumeric(50), PublicKey = StringFaker.AlphaNumeric(50), DefaultLockProperties = LockPropertyType.CPU | LockPropertyType.BIOS, FailOnNullHardwareIdentifier = BooleanFaker.Boolean(), PermittedActivationTypes = ActivationMethodType.Manual | ActivationMethodType.Email, PermittedExpirationTypes = LicenseType.Service, VersionLeeway = VersionLeewayType.Strict, }; fakeViewmodel = new ProductViewModel { Id = NumberFaker.Number(1, int.MaxValue), Name = StringFaker.Alpha(20), ReleaseDate = DateTime.Now, Notes = TextFaker.Sentences(5), SelectedDefaultLockProperties = new List <string> { ((int)LockPropertyType.CPU).ToString(), ((int)LockPropertyType.BIOS).ToString() }, FailOnNullHardwareIdentifier = BooleanFaker.Boolean(), PermittedActivationTypes = new List <string> { ((int)ActivationMethodType.Manual).ToString(), ((int)ActivationMethodType.Email).ToString() }, // randomly selects a versionleewaytype VersionLeeway = ((int)VersionLeewayType.Strict).ToString() }; }
public async Task <IActionResult> Index([FromQuery] int page = 1, [FromQuery] string nameFilter = "") { var productQuery = context.Products.AsQueryable(); if (!string.IsNullOrEmpty(nameFilter)) { /// TODO: имя проверяется регистрозависимо. передалать на регистронезависимый поиск. productQuery = productQuery.Where(x => x.Name.Contains(nameFilter)); } var products = await productQuery .OrderBy(x => x.Name) .Include(x => x.Mesurement) .Take(PRODUCT_PER_PAGE) .Skip((page - 1) * PRODUCT_PER_PAGE) .ToListAsync(); var result = new List <ProductViewModel>(); foreach (var product in products) { result.Add(ProductConverter.ConvertProduct(product)); } return(Json(result)); }
private void RewriteProtocolReport(ArchivedDiaryW adiary, string category, IEnumerable<ArchivedProduct> products) { var model = new ReportModel(); model.ReportParameters.Add("AcredetationLevel", category); model.ReportParameters.Add("ProtocolNumber", category + adiary.Number); model.ReportParameters.Add("ProtocolIssuedDate", adiary.ProtocolIssuedDate); var convertedProducts = new List<Product>(); var productConverter = new ProductConverter(); foreach (var pr in products) { var product = productConverter.ConvertFromArchived(pr); convertedProducts.Add(product); } model.ReportParameters.Add("Products", convertedProducts); //var methods = convertedProducts.SelectMany(p => p.ProductTests.Where(pt => pt.Test.AcredetationLevel.Level.Trim() == category).Select(pt => pt.Test.TestMethods)).Distinct(); var methods = convertedProducts.SelectMany(p => p.ProductTests.Where(pt => pt.Test.AcredetationLevel.Level.Trim() == category) .Select(pt => new MethodsModel() { TestName = pt.Test.Name, TestMethod = pt.TestMethod.Method })).ToList().Distinct(); model.ReportParameters.Add("Methods", methods); var quantities = convertedProducts.OrderBy(p => p.Number).Select(p => p.Quantity); model.ReportParameters.Add("Quantities", quantities); var protocolResultsConverter = new ProtocolResultsConverter(); var theProtocolResults = adiary.ArchivedProtocolResults.Select(apr => protocolResultsConverter.ConvertFromArchived(apr)); var protocolResults = theProtocolResults.Where(pr => pr.ProductTest.Test.AcredetationLevel.Level.Trim() == category) .OrderBy(x => x.ProductTest.Product.Number).ThenBy(x => x.ProductTest.Test.Name).ThenBy(x => x.ResultNumber); model.ReportParameters.Add("ProtocolResults", protocolResults); model.ReportParameters.Add("Contractor", adiary.Contractor); model.ReportParameters.Add("Client", adiary.Client); model.ReportParameters.Add("LetterNumber", adiary.LetterNumber); model.ReportParameters.Add("LetterDate", adiary.LetterDate); model.ReportParameters.Add("RequestDate", adiary.RequestDate.ToLocalTime()); model.ReportParameters.Add("LabLeader", adiary.ProtocolLabLeader); model.ReportParameters.Add("TesterMKB", adiary.ProtocolTesterMKB); model.ReportParameters.Add("TesterFZH", adiary.ProtocolTesterFZH); var remarksConverter = new RemarksConverter(); var remarks = adiary.ArchivedProtocolRemarks.Where(r => r.AcredetationLevel.Trim() == category). Select(r => new ProtocolsRemark() { Remark = remarksConverter.ConvertFromArchived(r), Number = r.Number }); model.ReportParameters.Add("Remarks", remarks); if (category == "A") { string acredetationString = @"АКРЕДИТИРАНА СЪГЛАСНО БДС EN ISO/IEC 17025:2006 СЕРТИФИКАТ №55 ЛИ ОТ 08.04.2015 г./ ИА „БСА” С ВАЛИДНОСТ НА АКРЕДИТАЦИЯТА ДО 31.03.2016 г. "; model.ReportParameters.Add("AcredetationString", acredetationString); } var report = new ProtocolReport(model); var data = report.GenerateReport(); CheckAndGenerateDirectories(adiary.Number); var fileProps = GetFileProperties(adiary.Number, FileNames.Protocol, category); if (File.Exists(fileProps.FullPath)) { string newDestination = fileProps.FullPath.Substring(0, fileProps.FullPath.Length - 5) + "_" + DateTime.Now.ToString("dd_MM_yyyy_HH_mm_ss") + ".docx"; File.Move(fileProps.FullPath, newDestination); } var file = File.Create(fileProps.FullPath); file.Write(data, 0, data.Length); file.Close(); }
public ProductBusinessImpl(IProductRepository repository) { _repository = repository; _converter = new ProductConverter(); }
public ProductBusiness(IRepository <Product> repository) { _repository = repository; _converter = new ProductConverter(); _context = new BaseContext(); }
public async Task <Product> GetProductAsync(Guid id) { var product = await _dbContext.Products.FindAsync(id); return(ProductConverter.Convert(product)); }
public GetPagedProductsByCategoryQueryHandler(IProductRepository repository, ProductConverter converter) { _repository = repository; _converter = converter; }
private void RewriteProtocolReport(ArchivedDiaryW adiary, string category, IEnumerable <ArchivedProduct> products) { var model = new ReportModel(); model.ReportParameters.Add("AcredetationLevel", category); model.ReportParameters.Add("ProtocolNumber", category + adiary.Number); model.ReportParameters.Add("ProtocolIssuedDate", adiary.ProtocolIssuedDate); var convertedProducts = new List <Product>(); var productConverter = new ProductConverter(); foreach (var pr in products) { var product = productConverter.ConvertFromArchived(pr); convertedProducts.Add(product); } model.ReportParameters.Add("Products", convertedProducts); var methods = convertedProducts.SelectMany(p => p.ProductTests.Where(pt => pt.Test.AcredetationLevel.Level.Trim() == category) .Select(pt => new MethodsModel() { TestName = pt.Test.Name, TestMethod = pt.TestMethod.Method })).ToList().Distinct(); model.ReportParameters.Add("Methods", methods); var quantities = convertedProducts.OrderBy(p => p.Number).Select(p => p.Quantity); model.ReportParameters.Add("Quantities", quantities); var protocolResultsConverter = new ProtocolResultsConverter(); var theProtocolResults = adiary.ArchivedProtocolResults.Select(apr => protocolResultsConverter.ConvertFromArchived(apr)); var protocolResults = theProtocolResults.Where(pr => pr.ProductTest.Test.AcredetationLevel.Level.Trim() == category) .OrderBy(x => x.ProductTest.Product.Number).ThenBy(x => x.ProductTest.Test.Name).ThenBy(x => x.ResultNumber); model.ReportParameters.Add("ProtocolResults", protocolResults); model.ReportParameters.Add("category", category); model.ReportParameters.Add("AcreditationRegisteredDate", adiary.AcreditationRegisteredDate); model.ReportParameters.Add("AcreditationValidToDate", adiary.AcreditationValidToDate); model.ReportParameters.Add("Contractor", adiary.Contractor); model.ReportParameters.Add("Client", adiary.Client); model.ReportParameters.Add("LetterNumber", adiary.LetterNumber); model.ReportParameters.Add("LetterDate", adiary.LetterDate); model.ReportParameters.Add("RequestDate", adiary.RequestDate.ToLocalTime()); model.ReportParameters.Add("LabLeader", adiary.ProtocolLabLeader); model.ReportParameters.Add("Tester", adiary.ProtocolTester); var remarksConverter = new RemarksConverter(); var remarks = adiary.ArchivedProtocolRemarks.Where(r => r.AcredetationLevel.Trim() == category) .Select(r => new ProtocolsRemark() { Remark = remarksConverter.ConvertFromArchived(r), Number = r.Number }); model.ReportParameters.Add("Remarks", remarks); if (category == "A") { string acredetationString = @"АКРЕДИТИРАНА СЪГЛАСНО БДС EN ISO/IEC 17025:2006 СЕРТИФИКАТ №55 ЛИ ОТ 08.04.2015 г./ ИА „БСА” С ВАЛИДНОСТ НА АКРЕДИТАЦИЯТА ДО 31.03.2016 г. "; model.ReportParameters.Add("AcredetationString", acredetationString); } var report = new ProtocolReport(model); var data = report.GenerateReport(); CheckAndGenerateDirectories(adiary.Number); var fileProps = GetFileProperties(adiary.Number, FileNames.Protocol, category); if (File.Exists(fileProps.FullPath)) { string newDestination = fileProps.FullPath.Substring(0, fileProps.FullPath.Length - 5) + "_" + DateTime.Now.ToString("dd_MM_yyyy_HH_mm_ss") + ".docx"; File.Move(fileProps.FullPath, newDestination); } var file = File.Create(fileProps.FullPath); file.Write(data, 0, data.Length); file.Close(); }