Example #1
0
        private void DesertAnimalIsHiredInWinter_ThrowsNullReferenceException_WhenAnimalsAreNull()
        {
            //Arrange
            List <Animal> animals = null;
            var           animalSelectionValidator = new AnimalSelectionValidator();

            //Act && Assert
            Assert.Throws <NullReferenceException>(() => animalSelectionValidator.DesertAnimalIsHiredInWinter(animals, DateTime.Now));
        }
Example #2
0
        private void DesertAnimalIsHiredInWinter_ReturnTrue_WhenDataIsValid()
        {
            //Arrange
            List <Animal> animals = GetAnimals();

            animals[1].Type = AnimalTypes.Woestijn;

            var animalSelectionValidator = new AnimalSelectionValidator();

            DateTime dateTime = new DateTime(2020, 1, 1);

            //Act
            var result = animalSelectionValidator.DesertAnimalIsHiredInWinter(animals, dateTime);

            //Assert
            Assert.True(result);
        }
Example #3
0
        private void DesertAnimalIsHiredInWinter_ReturnFalse_WhenTypeIsInvalid()
        {
            //Arrange
            List <Animal> animals = GetAnimals();

            animals[1].Type = AnimalTypes.Sneeuw;

            var animalSelectionValidator = new AnimalSelectionValidator();

            DateTime dateTime = new DateTime(2020, 01, 18);

            //Act
            var restult = animalSelectionValidator.DesertAnimalIsHiredInWinter(animals, dateTime);

            //Assert
            Assert.False(restult);
        }
Example #4
0
        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));
        }