private void FarmAnimalHasNoLionOrIceBear_ThrowNullReferenceException_WhenAnimalsAreNull() { //Arrange List <Animal> animals = null; var animalSelectionValidator = new AnimalSelectionValidator(); //Act & Assert Assert.Throws <NullReferenceException>(() => animalSelectionValidator.FarmAnimalHasNoLionOrIceBear(animals)); }
private void FarmAnimalHasNoLionOrIceBear_ReturnFalse_WhenAnimalAreFarmAndPolarBear() { //Arrange List <Animal> animals = GetAnimals(); var animalSelectionValidator = new AnimalSelectionValidator(); //Act var result = animalSelectionValidator.FarmAnimalHasNoLionOrIceBear(animals); //Assert Assert.False(result); }
private void FarmAnimalHasNoLionOrIceBear_ReturnTrue_WhenAnimalsAreZero() { //Arrange List <Animal> animals = new List <Animal>(); var animalSelectionValidator = new AnimalSelectionValidator(); //Act var result = animalSelectionValidator.FarmAnimalHasNoLionOrIceBear(animals); //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)); }