Beispiel #1
0
        public void ProcessMessage(Message message)
        {
            message.Formatter = new XmlMessageFormatter(
                new string[] { "System.String,mscorlib" }
                );
            string json = message.Body.ToString();

            log.Debug("ProcessMessage: Received msg: " + json);
            Cart             cart        = JsonConvert.DeserializeObject <Cart>(json);
            string           invoiceText = "Bondara Equipment Rental Service\n\n";
            RentalCalculator rc          = new RentalCalculator();
            Loyalty          loyalty     = new Loyalty();
            float            total       = 0;
            float            points      = 0;

            foreach (CartItem item in cart.getCartItems())
            {
                invoiceText += "Name: " + item.equipment.name;
                invoiceText += "\t\t\t\t Type: " + item.equipment.type;
                float price = rc.getRentalPrice(item.equipment.type, item.days);
                invoiceText += ", \t\t\t\t Rental Price: " + price + "\n\n\n";
                total       += price;
                points      += loyalty.getPoints(item.equipment.type);
                log.Debug("ProcessMessage: Eq Name:" + item.equipment.name + "|Type:" + item.equipment.type + "|Price:" + price);
            }
            invoiceText += "Total Price: " + total + "\n\n\n";
            invoiceText += "Loyalty Points earned: " + points + "\n";
            log.Debug("ProcessMessage: Total price: " + total + "|Points:" + points);
            FileWriter fw = new FileWriter();

            fw.WriteInvoice("Invoice.txt", invoiceText);
            log.Debug("ProcessMessage: Invoice generated at C:\\Bondora\\Invoices\\Invoice.txt");
        }
        public void TestHeavyEquipmentRentalOneDay()
        {
            RentalCalculator rc = new RentalCalculator();
            OneTime          ot = new OneTime();
            Premium          pr = new Premium();
            int   days          = 1;
            float shouldBe      = ot.getFees() + pr.getFees(1);

            Assert.AreEqual(rc.getRentalPrice(EquipmentType.Heavy, days), shouldBe);
        }
        public void TestSpecializedEquipmentRentalMoreThanTwoDays()
        {
            RentalCalculator rc = new RentalCalculator();
            Regular          r  = new Regular();
            Premium          pr = new Premium();
            int   days          = 5;
            float shouldBe      = pr.getFees(3) + r.getFees(2);

            Assert.AreEqual(rc.getRentalPrice(EquipmentType.Specialized, days), shouldBe);
        }
        public void TestRegularEquipmentRentalTwoDays()
        {
            RentalCalculator rc = new RentalCalculator();
            OneTime          ot = new OneTime();
            Premium          pr = new Premium();
            int   days          = 2;
            float shouldBe      = ot.getFees() + pr.getFees(days);

            Assert.AreEqual(rc.getRentalPrice(EquipmentType.Regular, days), shouldBe);
        }
        public void RentalCalculator_GivenCars_ReturnsValue()
        {
            var vehicleFactory   = new VehicleFactory();
            var rentalCalculator = new RentalCalculator(vehicleFactory);

            var rents = new List <Rent.Rent>()
            {
                new Rent.Rent()
                {
                    VehicleType = VehicleTypeEnum.Car,
                    EstimateKm  = 60,
                    Optionals   = new List <VehicleOptionalEnum>()
                    {
                        VehicleOptionalEnum.Gps
                    },
                    StartDate = new DateTime(2019, 10, 21, 11, 0, 0),
                    StopDate  = new DateTime(2019, 10, 23, 15, 0, 0)
                },
                new Rent.Rent()
                {
                    VehicleType = VehicleTypeEnum.MotorHome,
                    EstimateKm  = 850,
                    Optionals   = new List <VehicleOptionalEnum>()
                    {
                        VehicleOptionalEnum.Gps,
                        VehicleOptionalEnum.Fridge
                    },
                    StartDate = new DateTime(2019, 10, 21, 17, 0, 0),
                    StopDate  = new DateTime(2019, 10, 23, 09, 0, 0)
                }
            };

            var result = rentalCalculator.Calculate(rents);

            Assert.AreEqual(2, result.RentResults.Count);

            var car = result.RentResults[0];

            Assert.AreEqual(2, car.TotalDays);
            Assert.AreEqual(50M, car.Vehicle.DailyRate);
            Assert.AreEqual(30M, car.EstimateKmValue);
            Assert.AreEqual(1, car.Optionals.Count);
            Assert.AreEqual(25M, car.Optionals.First(x => x.Type == VehicleOptionalEnum.Gps).Rate);
            Assert.AreEqual(155M, car.TotalValue);

            var motorHome = result.RentResults[1];

            Assert.AreEqual(2, motorHome.TotalDays);
            Assert.AreEqual(600M, motorHome.TotalDaysValue);
            Assert.AreEqual(552.5M, motorHome.EstimateKmValue);
            Assert.AreEqual(2, motorHome.Optionals.Count);
            Assert.AreEqual(35M, motorHome.Optionals.First(x => x.Type == VehicleOptionalEnum.Gps).Rate);
            Assert.AreEqual(250M, motorHome.Optionals.First(x => x.Type == VehicleOptionalEnum.Fridge).Rate);
            Assert.AreEqual(1437.5M, motorHome.TotalValue);
        }