Beispiel #1
0
        public void CsvSplit_CorrectlyCommaDelimitedQuotedString_ReturnsStringList()
        {
            //Arrange
            string        source       = "\"AccountOfficeReference\",\"Address1\",\"Address2\",\"Address3\",\"Address4\",\"Address5\",\"BacsReferenceNo\",\"BankAccountName\",\"BankAccountNo\",\"BankBranch\",\"BankName\",\"BankSortCode\",\"CompanyName\",\"CompanyNo\",\"CompanyWeeks\",\"FourWeeklyDivisor\",\"HourlyDivisor\",\"MonthlyDivisor\",\"PayFrequency\",\"PeriodsPerYear\",\"QuarterlyDivisor\",\"TaxDistrict\",\"TaxOfficeNo\",\"TaxReference\",\"TwoWeeklyDivisor\",\"WeeklyDivisor\",\"WebSystemType\",\"AdditionalReports\",\"EmailPayslips\",\"EmailReports\",\"OutputMethod\",\"P11D\",\"PaidByBacs\",\"PayByDirectDebit\",\"PayDay\",\"PensionByWeb\",\"PostMethod\",\"SecondaryBacs\",\"PrintReports\",\"PrintEEsPayslip\",\"PrintERsPayslip\",\"NormalPayDay\",\"OrganisationName\",\"EmployeeNoFormat\",\"PayslipERsPension1\",\"PayslipERsPension2\",\"PrintPaymentDate\",\"OmniSlip\"";
            List <string> expectedList = new List <string>()
            {
                "AccountOfficeReference", "Address1", "Address2", "Address3", "Address4", "Address5", "BacsReferenceNo", "BankAccountName", "BankAccountNo", "BankBranch", "BankName", "BankSortCode", "CompanyName", "CompanyNo", "CompanyWeeks", "FourWeeklyDivisor", "HourlyDivisor", "MonthlyDivisor", "PayFrequency", "PeriodsPerYear", "QuarterlyDivisor", "TaxDistrict", "TaxOfficeNo", "TaxReference", "TwoWeeklyDivisor", "WeeklyDivisor", "WebSystemType", "AdditionalReports", "EmailPayslips", "EmailReports", "OutputMethod", "P11D", "PaidByBacs", "PayByDirectDebit", "PayDay", "PensionByWeb", "PostMethod", "SecondaryBacs", "PrintReports", "PrintEEsPayslip", "PrintERsPayslip", "NormalPayDay", "OrganisationName", "EmployeeNoFormat", "PayslipERsPension1", "PayslipERsPension2", "PrintPaymentDate", "OmniSlip"
            };
            //Act
            var result = CsvLib.CsvSplit(source, true, true, ',', '"');

            //Assert
            result.Should().BeEquivalentTo(expectedList);
        }
Beispiel #2
0
        public static void ReadPayrollFile(string fileName)
        {
            var engine      = new CsvParser(fileName, true);
            var payrollList = new Csv.Type.Common.CommonCsvList <Csv.Type.Payroll.Payroll>();

            while (!engine.EndOfStream)
            {
                engine.ReadLine();

                if (engine.CsvHeader.Count == engine.CsvLine.Count)
                {
                    payrollList.Items.Add(PayrollData.GetLine(engine));
                    Console.WriteLine($"AccountOfficeReference  : {engine.CsvItem("AccountOfficeReference")}");
                    Console.WriteLine($"Address1  : {engine.CsvItem("Address1")}");
                    Console.WriteLine($"CompanyName   : {engine.CsvItem("CompanyName")}");
                    Console.WriteLine($"FourWeeklyDivisor   : {engine.CsvItem("FourWeeklyDivisor")}");
                    Console.WriteLine($"TaxDistrict   : {engine.CsvItem("TaxDistrict")}");
                    Console.WriteLine($"NormalPayDay   : {engine.CsvItem("NormalPayDay")}");
                    Console.WriteLine($"EmployeeNoFormat   : {engine.CsvItem("EmployeeNoFormat")}");
                    Console.WriteLine($"OmniSlip  : {engine.CsvItem("OmniSlip")}");
                    Console.WriteLine($"PrintPaymentDate  : {engine.CsvItem("PrintPaymentDate")}");

                    Console.WriteLine("-----------------------------------------------");
                }
                else if (engine.CsvLine.Count > 0 && engine.CsvLine[0].Contains("EOF"))
                {
                    payrollList.EndOfFile          = true;
                    payrollList.EndOfFileTimeStamp = (engine.CsvLine.Count < 2) ? "" : engine.CsvLine[1]?.ToString();
                    Console.WriteLine($"End of CSV File : Create TimeStamp @ {payrollList.EndOfFileTimeStamp}");
                }
                else
                {
                    Console.WriteLine($"Error line : { engine.ErrorRow}");
                }


                var x = new Csv.Type.Payroll.Payroll();
                CsvLib.WireupCSV <Csv.Type.Payroll.Payroll>(ref x, engine.CsvHeader, engine.CsvLine);
                var y = x.Address1;
            }

            Console.WriteLine($"Total Parsed Count : {payrollList.Count()}");
            Console.WriteLine(engine.CsvItem("Address2"));
        }