static void Main(string[] args) { DateTime date = new DateTime(2020,12,12); List<IPriceRule> pricingRules = new List<IPriceRule>(); pricingRules.Add(new OnePersonPerRoomPriceRule()); pricingRules.Add(new TwoPersonsPerRoomPriceRule()); pricingRules.Add(new TVAPriceRule()); pricingRules.Add(new SeeSideRoomPriceRule()); pricingRules.Add(new AirConditionedRoomPriceRule()); pricingRules.Add(new BreakfastPriceRule()); pricingRules.Add(new MoreThanTwoPersonsPerRoomPriceRule()); List<IPriceRule> discountRules = new List<IPriceRule>(); discountRules.Add(new EarlyBirdDisountRule()); discountRules.Add(new LastMinuteDiscountRule()); IPriceCalculator priceCalculator = new PriceCalculator(pricingRules,discountRules); IRoom room = new Room(); room.NumberOfPersons = 2; room.NumberOfDays = 1 ; room.IsSeeSideRoom = true; room.NumberOfBreakfastsPerDay = 1; room.ReservationStartDate = date; room.HasAirConditioner = true; var price = priceCalculator.CalculatePrice(room); Console.WriteLine("The price for the room is: {0}.", price); }
public void CalculatePrice__PriceIsMaxValue__DoesNotThrow() { // A - arrange IRoom room = new Room { Price = decimal.MaxValue }; IPriceRule priceRule = new TVAPriceRule(); // A - act decimal result = priceRule.CalculatePrice(room); // A - assert Assert.AreEqual(decimal.MaxValue * 0.19m, result); }
public void CalculatePrice__ForMultitpleRules__ReturnedPriceIsCorrect() { var rule1 = new Mock<IPriceRule>(); rule1.Setup(x => x.CalculatePrice(It.IsAny<IRoom>())).Returns(decimal.MaxValue); var rule2 = new Mock<IPriceRule>(); rule2.Setup(x => x.CalculatePrice(It.IsAny<IRoom>())).Returns(15); var rules = new List<IPriceRule> { rule1.Object, rule2.Object }; IPriceCalculator priceCalculator = new PriceCalculator(rules, null); IRoom room = new Room(); var result = priceCalculator.CalculatePrice(room); rule1.Verify(x => x.CalculatePrice(It.IsAny<IRoom>()), Times.Once); rule2.Verify(x => x.CalculatePrice(It.IsAny<IRoom>()), Times.Once); }
public void CalculatePrice__RoomPriceCoorectlySetup__ReturnedTvaValueIsCorrect() { // A - arrange IRoom room = new Room { Price = 50 }; IPriceRule priceRule = new TVAPriceRule(); // A - act decimal result = priceRule.CalculatePrice(room); // A - assert Assert.AreEqual(9.5m, result); }