private void PenguinIsHiredInWeekend_ThrowsNullReferenceException_WhenAnimalsAreNull() { //Arrange List <Animal> animals = null; var animalSelectionValidator = new AnimalSelectionValidator(); //Act && Assert Assert.Throws <NullReferenceException>(() => animalSelectionValidator.PenguinIsHiredInWeekend(animals, DateTime.Now)); }
private void PenguinIsHiredInWeekend_ReturnFalse_WhenPinguinIsFalse() { //Arrange List <Animal> animals = GetAnimals(); var animalSelectionValidator = new AnimalSelectionValidator(); DateTime dateTime = new DateTime(2020, 01, 18); //Act var restult = animalSelectionValidator.PenguinIsHiredInWeekend(animals, dateTime); //Assert Assert.False(restult); }
private void PenguinIsHiredInWeekend_ReturnTrue_WhenDataIsValid() { //Arrange List <Animal> animals = GetAnimals(); animals.Add(new Animal() { ID = 4, Name = "Pinguin", Type = AnimalTypes.Sneeuw, Price = 45.00, PicturePath = "/images/animals/pingwing.png" }); var animalSelectionValidator = new AnimalSelectionValidator(); DateTime dateTime = new DateTime(2020, 01, 18); //Act var result = animalSelectionValidator.PenguinIsHiredInWeekend(animals, dateTime); //Assert Assert.True(result); }
public async Task <IActionResult> AnimalsSelected(BookingProcess data) { AnimalSelectionValidator animalSelectionValidator = new AnimalSelectionValidator(); Booking booking = await((BookingDBRepository)_bookingRepository).GetFromDate(data.Booking.Date); List <Animal> selectedAnimals = new List <Animal>(); foreach (Animal animal in data.Animals) { if (booking != null && animal.BookingIsSelected) { if (animalSelectionValidator.IsAnimalAlreadyBooked(booking.BookingAnimals, animal.ID)) { TempData["error"] = "Selected animals are already booked"; return(RedirectToActionPermanent(nameof(AnimalSelection), booking)); } } if (animal.BookingIsSelected) { Animal dAnimal = await((AnimalDbRepository)_animalRepository).Get(animal.ID); selectedAnimals.Add(dAnimal); } } booking = data.Booking; if (!animalSelectionValidator.IsAnAnimalSelected(selectedAnimals)) { TempData["error"] = "Please select an animal"; return(RedirectToActionPermanent(nameof(AnimalSelection), booking)); } if (!animalSelectionValidator.FarmAnimalHasNoLionOrIceBear(selectedAnimals)) { TempData["error"] = "An animal from the farm can not be along with Lion and Ice Bear"; return(RedirectToActionPermanent(nameof(AnimalSelection), booking)); } if (animalSelectionValidator.PenguinIsHiredInWeekend(selectedAnimals, data.Booking.Date)) { TempData["error"] = "Penguin can not be booked during the weekend"; return(RedirectToActionPermanent(nameof(AnimalSelection), booking)); } if (animalSelectionValidator.DesertAnimalIsHiredInWinter(selectedAnimals, data.Booking.Date)) { TempData["error"] = "Desert animal can not be selected for the Winter"; return(RedirectToActionPermanent(nameof(AnimalSelection), booking)); } if (animalSelectionValidator.SnowAnimalIsHiredForSummer(selectedAnimals, data.Booking.Date)) { TempData["error"] = "Snow Animal cannot be selected for the Summer"; return(RedirectToActionPermanent(nameof(AnimalSelection), booking)); } data.DateTime = data.Booking.Date; data.Animals = selectedAnimals; data.Booking.BookingState = BookingState.Accessories; return(View("AnimalSelection", data)); }