Example #1
0
        private static void Initialize()
        {
            Companies = new List <Company>
            {
                Company.Create(Constants.CompanyAId, Constants.CompanyAName),
                Company.Create(Constants.CompanyBId, Constants.CompanyBName)
            };

            Products = new List <Product>()
            {
                Product.Create("sku1", "test sku1", Constants.CompanyAId),
                Product.Create("sku2", "test sku1", Constants.CompanyAId),
                Product.Create("sku3", "test sku1", Constants.CompanyAId),
                Product.Create("sku4", "test sku1", Constants.CompanyAId),
                Product.Create("sku5", "test sku1", Constants.CompanyBId),
                Product.Create("sku1", "test sku1", Constants.CompanyBId),
                Product.Create("sku2", "test sku1", Constants.CompanyBId),
                Product.Create("sku3", "test sku1", Constants.CompanyBId),
                Product.Create("sku4", "test sku1", Constants.CompanyBId),
                Product.Create("sku6", "test sku1", Constants.CompanyBId),
            };

            Suppliers = new List <Supplier>()
            {
                Supplier.Create(1, "test 1", Constants.CompanyAId),
                Supplier.Create(2, "test 1", Constants.CompanyAId),
                Supplier.Create(3, "test 1", Constants.CompanyAId),
                Supplier.Create(4, "test 1", Constants.CompanyAId),
                Supplier.Create(1, "test 1", Constants.CompanyBId),
                Supplier.Create(2, "test 1", Constants.CompanyBId),
                Supplier.Create(3, "test 1", Constants.CompanyBId),
                Supplier.Create(4, "test 1", Constants.CompanyBId),
                Supplier.Create(5, "test 1", Constants.CompanyBId),
            };

            SupplierProductBarcodes = new List <SupplierProductBarcode>()
            {
                SupplierProductBarcode.Create(1, "sku1", "abc1", Constants.CompanyAId),
                SupplierProductBarcode.Create(2, "sku2", "abc2", Constants.CompanyAId),
                SupplierProductBarcode.Create(3, "sku1", "abc3", Constants.CompanyAId),
                SupplierProductBarcode.Create(4, "sku1", "abc4", Constants.CompanyAId),
                SupplierProductBarcode.Create(1, "sku3", "abc5", Constants.CompanyAId),
                SupplierProductBarcode.Create(1, "sku4", "abc6", Constants.CompanyAId),
                SupplierProductBarcode.Create(1, "sku1", "abc1", Constants.CompanyBId),
                SupplierProductBarcode.Create(1, "sku2", "abc2", Constants.CompanyBId),
                SupplierProductBarcode.Create(1, "sku3", "abc33", Constants.CompanyBId),
                SupplierProductBarcode.Create(1, "sku4", "abc44", Constants.CompanyBId),
                SupplierProductBarcode.Create(1, "sku5", "abc55", Constants.CompanyBId),
                SupplierProductBarcode.Create(1, "sku6", "abc66", Constants.CompanyBId),
                SupplierProductBarcode.Create(1, "sku6", "abc77", Constants.CompanyBId),
                SupplierProductBarcode.Create(1, "sku1", "abc111", Constants.CompanyBId),
                SupplierProductBarcode.Create(1, "sku1", "abc12343", Constants.CompanyBId),
                SupplierProductBarcode.Create(1, "sku1", "abc90", Constants.CompanyBId),
                SupplierProductBarcode.Create(1, "sku6", "abcsadff", Constants.CompanyBId),
                SupplierProductBarcode.Create(1, "sku5", "qaqawrf", Constants.CompanyBId),
                SupplierProductBarcode.Create(1, "sku3", "qwrqwerdsrt", Constants.CompanyBId),
                SupplierProductBarcode.Create(1, "sku1", "abc12431234324", Constants.CompanyBId)
            };
        }
Example #2
0
        public void Test1()
        {
            // Arrange
            var bc1 = new SupplierProductBarcode
            {
                Barcode      = barcode1,
                DataSourceId = dataSourceId1,
                Sku          = sku1,
                SupplierId   = supplierId1
            };
            // Same barcode, we consider same product, even they are not the same sku.
            var SameBarcodeWithBc1 = new SupplierProductBarcode
            {
                Barcode      = barcode1,
                DataSourceId = dataSourceId2,
                Sku          = sku2,
                SupplierId   = supplierId2
            };
            var SameSkuWithBc1DiffBarcode = new SupplierProductBarcode
            {
                Barcode      = barcode2,
                DataSourceId = dataSourceId1,
                Sku          = sku1,
                SupplierId   = supplierId1
            };


            // Prevent context shared across test and mess up result.
            var context = new MockDbContextDto
            {
                Barcodes = new List <SupplierProductBarcode> {
                    bc1, SameBarcodeWithBc1, SameSkuWithBc1DiffBarcode
                },
                Catalog             = new List <Catalog>(),
                Supplier            = new List <Supplier>(),
                ConsolidatedCatalog = new List <ConsolidatedCatalog>()
            };

            // Action
            List <BarcodeDto> result = null;
            var exception            = Record.Exception(() => { result = _service.GetBarcodeList(context); });

            // Assert
            Assert.Null(exception);
            Assert.NotNull(result);
            Assert.True(result.Count == 2, "Should only return one barcode.");
            Assert.True(result.First().Skus.Count == 2, $"Barcode {result.First().Barcode} should contain 2 SKUs.");
        }
Example #3
0
 /// <summary>
 /// Initialize barcode data
 /// </summary>
 /// <returns>Tuple with barcodeA and barcodeB data</returns>
 public static (List <SupplierProductBarcode> barcodeA, List <SupplierProductBarcode> barcodeB, string msg) GetBarcodeData()
 {
     try
     {
         var barcodesA = File.ReadAllLines($"input\\barcodesA.csv")
                         .Skip(1)      // To remove the header text
                         .Select(v => SupplierProductBarcode.FromCsv(v))
                         .ToList();
         var barcodesB = File.ReadAllLines($"input\\barcodesB.csv")
                         .Skip(1)     // To remove the header text
                         .Select(v => SupplierProductBarcode.FromCsv(v))
                         .ToList();
         return(barcodesA, barcodesB, "success");
     }
     catch (System.Exception ex)
     {
         return(null, null, ex.Message);
     }
 }
Example #4
0
        public void AddNewSupplierAndASetOfBarcodesToCompany(
            Catalog catalog,
            Supplier supplier,
            IEnumerable <string> newBarcodes,
            string name
            )
        {
            var company  = GetCompany(name);
            var catalogs = company.Catalogs;

            if (!catalogs.GetAll().Any(x => x.SKU == catalog.SKU))
            {
                throw new NotFoundException($"SKU {catalog.SKU} not found");
            }

            //add supplier
            var suppliers = company.Suppliers;

            if (suppliers.GetAll().Any(x => x.Id == supplier.Id))
            {
                throw new DuplicateValueException($"Supplier {supplier.Id} is already exists");
            }
            suppliers.Add(supplier);
            suppliers.SaveChanges();

            //add barcodes
            var barcodes = company.Barcodes;

            foreach (var b in newBarcodes)
            {
                var newBarcode = new SupplierProductBarcode
                {
                    SupplierId = supplier.Id,
                    Barcode    = b,
                    SKU        = catalog.SKU,
                };
                barcodes.Add(newBarcode);
            }
            barcodes.SaveChanges();
        }
Example #5
0
        private static void LoadFromCsv()
        {
            Companies = new List <Company>
            {
                Company.Create(Constants.CompanyAId, Constants.CompanyAName),
                Company.Create(Constants.CompanyBId, Constants.CompanyBName)
            };

            Products = File.ReadLines("..\\..\\..\\..\\input\\catalogA.csv").Skip(1).Select(line =>
                                                                                            Product.Create(line.Split(',')[0], line.Split(',')[1], Constants.CompanyAId)).ToList();
            Products.AddRange(File.ReadLines("..\\..\\..\\..\\input\\catalogB.csv").Skip(1).Select(line =>
                                                                                                   Product.Create(line.Split(',')[0], line.Split(',')[1], Constants.CompanyBId)).ToList());

            Suppliers = File.ReadLines("..\\..\\..\\..\\input\\suppliersA.csv").Skip(1).Select(line =>
                                                                                               Supplier.Create(int.Parse(line.Split(',')[0]), line.Split(',')[1], Constants.CompanyAId)).ToList();
            Suppliers.AddRange(File.ReadLines("..\\..\\..\\..\\input\\suppliersB.csv").Skip(1).Select(line =>
                                                                                                      Supplier.Create(int.Parse(line.Split(',')[0]), line.Split(',')[1], Constants.CompanyBId)).ToList());

            SupplierProductBarcodes = File.ReadLines("..\\..\\..\\..\\input\\barcodesA.csv").Skip(1).Select(line =>
                                                                                                            SupplierProductBarcode.Create(int.Parse(line.Split(',')[0]), line.Split(',')[1], line.Split(',')[2], Constants.CompanyAId)).ToList();
            SupplierProductBarcodes.AddRange(File.ReadLines("..\\..\\..\\..\\input\\barcodesB.csv").Skip(1).Select(line =>
                                                                                                                   SupplierProductBarcode.Create(int.Parse(line.Split(',')[0]), line.Split(',')[1], line.Split(',')[2], Constants.CompanyBId)).ToList());
        }