public CreateCompanyProductBarcodeResult CreateCompanyProductBarcode(CreateCompanyProductBarcodeRequest request) { var result = new CreateCompanyProductBarcodeResult(); try { result.Errors.AddRange(ValidateProductSkuRequired(request.ProductSku)); result.Errors.AddRange(CompanyProductService.ValidateCompanyProductExist(request.ProductSku, request.CompanyCode)); result.Errors.AddRange(ValidateSupplierCodeRequired(request.SupplierCode)); result.Errors.AddRange(SupplierService.ValidateSupplierExist(request.SupplierCode, request.CompanyCode)); result.Errors.AddRange(ValidateCompanyCodeRequired(request.CompanyCode)); result.Errors.AddRange(CompanyService.ValidateCompanyExist(request.CompanyCode)); result.Errors.AddRange(ValidateDuplicateCompanyProductBarcode(request.Barcode, request.SupplierCode, request.ProductSku, request.CompanyCode)); if (result.Errors.Any()) { return(result); } var supplier = SupplierService.GetSupplier(request.SupplierCode, request.CompanyCode); var companyProduct = CompanyProductService.GetCompanyProduct(request.ProductSku, request.CompanyCode); var newCompanyProductBarcode = new CompanyProductBarcode { SupplierId = supplier.SupplierId, CompanyProductId = companyProduct.CompanyProductId, Barcode = request.Barcode.ToLower().Trim(), CreatedDateUtc = DateTime.UtcNow, ModifiedDateUtc = DateTime.UtcNow }; UoW.CompanyProductBarcodes.Add(newCompanyProductBarcode); UoW.Save(); result.Success = true; } catch (Exception e) { result.Success = false; result.Errors.Add(new ExceptionError(e.Message)); } return(result); }
public BaseCompanyProductBarcodeTests() { UoW = new Mock <IUnitOfWork>(); Logger = new Mock <ILogger <ICompanyProductBarcodeService> >(); ImportCompanyProductBarcodeCsvService = new Mock <ICsvService <ImportCompanyProductBarcodeDto> >(); CompanyService = new Mock <ICompanyService>(); CompanyProductService = new Mock <ICompanyProductService>(); SupplierService = new Mock <ISupplierService>(); Subject = new CompanyProductBarcodeService(UoW.Object, Logger.Object, ImportCompanyProductBarcodeCsvService.Object, CompanyProductService.Object, SupplierService.Object, CompanyService.Object); var companyA = new Company { CompanyCode = TestData.CompanyCodeA, CompanyName = "Company A" }; var companyB = new Company { CompanyCode = TestData.CompanyCodeB, CompanyName = "Company A" }; CompanyService.Setup(m => m.GetCompany(TestData.CompanyCodeA)).Returns(companyA); CompanyService.Setup(m => m.GetCompany(TestData.CompanyCodeB)).Returns(companyB); CompanyService.Setup(m => m.ValidateCompanyExist(It.IsAny <string>())).Returns(new List <Error>()); var supplier = new Supplier { SupplierCode = TestData.SupplierCode, SupplierName = "SupplierName2", Company = companyA }; SupplierService.Setup(m => m.GetSupplier(TestData.SupplierCode, TestData.CompanyCodeA)).Returns(supplier); SupplierService.Setup(m => m.ValidateSupplierExist(TestData.SupplierCode, TestData.CompanyCodeA)).Returns(new List <Error>()); var companyProductProductCompanyA = new CompanyProduct { ProductSku = TestData.ProductSkuCompanyCodeA, ProductName = "ProductName1", Company = companyA }; var companyProductProductCompanyB = new CompanyProduct { ProductSku = TestData.ProductSkuCompanyCodeB, ProductName = "ProductName2", Company = companyB }; CompanyProductService.Setup(m => m.GetCompanyProduct(TestData.ProductSkuCompanyCodeA, TestData.CompanyCodeA)).Returns(companyProductProductCompanyA); CompanyProductService.Setup(m => m.ValidateCompanyProductExist(TestData.ProductSkuCompanyCodeA, TestData.CompanyCodeA)).Returns(new List <Error>()); CompanyProductService.Setup(m => m.GetCompanyProduct(TestData.ProductSkuCompanyCodeB, TestData.CompanyCodeB)).Returns(companyProductProductCompanyB); CompanyProductService.Setup(m => m.ValidateCompanyProductExist(TestData.ProductSkuCompanyCodeB, TestData.CompanyCodeB)).Returns(new List <Error>()); var companyProductBarcode1 = new CompanyProductBarcode { Barcode = TestData.BarcodeProductSkuCompanyCodeA, CompanyProduct = companyProductProductCompanyA, Supplier = supplier }; UoW.Setup(m => m.CompanyProductBarcodes.GetAll()).Returns(new List <CompanyProductBarcode> { companyProductBarcode1 }.AsQueryable()); }
public BaseProductTests() { UoW = new Mock <IUnitOfWork>(); Logger = new Mock <ILogger <ProductService> >(); ProductCatalogCsvService = new Mock <ICsvService <ProductCatalogDto> >(); Subject = new ProductService(UoW.Object, Logger.Object, ProductCatalogCsvService.Object); var companyA = new Company { CompanyCode = "A", CompanyName = "Company A" }; var companyB = new Company { CompanyCode = "B", CompanyName = "Company A" }; var companyASupplier1 = new Supplier { SupplierCode = "00001", SupplierName = "Supplier 1", Company = companyA }; var companyBSupplier1 = new Supplier { SupplierCode = "00001", SupplierName = "Supplier 1", Company = companyA }; var companyACompanyProduct1 = new CompanyProduct { ProductSku = "ProductSku1", ProductName = "ProductName1", Company = companyA, CompanyProductBarcodes = new List <CompanyProductBarcode>() }; var companyBCompanyProduct1 = new CompanyProduct { ProductSku = "ProductSku2", ProductName = "ProductName2", Company = companyB, CompanyProductBarcodes = new List <CompanyProductBarcode>() }; var companyBCompanyProduct2 = new CompanyProduct { ProductSku = "ProductSku3", ProductName = "ProductName3", Company = companyB, CompanyProductBarcodes = new List <CompanyProductBarcode>() }; var companyACompanyProduct1Barcode1 = new CompanyProductBarcode { Barcode = "Barcode1", CompanyProduct = companyACompanyProduct1, Supplier = companyASupplier1 }; companyACompanyProduct1.CompanyProductBarcodes.Add(companyACompanyProduct1Barcode1); var companyACompanyProduct1Barcode2 = new CompanyProductBarcode { Barcode = "Barcode2", CompanyProduct = companyACompanyProduct1, Supplier = companyASupplier1 }; companyACompanyProduct1.CompanyProductBarcodes.Add(companyACompanyProduct1Barcode2); var companyBCompanyProduct1Barcode1 = new CompanyProductBarcode { Barcode = "Barcode1", CompanyProduct = companyBCompanyProduct1, Supplier = companyBSupplier1 }; companyBCompanyProduct1.CompanyProductBarcodes.Add(companyBCompanyProduct1Barcode1); var companyBCompanyProduct2Barcode1 = new CompanyProductBarcode { Barcode = "Barcode3", CompanyProduct = companyBCompanyProduct2, Supplier = companyBSupplier1 }; companyBCompanyProduct2.CompanyProductBarcodes.Add(companyBCompanyProduct2Barcode1); UoW.Setup(m => m.CompanyProducts.GetAll()).Returns(new List <CompanyProduct> { companyACompanyProduct1, companyBCompanyProduct1, companyBCompanyProduct2, }.AsQueryable()); }