コード例 #1
0
        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}");
                }
            }
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
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.");
        }