private void AlphabeticalDiscount_ReturnsDiscount_WhenAnimalsAreValid() { //Arrange List <Animal> animals = GetAnimals(); var discountValidator = new DiscountValidator(); //Act var result = discountValidator.GetAlphabeticalDiscount(animals); //Assert var resultInt = Assert.IsType <int>(result); Assert.Equal(6, resultInt); }
public async Task <IViewComponentResult> InvokeAsync(BookingProcess data) { List <Animal> animals = await GetAnimals(data.Animals.Select(e => e.ID).ToArray()); List <Accessories> accessories = new List <Accessories>(); List <Discounts> discounts = new List <Discounts>(); DiscountValidator discountValidator = new DiscountValidator(); if (data.Accessories != null) { accessories = await GetAccessories(data.Accessories.Select(e => e.ID).ToArray()); } data.Animals = animals; data.Accessories = accessories; #region Discount int totalDiscountPercentage = 0; if (discountValidator.HasThreeSameTypeAnimals(animals)) { totalDiscountPercentage += 10; discounts.Add(new Discounts() { Name = "3 Types", Discount = 10 }); } int duckDiscount = discountValidator.ChanceOnDuckDiscount(animals); if (duckDiscount > 0) { totalDiscountPercentage += duckDiscount; discounts.Add(new Discounts() { Name = "Eend", Discount = duckDiscount } ); } int dateDiscount = discountValidator.BookingIsMondayOrTuesday(data.Booking.Date); if (dateDiscount > 0) { totalDiscountPercentage += dateDiscount; discounts.Add(new Discounts() { Name = data.Booking.Date.DayOfWeek.ToString(), Discount = dateDiscount }); } int alphabetDiscount = discountValidator.GetAlphabeticalDiscount(animals); if (alphabetDiscount > 0) { totalDiscountPercentage += alphabetDiscount; discounts.Add(new Discounts() { Name = "Alfabet", Discount = alphabetDiscount }); } totalDiscountPercentage = discountValidator.GetMaximumPercentage(totalDiscountPercentage, 60); data.TotalDiscount = totalDiscountPercentage; #endregion #region TotalPrice double totalPrice = 0.0; foreach (Animal animal in animals) { totalPrice += animal.Price; } foreach (Accessories accessoriese in accessories) { totalPrice += accessoriese.Price; } totalPrice = totalPrice / 100 * (100 - totalDiscountPercentage); #endregion data.TotalPrice = totalPrice; data.TotalDiscount = totalDiscountPercentage; data.Discounts = discounts; #region SaveData await _clientInfoRepository.Create(data.ClientInfo); data.ClientInfoId = data.ClientInfo.ID; data.DateTime = data.Booking.Date; data.BookingProcessAnimals = new List <BookingProcessAnimal>(); data.BookingProcessAccessories = new List <BookingProcessAccessories>(); foreach (Animal animal in animals) { data.BookingProcessAnimals.Add(new BookingProcessAnimal() { BookingProcessId = data.ID, AnimalId = animal.ID }); } foreach (Accessories a in accessories) { data.BookingProcessAccessories.Add(new BookingProcessAccessories() { BookingProcessId = data.ID, AccessoriesId = a.ID }); } await _bookingProcessRepository.Create(data); #endregion return(View(data)); }