Ejemplo n.º 1
0
        public void ShouldFailOnApplicationDate()
        {
            var sut = new AverageIncomeRequestValidator();

            var req = new AverageIncomeRequest()
            {
                Roe = new SimpleRoe()
                {
                    PayPeriods = new List <PayPeriod>()
                    {
                        new PayPeriod(1, 1000)
                    },
                    LastDayForWhichPaid  = new DateTime(2020, 11, 5),
                    FinalPayPeriodDay    = new DateTime(2020, 11, 30),
                    FirstDayForWhichPaid = new DateTime(2019, 7, 4),
                    PayPeriodType        = "weekly"
                },
                ApplicationDate = DateTime.Now.AddDays(10),
                NumBestWeeks    = 12
            };

            Action act = () => sut.Validate(req);
            var    ex  = Assert.Throws <ValidationException>(act);

            Assert.Contains("Application date", ex.Message);
        }
Ejemplo n.º 2
0
        public decimal Calculate(AverageIncomeRequest request)
        {
            var fullRoe    = _fullRoeCreator.Create(request.Roe);
            var incomeList = _incomeListGetter.Get(request.ApplicationDate, fullRoe);

            incomeList.Sort((a, b) => b.CompareTo(a));
            var result = incomeList.Take(request.NumBestWeeks).Average();

            return(result);
        }
Ejemplo n.º 3
0
 public ActionResult <AverageIncomeResponse> Calculate(AverageIncomeRequest request)
 {
     try {
         var result = _requestHandler.Handle(request);
         return(Ok(result));
     } catch (ValidationException ex) {
         _logger.LogError(ex, ex.Message);
         return(BadRequest(new { error = ex.Message }));
     }
 }
        public void ShouldWorkForSemiMonthly()
        {
            // Arrange
            var sut = GetSut();
            var roe = new SimpleRoe()
            {
                LastDayForWhichPaid  = new DateTime(2021, 4, 3),
                FinalPayPeriodDay    = new DateTime(2021, 4, 15),
                FirstDayForWhichPaid = new DateTime(2018, 6, 5),
                PayPeriods           = new List <PayPeriod>()
                {
                    new PayPeriod(1, 200),
                    new PayPeriod(2, 1100),
                    new PayPeriod(3, 1100),
                    new PayPeriod(4, 1000),
                    new PayPeriod(5, 1300),
                    new PayPeriod(6, 1000),
                    new PayPeriod(7, 1100),
                    new PayPeriod(8, 600),
                    new PayPeriod(9, 0),
                    new PayPeriod(10, 0),
                    new PayPeriod(11, 500),
                    new PayPeriod(12, 900),
                    new PayPeriod(13, 900),
                    new PayPeriod(14, 1100),
                    new PayPeriod(15, 1100),
                    new PayPeriod(16, 1200),
                    new PayPeriod(17, 1200),
                    new PayPeriod(18, 1200),
                    new PayPeriod(19, 1300),
                    new PayPeriod(20, 1100),
                    new PayPeriod(21, 1100),
                    new PayPeriod(22, 1100),
                    new PayPeriod(23, 1050),
                    new PayPeriod(24, 1000),
                    new PayPeriod(25, 900),
                },
                PayPeriodType = "semi-monthly"
            };

            var req = new AverageIncomeRequest()
            {
                Roe             = roe,
                NumBestWeeks    = 20,
                ApplicationDate = new DateTime(2021, 5, 2),
            };

            // Act
            var result = sut.Calculate(req);

            // Assert
            Assert.InRange(result, 540, 545);
        }
Ejemplo n.º 5
0
        public void ShouldWorkNormally()
        {
            // Arrange
            var simpleRoe = new SimpleRoe()
            {
                PayPeriodType        = ppTypes.MONTHLY,
                FirstDayForWhichPaid = new DateTime(2021, 2, 10),
                LastDayForWhichPaid  = new DateTime(2021, 3, 27),
                FinalPayPeriodDay    = new DateTime(2021, 3, 31),
                PayPeriods           = new List <PayPeriod>()
                {
                    new PayPeriod(1, 1000),
                    new PayPeriod(2, 2000)
                }
            };

            var fullRoeCreator   = A.Fake <ICreateFullRoes>();
            var incomeListGetter = A.Fake <IGetIncomeList>();

            var fullRoe    = A.Fake <FullRoe>();
            var incomeList = new List <decimal>()
            {
                3, -33.3M, 9, 9.999M, 10, 14, 8.8M, 16.5M, 7
            };

            A.CallTo(() => fullRoeCreator.Create(A <SimpleRoe> ._))
            .Returns(fullRoe);

            A.CallTo(() => incomeListGetter.Get(A <DateTime> ._, A <FullRoe> ._))
            .Returns(incomeList);


            var sut = new AverageIncomeCalculator(fullRoeCreator, incomeListGetter);

            // Act
            var req = new AverageIncomeRequest()
            {
                NumBestWeeks    = 3,
                Roe             = A.Fake <SimpleRoe>(),
                ApplicationDate = DateTime.Now,
            };
            var result = sut.Calculate(req);

            // Assert
            A.CallTo(() => fullRoeCreator.Create(A <SimpleRoe> ._))
            .MustHaveHappenedOnceExactly();

            A.CallTo(() => incomeListGetter.Get(req.ApplicationDate, A <FullRoe> ._))
            .MustHaveHappenedOnceExactly();

            Assert.Equal(13.5M, result);
        }
        public void ShouldWorkForMonthly()
        {
            // Arrange
            var sut = GetSut();
            var roe = new SimpleRoe()
            {
                LastDayForWhichPaid  = new DateTime(2021, 4, 17),
                FinalPayPeriodDay    = new DateTime(2021, 4, 30),
                FirstDayForWhichPaid = new DateTime(2018, 6, 5),
                PayPeriods           = new List <PayPeriod>()
                {
                    new PayPeriod(1, 2300),
                    new PayPeriod(2, 3400),
                    new PayPeriod(3, 3400),
                    new PayPeriod(4, 3400),
                    new PayPeriod(5, 2500),
                    new PayPeriod(6, 3100),
                    new PayPeriod(7, 3400),
                    new PayPeriod(8, 3400),
                    new PayPeriod(9, 3400),
                    new PayPeriod(10, 3000),
                    new PayPeriod(11, 2900),
                    new PayPeriod(12, 3400),
                    new PayPeriod(13, 3400),
                },
                PayPeriodType = "monthly"
            };

            var req = new AverageIncomeRequest()
            {
                Roe             = roe,
                NumBestWeeks    = 14,
                ApplicationDate = new DateTime(2021, 5, 2),
            };

            // Act
            var result = sut.Calculate(req);

            // Assert
            Assert.InRange(result, 830, 835);
        }
        public void ShouldWorkForBiWeekly()
        {
            // Arrange
            var sut = GetSut();
            var roe = new SimpleRoe()
            {
                LastDayForWhichPaid  = new DateTime(2020, 9, 18),
                FinalPayPeriodDay    = new DateTime(2020, 9, 19),
                FirstDayForWhichPaid = new DateTime(2020, 4, 6),
                PayPeriods           = new List <PayPeriod>()
                {
                    new PayPeriod(1, 1800),
                    new PayPeriod(2, 1800),
                    new PayPeriod(3, 1800),
                    new PayPeriod(4, 750),
                    new PayPeriod(5, 0),
                    new PayPeriod(6, 450),
                    new PayPeriod(7, 1800),
                    new PayPeriod(8, 1800),
                    new PayPeriod(9, 1800),
                    new PayPeriod(10, 1800),
                    new PayPeriod(11, 1800),
                    new PayPeriod(12, 1100)
                },
                PayPeriodType = "bi-weekly"
            };

            var req = new AverageIncomeRequest()
            {
                Roe             = roe,
                NumBestWeeks    = 20,
                ApplicationDate = new DateTime(2020, 10, 4),
            };

            // Act
            var result = sut.Calculate(req);

            // Assert
            Assert.InRange(result, 810, 815);
        }
Ejemplo n.º 8
0
        public void ShouldPassValidation()
        {
            var sut = new AverageIncomeRequestValidator();

            var req = new AverageIncomeRequest()
            {
                Roe = new SimpleRoe()
                {
                    PayPeriods = new List <PayPeriod>()
                    {
                        new PayPeriod(1, 1000)
                    },
                    LastDayForWhichPaid  = new DateTime(2020, 11, 5),
                    FinalPayPeriodDay    = new DateTime(2020, 11, 30),
                    FirstDayForWhichPaid = new DateTime(2019, 7, 4),
                    PayPeriodType        = "weekly"
                },
                ApplicationDate = new DateTime(2020, 12, 1),
                NumBestWeeks    = 12
            };

            sut.Validate(req);
        }
        public void ShouldWorkForWeekly()
        {
            // Arrange
            var sut = GetSut();
            var roe = new SimpleRoe()
            {
                LastDayForWhichPaid  = new DateTime(2020, 9, 18),
                FinalPayPeriodDay    = new DateTime(2020, 9, 19),
                FirstDayForWhichPaid = new DateTime(2019, 4, 6),
                PayPeriods           = new List <PayPeriod>()
                {
                    new PayPeriod(1, 500),
                    new PayPeriod(2, 530),
                    new PayPeriod(3, 520),
                    new PayPeriod(4, 510),
                    new PayPeriod(5, 0),
                    new PayPeriod(6, 450),
                    new PayPeriod(7, 470),
                    new PayPeriod(8, 520),
                    new PayPeriod(9, 520),
                    new PayPeriod(10, 520),
                    new PayPeriod(11, 520),
                    new PayPeriod(12, 520),
                    new PayPeriod(13, 520),
                    new PayPeriod(14, 540),
                    new PayPeriod(15, 500),
                    new PayPeriod(16, 550),
                    new PayPeriod(17, 0),
                    new PayPeriod(18, 450),
                    new PayPeriod(19, 500),
                    new PayPeriod(20, 500),
                    new PayPeriod(21, 500),
                    new PayPeriod(22, 500),
                    new PayPeriod(23, 520),
                    new PayPeriod(24, 520),
                    new PayPeriod(25, 520),
                    new PayPeriod(26, 580),
                    new PayPeriod(27, 580),
                    new PayPeriod(28, 600),
                    new PayPeriod(29, 600),
                    new PayPeriod(30, 610),
                    new PayPeriod(31, 610),
                    new PayPeriod(32, 610),
                    new PayPeriod(33, 610),
                    new PayPeriod(34, 610),
                    new PayPeriod(35, 630),
                    new PayPeriod(36, 630),
                    new PayPeriod(37, 630),
                    new PayPeriod(38, 630),
                    new PayPeriod(39, 630),
                    new PayPeriod(40, 700),
                    new PayPeriod(41, 700),
                    new PayPeriod(42, 700),
                    new PayPeriod(43, 700),
                    new PayPeriod(44, 700),
                    new PayPeriod(45, 700),
                    new PayPeriod(46, 700),
                    new PayPeriod(47, 700),
                    new PayPeriod(48, 700),
                    new PayPeriod(49, 700),
                    new PayPeriod(50, 700),
                    new PayPeriod(51, 700),
                    new PayPeriod(52, 700),
                    new PayPeriod(53, 750)
                },
                PayPeriodType = "weekly"
            };

            var req = new AverageIncomeRequest()
            {
                Roe             = roe,
                NumBestWeeks    = 14,
                ApplicationDate = new DateTime(2020, 10, 4),
            };

            // Act
            var result = sut.Calculate(req);

            // Assert
            Assert.InRange(result, 680, 690);
        }