public void Test_Read_BevNet_File_With_Header_And_Three_Records()
        {
            IEnumerable <PriceFile> priceFile;

            priceFile = FileReaderGeneric <PriceFile> .ReadFile("C:\\_P\\Tools\\cmArt.LibIntegrations\\" +
                                                                "IntegrationTest_cmArt.LibIntegrations\\BevNet_Small.csv");

            Assert.AreEqual(3, priceFile.Count());
        }
        public void ValidateContents_Of_BevNet_File_With_Header_And_First_Of_Three_Records()
        {
            IEnumerable <PriceFile> priceFile;

            priceFile = FileReaderGeneric <PriceFile> .ReadFile("C:\\_P\\Tools\\cmArt.LibIntegrations\\" +
                                                                "IntegrationTest_cmArt.LibIntegrations\\BevNet_Small.csv");

            Assert.AreEqual(3, priceFile.Count());

            // validate contents of record 1
            PriceFile record = priceFile.FirstOrDefault();

            Assert.AreEqual("010SK", record.UNIV_PROD);
            Assert.AreEqual("LEALTANZA  RIOJA CRIANZA", record.BDESC);
            Assert.AreEqual("LEALTANZA CRIANZA", record.DESCRIPTIO);
            Assert.AreEqual(750, record.SIZE);
            Assert.AreEqual("", record.VINTAGE);
            Assert.AreEqual("645", record.UNIV_CAT);
            Assert.AreEqual("W", record.LWBN);
            Assert.AreEqual((decimal)13.4100, record.BESTBOT);
            Assert.AreEqual("01/01/2021", record.DATE);
            Assert.AreEqual(12, record.BOTPERCASE);
            Assert.AreEqual(0, record.SECPACK);
            Assert.AreEqual("EDER", record.WHOLESALER);
            Assert.AreEqual("00018", record.PROD_ITEM);
            Assert.AreEqual("", record.UPC);
            Assert.AreEqual((decimal)160.9200, record.CASE_PRICE);
            Assert.AreEqual((decimal)16.99, record.BOT_PRICE);
            Assert.AreEqual((decimal)25.4900, record.FRONT_NYC);
            Assert.AreEqual((decimal)18.0000, record.POSTOFF);
            Assert.AreEqual(0, record.QTY1__);
            Assert.AreEqual(" ", record.D_TYPE1__);
            Assert.AreEqual(0.0000, record.DISCOUNT1_);
            Assert.AreEqual(0, record.QTY2__);
            Assert.AreEqual(" ", record.D_TYPE2__);
            Assert.AreEqual(0.0000, record.DISCOUNT2_);
            Assert.AreEqual(0, record.QTY3__);
            Assert.AreEqual(" ", record.D_TYPE3__);
            Assert.AreEqual(0.0000, record.DISCOUNT3_);
            Assert.AreEqual(0, record.QTY4__);
            Assert.AreEqual(" ", record.D_TYPE4__);
            Assert.AreEqual(0.0000, record.DISCOUNT4_);
            Assert.AreEqual(0, record.QTY5__);
            Assert.AreEqual(" ", record.D_TYPE5__);
            Assert.AreEqual(0.0000, record.DISCOUNT5_);
            Assert.AreEqual(0, record.QTY6__);
            Assert.AreEqual(" ", record.D_TYPE6__);
            Assert.AreEqual(0.0000, record.DISCOUNT6_);
            Assert.AreEqual(0, record.QTY7__);
            Assert.AreEqual(" ", record.D_TYPE7__);
            Assert.AreEqual(0.0000, record.DISCOUNT7_);
            Assert.AreEqual(0, record.QTY8__);
            Assert.AreEqual(" ", record.D_TYPE8__);
            Assert.AreEqual(0.0000, record.DISCOUNT8_);
            Assert.AreEqual(0, record.QTY9__);
            Assert.AreEqual(" ", record.D_TYPE9__);
            Assert.AreEqual(0.0000, record.DISCOUNT9_);
            Assert.AreEqual("", record.DIV1___);
            Assert.AreEqual("", record.DIV2___);
            Assert.AreEqual("", record.DIV3___);
            Assert.AreEqual("", record.DIV4___);
            Assert.AreEqual("", record.DIV5___);
            Assert.AreEqual("", record.DIV6___);
            Assert.AreEqual("", record.DIV7___);
            Assert.AreEqual("", record.DIV8___);
            Assert.AreEqual("", record.DIV9___);
            Assert.AreEqual("", record.DIV10___);
            Assert.AreEqual("", record.DIV11___);
            Assert.AreEqual("", record.DIV12___);
            Assert.AreEqual("", record.ASST_SIZE);
            Assert.AreEqual((decimal)25.49, record.CALE_SHELF);
            Assert.AreEqual("", record.TRUEVINT);
            Assert.AreEqual("F", record.FULLCASE);
            Assert.AreEqual("Spanish Still Wine", record.TYPE_DESC);
            Assert.AreEqual((decimal)0.00, record.DEPOSIT);
            Assert.AreEqual("Eder Brothers", record.WHOLE_NAME);

            // validate contents of record 2
            //record = priceFile.Skip(1).FirstOrDefault();
            //Assert.AreEqual("", record.UNIV_PROD);
            //Assert.AreEqual("", record.BDESC);
            //Assert.AreEqual("", record.DESCRIPTIO);
            //Assert.AreEqual("", record.SIZE);
            //Assert.AreEqual("", record.VINTAGE);
            //Assert.AreEqual("", record.UNIV_CAT);
            //Assert.AreEqual("", record.LWBN);
            //Assert.AreEqual("", record.BESTBOT);
            //Assert.AreEqual("", record.DATE);
            //Assert.AreEqual("", record.BOTPERCASE);
            //Assert.AreEqual("", record.SECPACK);
            //Assert.AreEqual("", record.WHOLESALER);
            //Assert.AreEqual("", record.PROD_ITEM);
            //Assert.AreEqual("", record.UPC);
            //Assert.AreEqual("", record.CASE_PRICE);
            //Assert.AreEqual("", record.BOT_PRICE);
            //Assert.AreEqual("", record.FRONT_NYC);
            //Assert.AreEqual("", record.POSTOFF);
            //Assert.AreEqual("", record.QTY1__);
            //Assert.AreEqual("", record.D_TYPE1__);
            //Assert.AreEqual("", record.DISCOUNT1_);
            //Assert.AreEqual("", record.QTY2__);
            //Assert.AreEqual("", record.D_TYPE2__);
            //Assert.AreEqual("", record.DISCOUNT2_);
            //Assert.AreEqual("", record.QTY3__);
            //Assert.AreEqual("", record.D_TYPE3__);
            //Assert.AreEqual("", record.DISCOUNT3_);
            //Assert.AreEqual("", record.QTY4__);
            //Assert.AreEqual("", record.D_TYPE4__);
            //Assert.AreEqual("", record.DISCOUNT4_);
            //Assert.AreEqual("", record.QTY5__);
            //Assert.AreEqual("", record.D_TYPE5__);
            //Assert.AreEqual("", record.DISCOUNT5_);
            //Assert.AreEqual("", record.QTY6__);
            //Assert.AreEqual("", record.D_TYPE6__);
            //Assert.AreEqual("", record.DISCOUNT6_);
            //Assert.AreEqual("", record.QTY7__);
            //Assert.AreEqual("", record.D_TYPE7__);
            //Assert.AreEqual("", record.DISCOUNT7_);
            //Assert.AreEqual("", record.QTY8__);
            //Assert.AreEqual("", record.D_TYPE8__);
            //Assert.AreEqual("", record.DISCOUNT8_);
            //Assert.AreEqual("", record.QTY9__);
            //Assert.AreEqual("", record.D_TYPE9__);
            //Assert.AreEqual("", record.DISCOUNT9_);
            //Assert.AreEqual("", record.DIV1___);
            //Assert.AreEqual("", record.DIV2___);
            //Assert.AreEqual("", record.DIV3___);
            //Assert.AreEqual("", record.DIV4___);
            //Assert.AreEqual("", record.DIV5___);
            //Assert.AreEqual("", record.DIV6___);
            //Assert.AreEqual("", record.DIV7___);
            //Assert.AreEqual("", record.DIV8___);
            //Assert.AreEqual("", record.DIV9___);
            //Assert.AreEqual("", record.DIV10___);
            //Assert.AreEqual("", record.DIV11___);
            //Assert.AreEqual("", record.DIV12___);
            //Assert.AreEqual("", record.ASST_SIZE);
            //Assert.AreEqual("", record.CALE_SHELF);
            //Assert.AreEqual("", record.TRUEVINT);
            //Assert.AreEqual("", record.FULLCASE);
            //Assert.AreEqual("", record.TYPE_DESC);
            //Assert.AreEqual("", record.DEPOSIT);
            //Assert.AreEqual("", record.WHOLE_NAME);

            // validate contents of record 3
            //record = priceFile.Skip(2).FirstOrDefault();
            //Assert.AreEqual("", record.UNIV_PROD);
            //Assert.AreEqual("", record.BDESC);
            //Assert.AreEqual("", record.DESCRIPTIO);
            //Assert.AreEqual("", record.SIZE);
            //Assert.AreEqual("", record.VINTAGE);
            //Assert.AreEqual("", record.UNIV_CAT);
            //Assert.AreEqual("", record.LWBN);
            //Assert.AreEqual("", record.BESTBOT);
            //Assert.AreEqual("", record.DATE);
            //Assert.AreEqual("", record.BOTPERCASE);
            //Assert.AreEqual("", record.SECPACK);
            //Assert.AreEqual("", record.WHOLESALER);
            //Assert.AreEqual("", record.PROD_ITEM);
            //Assert.AreEqual("", record.UPC);
            //Assert.AreEqual("", record.CASE_PRICE);
            //Assert.AreEqual("", record.BOT_PRICE);
            //Assert.AreEqual("", record.FRONT_NYC);
            //Assert.AreEqual("", record.POSTOFF);
            //Assert.AreEqual("", record.QTY1__);
            //Assert.AreEqual("", record.D_TYPE1__);
            //Assert.AreEqual("", record.DISCOUNT1_);
            //Assert.AreEqual("", record.QTY2__);
            //Assert.AreEqual("", record.D_TYPE2__);
            //Assert.AreEqual("", record.DISCOUNT2_);
            //Assert.AreEqual("", record.QTY3__);
            //Assert.AreEqual("", record.D_TYPE3__);
            //Assert.AreEqual("", record.DISCOUNT3_);
            //Assert.AreEqual("", record.QTY4__);
            //Assert.AreEqual("", record.D_TYPE4__);
            //Assert.AreEqual("", record.DISCOUNT4_);
            //Assert.AreEqual("", record.QTY5__);
            //Assert.AreEqual("", record.D_TYPE5__);
            //Assert.AreEqual("", record.DISCOUNT5_);
            //Assert.AreEqual("", record.QTY6__);
            //Assert.AreEqual("", record.D_TYPE6__);
            //Assert.AreEqual("", record.DISCOUNT6_);
            //Assert.AreEqual("", record.QTY7__);
            //Assert.AreEqual("", record.D_TYPE7__);
            //Assert.AreEqual("", record.DISCOUNT7_);
            //Assert.AreEqual("", record.QTY8__);
            //Assert.AreEqual("", record.D_TYPE8__);
            //Assert.AreEqual("", record.DISCOUNT8_);
            //Assert.AreEqual("", record.QTY9__);
            //Assert.AreEqual("", record.D_TYPE9__);
            //Assert.AreEqual("", record.DISCOUNT9_);
            //Assert.AreEqual("", record.DIV1___);
            //Assert.AreEqual("", record.DIV2___);
            //Assert.AreEqual("", record.DIV3___);
            //Assert.AreEqual("", record.DIV4___);
            //Assert.AreEqual("", record.DIV5___);
            //Assert.AreEqual("", record.DIV6___);
            //Assert.AreEqual("", record.DIV7___);
            //Assert.AreEqual("", record.DIV8___);
            //Assert.AreEqual("", record.DIV9___);
            //Assert.AreEqual("", record.DIV10___);
            //Assert.AreEqual("", record.DIV11___);
            //Assert.AreEqual("", record.DIV12___);
            //Assert.AreEqual("", record.ASST_SIZE);
            //Assert.AreEqual("", record.CALE_SHELF);
            //Assert.AreEqual("", record.TRUEVINT);
            //Assert.AreEqual("", record.FULLCASE);
            //Assert.AreEqual("", record.TYPE_DESC);
            //Assert.AreEqual("", record.DEPOSIT);
            //Assert.AreEqual("", record.WHOLE_NAME);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Begin");

            IConfiguration config = new ConfigurationBuilder()
                                    .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                                    .Build();

            IEnumerable <IPriceFile> BevNetRecords = new List <PriceFile>();
            string     PathAndFile = config["SourceDirectory"] + config["FileName"];
            const bool DontSuppressRecordErrors = false;

            BevNetRecords = FileReaderGeneric <PriceFile> .ReadFile
                                (PathAndFile : PathAndFile
                                , SupressRecordErrors : DontSuppressRecordErrors
                                );

            int MaxRecordsToDisplay = 10;

            for (int i = 0; i < MaxRecordsToDisplay; i++)
            {
                Console.WriteLine((BevNetRecords.Skip(i).FirstOrDefault() ?? new PriceFile()).PROD_ITEM);
            }

            Console.WriteLine($"Path: {config["SourceDirectory"]}");

            Console.WriteLine("Loading Inventory From Real Windward");

            IEnumerable <IS5InvAssembled> InvAss = GetDataFromSystemFive(config);

            Console.WriteLine("Finished - Loading Inventory From Real Windward");

            // A: Get XRef from Account for AUnique,BankInfo pairs
            IEnumerable <QryAccount> accts = GetXRefFromSupplierRecords(config);

            // B: Attach BankInfo / wholesaler to Assembled Inventory to make InvAss, wholesaler pairs
            //   GenericJoins service will do this
            IEnumerable <Tuple <IS5InvAssembled, QryAccount> > result = MakePairs(InvAss, accts);

            // C: create a facade to go from InvAss, wholesaler pairs to a data load format
            IEnumerable <AdaptToDataLoadFormat> adapters = result.Select(p =>
            {
                AdaptToDataLoadFormat tmp = new AdaptToDataLoadFormat();
                tmp.Init(new ValueTuple <IS5InvAssembled, QryAccount>(p.Item1, p.Item2));
                return(tmp);
            }
                                                                         );

            // At this point I believe I can focus on putting into CSV file. So implement ICopyable<T>
            IEnumerable <DataLoadFormat> DataLoad = adapters.Select(a =>
            {
                DataLoadFormat tmp = new DataLoadFormat();
                tmp.CopyFrom(a); // .CopyFrom is from ICopyable
                tmp.SupplierPartNumber   = tmp.SupplierPartNumber.TrimEnd();
                tmp.S5Orig_ListPrice     = a.PriceSchedule1_MSRP;
                tmp.S5Orig_MinPrice      = a.PriceSchedule2_MinPrice;
                tmp.S5Orig_WholesaleCost = a.WholesaleCost;
                return(tmp);
            });


            // D: create an adapter to go from the data load format to Common fields - PriceFileAdapter

            // E: get common fields from BevNets PriceFileAdapter


            // F: apply rehydrator to step Ds adapter and step Es common fields
            Rehydrater <PriceFile_Clean, IPriceFile, CommonFields, ICommonFields, PriceFileAdapter
                        , (string SupplierCode, string SupplierPart)> rehydrater;

            rehydrater = new Rehydrater <PriceFile_Clean, IPriceFile, CommonFields, ICommonFields, PriceFileAdapter
                                         , (string SupplierCode, string SupplierPart)>();

            List <(IPriceFile IFrom, ICommonFields ITo)> pairs = new List <(IPriceFile, ICommonFields)>();
            //  - Assemble pairs of matching records that need to be updated from each other.
            //      - DataLoadFormat is ICommonFields
            //      - BevNetRecords is IPriceFile
            //      - Join them together into pairs and perorm the update
            Func <ICommonFields, (string SupplierCode, string SupplierPart)> keyDataLoad = (common) =>
            {
                return(new ValueTuple <string, string>(common.SupplierCode.ToUpper(), common.SupplierPartNumber));
            };
            Func <IPriceFile, ValueTuple <string, string> > keyBevNet = (priceRecord) =>
            {
                return(new ValueTuple <string, string>(priceRecord.WHOLESALER.ToUpper(), priceRecord.PROD_ITEM));
            };

            IEnumerable <Tuple <IPriceFile, ICommonFields> > updatePairs
                = GenericJoins <IPriceFile, ICommonFields, (string SupplierCode, string SupplierPart)>
                  .InnerJoin(BevNetRecords, DataLoad, keyBevNet, keyDataLoad);

            pairs = updatePairs.Select(p => new ValueTuple <IPriceFile, ICommonFields>(p.Item1, p.Item2)).ToList();

            rehydrater.From_To_Pairs = pairs;
            rehydrater.UpdateIntegrationRecords();
            DataLoad = rehydrater.From_To_Pairs.Select(p => (DataLoadFormat)p.Item2);
            // Write the file
            var engine = new FileHelperAsyncEngine <DataLoadFormat>();

            using (engine.BeginWriteFile(config["SourceDirectory"] + "S5InventoryDataLoad.csv"))
            {
                foreach (var record in DataLoad)
                {
                    record.Change_ListPrice     = record.PriceSchedule1_MSRP - record.S5Orig_ListPrice;
                    record.Change_MinPrice      = record.PriceSchedule2_MinPrice - record.S5Orig_MinPrice;
                    record.Change_WholesaleCost = record.WholesaleCost - record.S5Orig_WholesaleCost;
                    engine.WriteNext(record);
                }
            }

            // G: export the resulting data load object to CSV

            Console.WriteLine("Done");
            Console.ReadKey();
        }