Ejemplo n.º 1
0
        public void TestBookingControllerSearchHotelsActionSearchHotelsInvalidData(BookingInputViewModel testInputViewModel)
        {
            var mockHotelService     = new Mock <IHotelService>();
            var applicationDbcontext = new ApplicationDbContext(CreateNewContextOptions());
            var mockRoomService      = new Mock <IRoomService>();
            var store = new Mock <IUserStore <ApplicationUser> >();
            var mgr   = new Mock <UserManager <ApplicationUser> >(store.Object, null, null, null, null, null, null, null, null);

            mgr.Object.UserValidators.Add(new UserValidator <ApplicationUser>());
            mgr.Object.PasswordValidators.Add(new PasswordValidator <ApplicationUser>());

            var testController = new BookingController(applicationDbcontext, mockHotelService.Object, mockRoomService.Object, mgr.Object);

            Assert.ThrowsAsync <ArgumentOutOfRangeException>(() => testController.SearchHotels(testInputViewModel));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> SearchHotels([Bind] BookingInputViewModel inputModel)
        {
            if (string.IsNullOrWhiteSpace(inputModel.Destination) || inputModel.Destination.Length > 30 || inputModel.CheckOut <= inputModel.CheckIn || inputModel.CheckIn == new DateTime(0001, 01, 01) || inputModel.CheckOut == new DateTime(0001, 01, 01) || inputModel.Adults <= 0 || inputModel.Children < 0 || inputModel.Destination.Length > 30 || inputModel.CheckIn < DateTime.Today || inputModel.CheckOut < DateTime.Today)
            {
                throw new ArgumentOutOfRangeException("User Input data is incorrect! Make sure that departure date is greater than arrival date! Make sure that number of adults is not empty!");
            }

            //Check if datetime is with default value, additional checks for other parameters

            var searchedHotelsByCity = await this.hotelService.SearchWithLocationAsync(inputModel.Destination);

            var searchedHotelsByName = await this.hotelService.SearchWithHotelNameAsync(inputModel.Destination);

            var searchResultList = new List <Hotel>();

            searchResultList = searchedHotelsByCity.Count == 0 ? searchedHotelsByName : searchedHotelsByCity;
            //Searching with city is with priority and searching with name is optional

            var bookingViewModel = new BookingViewModel();
            var hotelViewModel   = new List <BookingOutputViewModel>();

            foreach (var hotel in searchResultList)
            {
                var currentViewModelHotel = new BookingOutputViewModel();
                currentViewModelHotel.HotelId   = hotel.Id;
                currentViewModelHotel.HotelName = hotel.Name;
                currentViewModelHotel.Address   = hotel.Address.Street
                                                  + ", " + hotel.Address.City + ", " + hotel.Address.State + ", " + hotel.Address.PostalCode;
                currentViewModelHotel.PetFriendly = hotel.Amenity.AllowPets == true ? "Yes" : "No";
                currentViewModelHotel.Wifi        = hotel.Amenity.WiFi == true ? "Yes" : "No";
                currentViewModelHotel.Pool        = hotel.Amenity.Pool == true ? "Yes" : "No";
                currentViewModelHotel.Stars       = hotel.Stars;
                currentViewModelHotel.Image       = hotel.Image;

                hotelViewModel.Add(currentViewModelHotel);
            }
            bookingViewModel.BookingOutputViewModels = hotelViewModel;
            //Contains information about the searched hotels;
            bookingViewModel.InputModel = inputModel;
            //Contains information about the input, including validation

            //TODO Implement Paging

            return(this.View("Index", bookingViewModel));
        }