public void ReadRecords_CSVFile_ReturnResult()
        {
            FileStream inputFile = PayslipExtension.ReadInputFile();

            Employee[] EmployeeRecords = new[]
            {
                new Employee
                {
                    FirstName        = "David",
                    LastName         = "Rudd",
                    AnnualSalary     = 60050M,
                    SuperRate        = 0.09M,
                    PaymentStartDate = new PaymentPeriod(new DateTime(DateTime.Now.Year, 3, 1), new DateTime(DateTime.Now.Year, 3, 31))
                }
            };
            var EmployeeRecordsinFile = new EmployeeRecords().ReadRecords <Employee>(inputFile).ToArray();

            for (int i = 0; i < EmployeeRecords.Length; i++)
            {
                Assert.Equal(EmployeeRecords[i].FirstName, EmployeeRecordsinFile[i].FirstName);
                Assert.Equal(EmployeeRecords[i].LastName, EmployeeRecordsinFile[i].LastName);
                Assert.Equal(EmployeeRecords[i].AnnualSalary, EmployeeRecordsinFile[i].AnnualSalary);
                Assert.Equal(EmployeeRecords[i].SuperRate, EmployeeRecordsinFile[i].SuperRate);
                Assert.Equal(EmployeeRecords[i].PaymentStartDate.EndDate, EmployeeRecordsinFile[i].PaymentStartDate.EndDate);
                Assert.Equal(EmployeeRecords[i].PaymentStartDate.StartDate, EmployeeRecordsinFile[i].PaymentStartDate.StartDate);
            }
        }
        public void WritePayslipRecords_ReadHeader()
        {
            PaySlip[] payslips = new[]
            {
                new PaySlip
                {
                    Name        = PayslipExtension.RandomString(),
                    PayPeriod   = PayslipExtension.RandomString(),
                    GrossIncome = 1245678M,
                    IncomeTax   = 4567M,
                    NetIncome   = 1245678M,
                    Super       = 1245M
                }
            };

            //Writing to Bytes
            Byte[] recordByte = new EmployeeRecords().WriteRecordsToBytes(payslips);
            //Read and verify records
            using (StreamReader reader = new StreamReader(new MemoryStream(recordByte)))
            {
                //First line is the header
                var Header = reader.ReadLine();
                Assert.Equal("Name,PayPeriod,GrossIncome,IncomeTax,NetIncome,Super", Header);
            }
        }
        public void WritePayslipRecords_ReadRecords()
        {
            PaySlip[] payslips = new[]
            {
                new PaySlip
                {
                    Name        = PayslipExtension.RandomString(),
                    PayPeriod   = PayslipExtension.RandomString(),
                    GrossIncome = 1245678M,
                    IncomeTax   = 4567M,
                    NetIncome   = 1245678M,
                    Super       = 1245M
                }
            };

            //Writing to Bytes
            Byte[] recordByte = new EmployeeRecords().WriteRecordsToBytes(payslips);
            //Read and verify records
            using (StreamReader reader = new StreamReader(new MemoryStream(recordByte)))
            {
                //First line is the header
                var Header = reader.ReadLine();
                foreach (var payrecord in payslips)
                {
                    var item = reader.ReadLine();
                    Assert.Equal(item, $"{payrecord.Name},{payrecord.PayPeriod},{payrecord.GrossIncome},{payrecord.IncomeTax},{payrecord.NetIncome},{payrecord.Super}");
                }
            }
        }
Ejemplo n.º 4
0
        public void Calculate_EmployeeAnnualSalary_ReturnsValidationError()
        {
            var     validation   = new Validation();
            decimal annualSalary = 1.5M;
            var     employee     = new Employee(PayslipExtension.RandomString(), PayslipExtension.RandomString(), annualSalary, 0M, new PaymentPeriod(new DateTime(2019, 2, 01), new DateTime(2019, 2, 28)));

            PayslipExtension.BuildPayslip().Calculate(new[] { employee }, validation);
            //validation.Errors
            var Errors = validation.Errors.FirstOrDefault();

            Assert.Equal(Errors, $"{nameof(annualSalary)}, value:{annualSalary}  must be a whole number.");
        }
Ejemplo n.º 5
0
        public void CalculateRecords_ReturnTrue()
        {
            FileStream inputFile  = PayslipExtension.ReadInputFile();
            var        validation = new Validation();

            Employee[] EmployeeRecords = new[]
            {
                new Employee
                {
                    FirstName        = "David",
                    LastName         = "Rudd",
                    AnnualSalary     = 60050M,
                    SuperRate        = 0.09M,
                    PaymentStartDate = new PaymentPeriod(new DateTime(DateTime.Now.Year, 3, 1), new DateTime(DateTime.Now.Year, 3, 31))
                }
            };

            PayslipExtension.BuildPayslip().Calculate(EmployeeRecords, validation);

            Assert.True(validation.IsValid);
        }