public void RentalFamilyTestFailNoPromotion()
        {
            //Creates the collection of rentals
            List <IRental> listRentals = new List <IRental>();

            listRentals.Add(new RentalHour()
            {
                cantRent = 9
            });
            listRentals.Add(new RentalDay()
            {
                cantRent = 3
            });

            FamilyRental rf = new FamilyRental(listRentals);

            try
            {
                //The function calculation for the total of the cost
                double totalCost = rf.CalcCost();
                Assert.Fail("Without promocion");
            }
            catch (Exception ex)
            {
                // whatever logging code
            }
        }
Exemple #2
0
        public void Should_not_get_price_minrentals()
        {
            var rentService = _configurationService.GetInstance <IRentaislService>();

            var rentals = new List <Rental>();

            FamilyRental familyRental = new FamilyRental();

            try
            {
                familyRental.AddRental(new RentalByDay {
                    Amount = 1, Id = 1
                });
                familyRental.AddRental(new RentalByDay {
                    Amount = 1, Id = 1
                });

                var price = familyRental.Price;
            }
            catch (InvalidFamilyRentalException ex)
            {
                Assert.IsTrue(0 == 0);

                return;
            }

            Assert.IsTrue(0 != 0);
        }
        public void RentalFamilyTest()
        {
            //Creates the collection of rentals
            List <IRental> listRentals = new List <IRental>();

            listRentals.Add(new RentalHour()
            {
                cantRent = 9
            });
            listRentals.Add(new RentalDay()
            {
                cantRent = 3
            });
            listRentals.Add(new RentalWeek()
            {
                cantRent = 12
            });

            FamilyRental rf = new FamilyRental(listRentals);

            //The function calculation for the total of the cost
            double totalCost = rf.CalcCost();

            Assert.AreEqual(totalCost, 577.5);
        }
        public void SetUp()
        {
            this.MockClient = new Mock <IClient>();

            this.MockRental1 = new Mock <IRental>();
            this.MockRental2 = new Mock <IRental>();
            this.MockRental3 = new Mock <IRental>();
            this.MockRental4 = new Mock <IRental>();
            IList <IRental> rentals = new List <IRental>();

            rentals.Add(this.MockRental1.Object);
            rentals.Add(this.MockRental2.Object);
            rentals.Add(this.MockRental3.Object);
            rentals.Add(this.MockRental4.Object);

            PromotionRules familyRentalRules = new PromotionRules(TestsConstants.FAMILY_RENTAL_TERMS_AND_CONDITIONS,
                                                                  new DateTime(TestsConstants.FAMILY_RENTAL_EFFECTIVE_DATE_YEAR, TestsConstants.FAMILY_RENTAL_EFFECTIVE_DATE_MONTH,
                                                                               TestsConstants.FAMILY_RENTAL_EFFECTIVE_DATE_DAY, 0, 0, 0),
                                                                  new DateTime(TestsConstants.FAMILY_RENTAL_EXPIRATON_DATE_YEAR, TestsConstants.FAMILY_RENTAL_EXPIRATON_DATE_MONTH,
                                                                               TestsConstants.FAMILY_RENTAL_EXPIRATON_DATE_DAY, 0, 0, 0));
            FamilyRentalInformation familyRentalInformation = new FamilyRentalInformation(
                TestsConstants.FAMILY_RENTAL_DISCOUNT_PERCENT, TestsConstants.FAMILY_RENTAL_MINIMUM_RENTALS,
                TestsConstants.FAMILY_RENTAL_MAXIMUM_RENTALS, familyRentalRules);

            this.FamilyRental = new FamilyRental(this.MockClient.Object, familyRentalInformation, rentals);
        }
Exemple #5
0
        public void FamilyRental_CalculatePrice_RentalListFull_Succeeds()
        {
            //Arrange
            decimal      discount      = new decimal(0.30);
            Rental       rentalByHour  = new Rental(5, 3);
            Rental       rentalByDay   = new Rental(20, 2);
            Rental       rentalByWeek  = new Rental(60, 1);
            FamilyRental familyRental  = new FamilyRental(discount);
            FamilyRental familyRental2 = new FamilyRental(discount);

            familyRental2.AddRental(rentalByHour);
            familyRental2.AddRental(rentalByDay);
            familyRental2.AddRental(rentalByWeek);

            familyRental.AddRental(rentalByHour);
            familyRental.AddRental(rentalByDay);
            familyRental.AddRental(rentalByWeek);
            familyRental.AddRental(familyRental2);

            //Act
            var result = familyRental.CalculatePrice();

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(136.85, (double)result);
        }
Exemple #6
0
        public void TestAvailableSlots()
        {
            var familyRental = new FamilyRental();

            Assert.AreEqual(familyRental.AvailableSlots, 5);
            familyRental.AddRental(_rentals[0]);
            Assert.AreEqual(familyRental.AvailableSlots, 4);
        }
Exemple #7
0
        public void TestByFamilyRental()
        {
            FamilyRental fr = new FamilyRental();

            fr.AddRental(CreateHourRental());
            fr.AddRental(CreateDayRental());
            Assert.AreEqual(fr.Rent(), 63);
        }
Exemple #8
0
        public void TestByFamilyRentalInvalid()
        {
            FamilyRental rf = new FamilyRental();

            rf.AddRental(CreateHourRental());
            rf.AddRental(CreateDayRental());
            rf.AddRental(CreateWeekRental());
            Assert.AreEqual(rf.Rent(), 63);
        }
Exemple #9
0
        public void TestAddExcess()
        {
            var familyRental = new FamilyRental();
            var rentals      = _rentals.Take(5).ToList();

            foreach (var r in rentals)
            {
                familyRental.AddRental(r);
            }
            Assert.ThrowsException <RentalException>(() => familyRental.AddRental(rentals.Last()));
        }
Exemple #10
0
        public void TestIsValid()
        {
            var familyRental = new FamilyRental();
            var rentals      = _rentals.Take(5).ToList();

            foreach (var r in rentals)
            {
                familyRental.AddRental(r);
            }
            Assert.IsTrue(familyRental.IsValid());
        }
Exemple #11
0
        public void FamilyRental_Constructor_DiscountInRange_Succeeds()
        {
            //Arrange
            decimal discount = new decimal(0.10);

            //Act
            FamilyRental familyRental = new FamilyRental(discount);

            //Assert
            Assert.IsNotNull(familyRental);
        }
Exemple #12
0
        public void TestBeginDate()
        {
            var familyRental = new FamilyRental();

            familyRental.AddRental(new HourlyRental {
                BeginDate = _baseDate
            });
            familyRental.AddRental(new HourlyRental {
                BeginDate = _baseDate.AddDays(-5)
            });
            Assert.AreEqual(familyRental.BeginDate, _baseDate.AddDays(-5));
        }
Exemple #13
0
        public void FamilyRental_RemoveRental_RentalListEmpty_Fials()
        {
            //Arrange
            decimal      discount     = new decimal(0.30);
            int          pricePerUnit = 5;
            decimal      units        = 3;
            Rental       rental       = new Rental(pricePerUnit, units);
            FamilyRental familyRental = new FamilyRental(discount);

            //Act & Assert
            Assert.ThrowsException <IndexOutOfRangeException>(() => familyRental.RemoveRental(rental));
        }
Exemple #14
0
        public void TestEndDate()
        {
            var familyRental = new FamilyRental();

            familyRental.AddRental(new HourlyRental {
                BeginDate = _baseDate, EndDate = _baseDate.AddHours(8)
            });
            familyRental.AddRental(new HourlyRental {
                BeginDate = _baseDate, EndDate = _baseDate.AddHours(3)
            });
            Assert.AreEqual(familyRental.EndDate, _baseDate.AddHours(8));
        }
Exemple #15
0
        public void ProvideFamilyRentalWithAmountsOk()
        {
            // I force the 3 and 5 to control the amount of rentals allowed and not depend on the constants
            FamilyRentalInformation familyRentalInformation = new FamilyRentalInformation(
                TestsConstants.FAMILY_RENTAL_DISCOUNT_PERCENT, 3, 5, this.FamilyRentalRules);

            this.RentalOperator.UpdateCurrentFamilyRentalInformation(familyRentalInformation);

            IClient father   = new Client();
            IClient mother   = new Client();
            IClient son      = new Client();
            IClient daughter = new Client();

            IList <IClient> clients = new List <IClient>();

            clients.Add(mother);
            clients.Add(father);
            clients.Add(son);
            clients.Add(daughter);

            Bike bike2 = new Bike("YGR496", this.BikeSpecifications);
            BikeSpecifications bikeSpecifications3 = new BikeSpecifications("Trek", "Madone", "Green");
            Bike bike3 = new Bike("JWT764", bikeSpecifications3);
            BikeSpecifications bikeSpecifications4 = new BikeSpecifications("Santa Cruz", "V10", "Brown");
            Bike bike4 = new Bike("MTN858", bikeSpecifications4);

            IList <Bike> bikes = new List <Bike>();

            bikes.Add(this.Bike);
            bikes.Add(bike2);
            bikes.Add(bike3);
            bikes.Add(bike4);

            IList <UnitOfTime> unitsOfTimes = new List <UnitOfTime>();

            unitsOfTimes.Add(UnitOfTime.Hour);
            unitsOfTimes.Add(UnitOfTime.Hour);
            unitsOfTimes.Add(UnitOfTime.Day);
            unitsOfTimes.Add(UnitOfTime.Day);

            FamilyRental familyRental = this.RentalOperator.ProvideFamilyRental(mother, clients, bikes, unitsOfTimes);

            Assert.AreEqual(mother, familyRental.Client);
            Assert.AreEqual(this.RentalOperator.CurrentFamilyRentalInformation, familyRental.Information);
            for (int i = 0; i < clients.Count; i++)
            {
                Assert.AreEqual(clients[i], familyRental.Rentals[i].Client);
                Assert.AreEqual(bikes[i], familyRental.Rentals[i].Bike);
                Assert.AreEqual(unitsOfTimes[i], familyRental.Rentals[i].Modality.UnitOfTime);
            }
        }
Exemple #16
0
        public void FamilyRental_GetRental_indexOutOfRange_Fails()
        {
            //Arrange
            decimal      discount     = new decimal(0.30);
            int          pricePerUnit = 5;
            decimal      units        = 3;
            Rental       rental       = new Rental(pricePerUnit, units);
            FamilyRental familyRental = new FamilyRental(discount);

            familyRental.AddRental(rental);

            //Act & Assert
            Assert.ThrowsException <IndexOutOfRangeException>(() => familyRental.GetRental(1));
        }
Exemple #17
0
        public void TestGetPrice()
        {
            var familyRental = new FamilyRental();
            var rentals      = _rentals.Take(3).ToList();

            foreach (var r in rentals)
            {
                familyRental.AddRental(r);
            }
            var expectedPrice = (15m + 60m + 180m);

            expectedPrice -= expectedPrice * 0.3m;
            Assert.AreEqual(familyRental.GetPrice(), expectedPrice);
        }
Exemple #18
0
        public void FamilyRental_CalculatePrice_RentalListNotFull_Fails()
        {
            //Arrange
            decimal      discount     = new decimal(0.30);
            Rental       rentalByHour = new Rental(5, 3);
            Rental       rentalByDay  = new Rental(20, 2);
            Rental       rentalByWeek = new Rental(60, 1);
            FamilyRental familyRental = new FamilyRental(discount);

            familyRental.AddRental(rentalByHour);
            familyRental.AddRental(rentalByDay);

            //Act & Assert
            Assert.ThrowsException <IndexOutOfRangeException>(() => familyRental.CalculatePrice());
        }
Exemple #19
0
        public void TestIsNotFinished()
        {
            var familyRental = new FamilyRental();

            familyRental.AddRental(new HourlyRental {
                BeginDate = _baseDate, EndDate = _baseDate.AddHours(3)
            });
            familyRental.AddRental(new HourlyRental {
                BeginDate = _baseDate
            });
            familyRental.AddRental(new HourlyRental {
                BeginDate = _baseDate, EndDate = _baseDate.AddHours(3)
            });
            Assert.IsFalse(familyRental.IsFinished());
        }
Exemple #20
0
        public void FamilyRental_AddRental_RentalListNotFull_Succeeds()
        {
            //Arrange
            decimal      discount     = new decimal(0.30);
            int          pricePerUnit = 5;
            decimal      units        = 3;
            Rental       rental       = new Rental(pricePerUnit, units);
            FamilyRental familyRental = new FamilyRental(discount);

            //Act
            familyRental.AddRental(rental);

            //Assert
            Assert.AreEqual(1, familyRental.GetRentalCount());
        }
Exemple #21
0
        public void InitialSetup()
        {
            _nBikes = 1;
            _hours  = 3;
            _days   = 2;
            _weeks  = 1;

            _hourlyRental = new HourlyRental(_nBikes, _hours);
            _dailyRental  = new DailyRental(_nBikes, _days);
            _weeklyRental = new WeeklyRental(_nBikes, _weeks);

            _familyRental = new FamilyRental();
            _familyRental.AddRental(_hourlyRental);
            _familyRental.AddRental(_dailyRental);
            _familyRental.AddRental(_weeklyRental);
        }
Exemple #22
0
        public void TestRemove()
        {
            var familyRental = new FamilyRental();
            var rentals      = _rentals.Take(3).ToList();

            foreach (var r in rentals)
            {
                familyRental.AddRental(r);
            }
            Assert.AreEqual(familyRental.Rentals.Count(), 3);

            foreach (var r in rentals)
            {
                familyRental.RemoveRental(r);
            }
            Assert.AreEqual(familyRental.Rentals.Count(), 0);
        }
Exemple #23
0
        public void FamilyRental_GetRentalCount_AllParameters_Succeeds()
        {
            //Arrange
            decimal      discount     = new decimal(0.30);
            int          pricePerUnit = 5;
            decimal      units        = 3;
            Rental       rental       = new Rental(pricePerUnit, units);
            FamilyRental familyRental = new FamilyRental(discount);

            familyRental.AddRental(rental);

            //Act
            var result = familyRental.GetRentalCount();

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result);
        }
        public void RentalFamilyTestFailNoRentals()
        {
            //Creates the collection of rentals
            List <IRental> listRentals = new List <IRental>();

            FamilyRental rf = new FamilyRental(listRentals);

            try
            {
                //The function calculation for the total of the cost
                double totalCost = rf.CalcCost();
                Assert.Fail("Without rents");
            }
            catch (Exception ex)
            {
                // whatever logging code
            }
        }
Exemple #25
0
        public void RequestAFamilyRental()
        {
            List <IClient>     clients      = new List <IClient>();
            IList <Bike>       bikes        = new List <Bike>();
            IList <UnitOfTime> unitsOfTimes = new List <UnitOfTime>();

            for (int i = 0; i < this.RentalOperator.CurrentFamilyRentalInformation.MaximumRentals; i++)
            {
                clients.Add(new Client());
                bikes.Add(new Bike("AAA000", this.BikeSpecifications));
                unitsOfTimes.Add(UnitOfTime.Day);
            }

            FamilyRental familyRental = this.Client.RequestAFamilyRental(clients, bikes, unitsOfTimes, this.RentalOperator);

            Assert.AreEqual(this.Client, familyRental.Client);
            for (int i = 0; i < clients.Count; i++)
            {
                Assert.AreEqual(clients[i], familyRental.Rentals[i].Client);
                Assert.AreEqual(bikes[i], familyRental.Rentals[i].Bike);
                Assert.AreEqual(unitsOfTimes[i], familyRental.Rentals[i].Modality.UnitOfTime);
            }
        }
Exemple #26
0
        public void ProvideFamilyRentalWithAmountsEqualToMinimum()
        {
            IList <IClient>    clients      = new List <IClient>();
            IList <Bike>       bikes        = new List <Bike>();
            IList <UnitOfTime> unitsOfTimes = new List <UnitOfTime>();

            for (int i = 0; i < this.RentalOperator.CurrentFamilyRentalInformation.MinimumRentals; i++)
            {
                clients.Add(new Client());
                bikes.Add(new Bike("AAA000", this.BikeSpecifications));
                unitsOfTimes.Add(UnitOfTime.Day);
            }

            FamilyRental familyRental = this.RentalOperator.ProvideFamilyRental(clients[0], clients, bikes, unitsOfTimes);

            Assert.AreEqual(clients[0], familyRental.Client);
            Assert.AreEqual(this.RentalOperator.CurrentFamilyRentalInformation, familyRental.Information);
            for (int i = 0; i < clients.Count; i++)
            {
                Assert.AreEqual(clients[i], familyRental.Rentals[i].Client);
                Assert.AreEqual(bikes[i], familyRental.Rentals[i].Bike);
                Assert.AreEqual(unitsOfTimes[i], familyRental.Rentals[i].Modality.UnitOfTime);
            }
        }
Exemple #27
0
        public void Should_get_family_rental_price()
        {
            var rentService = _configurationService.GetInstance <IRentaislService>();

            var rentals = new List <Rental>();

            FamilyRental familyRental = new FamilyRental();

            familyRental.AddRental(new RentalByDay {
                Amount = 1, Id = 1
            });
            familyRental.AddRental(new RentalByDay {
                Amount = 1, Id = 1
            });
            familyRental.AddRental(new RentalByDay {
                Amount = 1, Id = 1
            });

            var price = familyRental.Price;


            // TODO: Calculate number from configuration file values.
            Assert.IsTrue(price == 42);

            familyRental = new FamilyRental();

            familyRental.AddRental(new RentalByDay {
                Amount = 1, Id = 1
            });
            familyRental.AddRental(new RentalByDay {
                Amount = 1, Id = 1
            });
            familyRental.AddRental(new RentalByDay {
                Amount = 1, Id = 1
            });
            familyRental.AddRental(new RentalByDay {
                Amount = 1, Id = 1
            });

            price = familyRental.Price;

            // TODO: Calculate number from configuration file values.
            Assert.IsTrue(price == 56);

            familyRental = new FamilyRental();

            familyRental.AddRental(new RentalByDay {
                Amount = 1, Id = 1
            });
            familyRental.AddRental(new RentalByDay {
                Amount = 1, Id = 1
            });
            familyRental.AddRental(new RentalByDay {
                Amount = 1, Id = 1
            });
            familyRental.AddRental(new RentalByDay {
                Amount = 1, Id = 1
            });
            familyRental.AddRental(new RentalByDay {
                Amount = 1, Id = 1
            });

            price = familyRental.Price;

            Assert.IsTrue(price == 70);
        }