public void RoomAvailabilityCreateValid()
        {
            RoomAvailabilitiesController controller = new RoomAvailabilitiesController();
            var result = controller.Create();
            Assert.IsInstanceOfType(result, typeof(ViewResult));

        }
        public void RoomAvailabilityDetailsNull()
        {
            RoomAvailabilitiesController controller = new RoomAvailabilitiesController();
            var result = (HttpStatusCodeResult)controller.Details(null);
            Assert.AreEqual(400, result.StatusCode);
            Assert.IsInstanceOfType(result, typeof(HttpStatusCodeResult));

        }
        public void RoomAvailabilityCreate()
        {
            RoomAvailabilitiesController controller = new RoomAvailabilitiesController();
            RoomAvailability roomAvail = new RoomAvailability();
            roomAvail.AccomodationId = 1;
            roomAvail.ArrivalDate = new DateTime(2015, 9, 22);
            roomAvail.DepartureDate = new DateTime(2016, 9, 28);
            roomAvail.IsPaid = true;
            roomAvail.RoomAvailabilityId = 0;
            roomAvail.RoomId = 1;
            roomAvail.TotalPrice = 100;
            roomAvail.UserId = "1";

            var result = controller.Create(roomAvail);
            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
            Assert.IsNotNull(result);

        }
        public void RoomAvailabilityInvalidInput()
        {
            RoomAvailabilitiesController controller = new RoomAvailabilitiesController();
            RoomAvailability roomAvail = new RoomAvailability();
            roomAvail.AccomodationId = 1;
            roomAvail.ArrivalDate = new DateTime(2015, 9, 22);
            roomAvail.DepartureDate = new DateTime(2016, 9, 28);
            roomAvail.IsPaid = true;
            roomAvail.RoomAvailabilityId = 0;
            roomAvail.RoomId = 1;
            roomAvail.TotalPrice = -100;
            roomAvail.UserId = "1";


            var context = new ValidationContext(roomAvail, null, null);
            var results = new List<ValidationResult>();
            TypeDescriptor.AddProviderTransparent(new AssociatedMetadataTypeTypeDescriptionProvider(typeof(RoomAvailability), typeof(RoomAvailability)), typeof(RoomAvailability));

            var isModelStateValid = Validator.TryValidateObject(roomAvail, context, results, true);
            Assert.AreEqual(false, isModelStateValid);

        }
        public ActionResult FindAvailableRooms(List<Accomodation> accomdationQuery,DateTime arrivalDate, DateTime departureDate,string TempUserId)
        {
            //referencing the roomAvailabilityController so we could access the Action inside the AccomodationController
            var roomAvailabilityController = new RoomAvailabilitiesController();    //RoomAvailibility CONTROLLER Object

            List<Room> roomList = new List<Room>();

            //iterating trough the list of accomodations and their rooms
            for (int i = 0; i < accomdationQuery.Count; i++)
            {
                foreach (var room in accomdationQuery[i].ListOfRooms)
                {
                    Room roomToAdd = roomAvailabilityController.GetAvailabilityAndPrice(room.AccomodationId, room.RoomId, arrivalDate, departureDate, TempUserId);
                    if (roomToAdd != null)
                    {
                        roomToAdd.TempReservationString = System.Guid.NewGuid().ToString();
                        roomList.Add(roomToAdd);
                    }
                }
            }

            if (roomList.Count == 0)
            {
                ModelState.AddModelError("searchString", "There are no available rooms found which suites your search criteria. Your arrival date was: " + arrivalDate.ToShortDateString() + " , and departure date: " + departureDate.ToShortDateString() + " . Please search again.");
                return View("Index", accomdationQuery);
                //return View("NoRoomsFound");
            }
            

            List<int> roomIds = new List<int>();

            foreach (var room in roomList)
            {
                roomIds.Add(room.RoomId);
            }

            //IQueryable<Room> query = db.Rooms.Include(r => r.Accomodation).Include(r => r.RoomType);
            IQueryable<Room> query = db.Rooms.Include(r => r.RoomType);
            List<Room> queriedRooms = new List<Room>();

            foreach (int id in roomIds)
            {
                queriedRooms.AddRange(query.Where(x => x.RoomId == id).ToList());
            }

            for (int i = 0; i < queriedRooms.Count; i++)
            {
                queriedRooms[i].TempTotalPrice = roomList[i].TempTotalPrice;
                queriedRooms[i].TempReservationString = roomList[i].TempReservationString;
                queriedRooms[i].TempArrivalDate = roomList[i].TempArrivalDate;
                queriedRooms[i].TempDepartureDate = roomList[i].TempDepartureDate;
                queriedRooms[i].Price = roomList[i].Price;
                queriedRooms[i].TempUserId = roomList[i].TempUserId;
            }

            if (queriedRooms != null)
            {
                return ShowAvailableRooms(queriedRooms);
            }
            return View("NoRoomsFound");
        }
        public void RoomAvailabilityDetails()
        {
            RoomAvailabilitiesController controller = new RoomAvailabilitiesController();
            var result = controller.Details(1);
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(ViewResult));

        }
 public void RoomAvailabilitysDeleteNotFound()
 {
     RoomAvailabilitiesController controller = new RoomAvailabilitiesController();
     var result = (HttpStatusCodeResult)controller.Delete(-1);
     Assert.AreEqual(404, result.StatusCode);
     Assert.IsInstanceOfType(result, typeof(HttpStatusCodeResult));
 }
        public void RoomAvailabilityDelete()
        {
            RoomAvailabilitiesController controller = new RoomAvailabilitiesController();
            var result = controller.Delete(1);
            Assert.IsNotNull(result);

        }