public void RoomsCreate() { RoomsController controller = new RoomsController(); Room rm = new Room(); rm.AccomodationId = 1; rm.NumberOfRooms = 23; rm.Price = 50; rm.TempReservationString = "reserved"; rm.RoomCapacity = 2; rm.RoomId = 0; rm.RoomTypeId = 1; rm.RoomDetails = " Air conditioning, Desk, Heating, Shower, Hairdryer,Flat-screen TV, Wi-Fi,Pay-per-view channels,Minibar"; var result = controller.Create(rm); Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult)); }
public void RoomCreateInvalidInput() { RoomsController controller = new RoomsController(); Room rm = new Room(); rm.AccomodationId = 1; rm.NumberOfRooms = -23; rm.Price = -50; rm.TempReservationString = "reserved"; rm.RoomCapacity = -2; rm.RoomId = 0; rm.RoomTypeId = 1; rm.RoomDetails = " Air conditioning, Desk, Heating, Shower, Hairdryer,Flat-screen TV, Wi-Fi,Pay-per-view channels,Minibar"; var context = new ValidationContext(rm, null, null); var results = new List<ValidationResult>(); TypeDescriptor.AddProviderTransparent(new AssociatedMetadataTypeTypeDescriptionProvider(typeof(Room), typeof(Room)), typeof(Room)); var isModelStateValid = Validator.TryValidateObject(rm, context, results, true); Assert.AreEqual(false, isModelStateValid); }
//public ActionResult GetAvailability(DateTime? from, DateTime? to) //{ // //TESTNI PODACI SU U PITANJU - TREBA IMPLEMENTIRATI PRAVE PODATKE // //TESTNI PODACI SU U PITANJU - TREBA IMPLEMENTIRATI PRAVE PODATKE // //TESTNI PODACI SU U PITANJU - TREBA IMPLEMENTIRATI PRAVE PODATKE // //TESTNI PODACI SU U PITANJU - TREBA IMPLEMENTIRATI PRAVE PODATKE // //TESTNI PODACI SU U PITANJU - TREBA IMPLEMENTIRATI PRAVE PODATKE // RoomAvailability roomCheck = new RoomAvailability() { AccomodationId = 50, ArrivalDate = from.Value, DepartureDate = to.Value, IsPaid = true, RoomId = 67, RoomAvailabilityId = 3, UserId = 1 }; // var currentBooking = db.RoomAvailabilities.Where((x => x.RoomId == 67 && x.AccomodationId == 50 && // (from <= x.DepartureDate && from >= x.ArrivalDate || x.ArrivalDate <= to && x.ArrivalDate >= from))) // .FirstOrDefault(); // if (currentBooking != null) // { // return View(roomCheck); // } // db.RoomAvailabilities.Add(roomCheck); // db.SaveChanges(); // return RedirectToAction("Index"); //} public Room GetAvailabilityAndPrice(int accomodationId, int roomId, DateTime? from, DateTime? to,string UserId) //nedostaje UserID da bi se znalo za koga se soba rezerviĊĦe { var currentBooking = db.RoomAvailabilities.Where((x => x.RoomId == roomId && x.AccomodationId == accomodationId && (from <= x.DepartureDate && from >= x.ArrivalDate || x.ArrivalDate <= to && x.ArrivalDate >= from))) .ToList(); //if (currentBooking != null) //{ // return null; //} var roomTypeId = db.Rooms.Where(x => x.RoomId == roomId).SingleOrDefault().RoomTypeId; var pricePerNight = db.Rooms.Where(x => x.RoomId == roomId).SingleOrDefault().Price; var numberOfRooms = db.Rooms.Where(x => x.RoomId == roomId).SingleOrDefault().NumberOfRooms; var roomCapacity = db.Rooms.Where(x => x.RoomId == roomId).SingleOrDefault().RoomCapacity; //START - NEW TEST if (currentBooking.Count >= numberOfRooms) { return null; } //END - NEW TEST Room foundRoom = new Room() { AccomodationId = accomodationId, Price = pricePerNight, RoomId = roomId, RoomTypeId = roomTypeId, ListOfAvailableRooms = null, NumberOfRooms = numberOfRooms, RoomCapacity = roomCapacity, TempArrivalDate = from.Value, TempDepartureDate = to.Value, TempIsPaid = false, TempUserId = UserId }; double totalPrice = 0; DateTime currentDay = new DateTime(); double pricePerDay = 0; currentDay = from.Value; while (currentDay <= to.Value) { try { pricePerDay = db.RoomPrices.Where(x => x.StartDate <= currentDay && x.EndDate >= currentDay && x.RoomTypeId == roomTypeId && x.AccomodationId == foundRoom.AccomodationId) .FirstOrDefault().SpecialPrice; } catch (Exception) { //Implement the error LOG when the user does not sets the prices for a room on certain dates. The error will be cought here! totalPrice += db.Rooms.Where(x => x.RoomId == roomId).SingleOrDefault().Price; } totalPrice += pricePerDay; currentDay = currentDay.AddDays(1); } double totalDays = (to.Value - from.Value).TotalDays; foundRoom.Price = totalPrice / totalDays; foundRoom.TempTotalPrice = totalPrice; return foundRoom; }