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);
        }