Example #1
0
        public void GetCheapestSpecialRate_NonSpecialRequest_ReturnNoApplicableRates()
        {
            // Arrange
            var entered = new DateTime(2020, 8, 10, 8, 0, 0);
            var exited  = new DateTime(2020, 8, 10, 17, 0, 0);

            using (var context = new RatesDbContext(options))
            {
                context.SpecialRates.Add(new SpecialRate
                {
                    Name                 = "Weekend Rate",
                    RateType             = RateType.Flat,
                    Rate                 = 10.00,
                    EnterFrom            = new DateTime(2000, 1, 1, 0, 0, 0),
                    EnterTo              = new DateTime(2000, 1, 2, 23, 59, 59),
                    ExitFrom             = new DateTime(2000, 1, 1, 0, 0, 0),
                    ExitTo               = new DateTime(2000, 1, 2, 23, 59, 59),
                    ApplicableDaysOfWeek = new List <DayOfWeek>
                    {
                        DayOfWeek.Saturday,
                        DayOfWeek.Sunday
                    }
                });
                context.SaveChanges();

                var _mockedParkingRateService = new ParkingRateService(context, _mapper, _mockedLogger.Object);

                // Act
                var response = _mockedParkingRateService.GetCheapestSpecialRate(entered, exited);

                // Assert
                Assert.Null(response);
            }
        }
Example #2
0
        public void GetStandardRate_2HrDuration_ReturnStandardRate()
        {
            // Arrange
            var entered = new DateTime(2020, 8, 8, 8, 0, 0);
            var exited  = new DateTime(2020, 8, 8, 10, 0, 0);

            using (var context = new RatesDbContext(options))
            {
                context.StandardRates.Add(new StandardRate
                {
                    Name        = "Standard Rate",
                    RateType    = RateType.Hourly,
                    Rate        = 5.00,
                    MaximumRate = 20.00
                });
                context.SaveChanges();

                var _mockedParkingRateService = new ParkingRateService(context, _mapper, _mockedLogger.Object);

                // Act
                var response = _mockedParkingRateService.GetStandardRate(entered, exited);

                // Assert
                Assert.NotNull(response);
                Assert.IsType <GetParkingRateResponse>(response);
                Assert.Equal(10.00, response.Total);
            }
        }
Example #3
0
        public void GetStandardRate_NoContextDbData_ThrowsNullException()
        {
            // Arrange
            var entered = new DateTime(2020, 8, 8, 8, 0, 0);
            var exited  = new DateTime(2020, 8, 8, 10, 0, 0);

            using (var context = new RatesDbContext(options))
            {
                var _mockedParkingRateService = new ParkingRateService(context, _mapper, _mockedLogger.Object);

                // Act & Assert
                Assert.Throws <NullReferenceException>(() => _mockedParkingRateService.GetStandardRate(entered, exited));
            }
        }
Example #4
0
 public RatesService(RatesDbContext ratesDbContext)
 {
     _ratesDbContext = ratesDbContext;
 }