Ejemplo n.º 1
0
        public void when_calling_ReserveHolidayHome_with_model_error_returns_BookViewModel()
        {
            //CheckBookingModel model = new CheckBookingModel();
            //model.Available = true;
            //model.DaysAvailable = 3;
            //model.FirstDateAvailable = new DateTime(2019, 4, 13);
            //model.room = new Room() { Price = 100, numberofGuests = 1, numberofBeds = 1, doubleBed = false, petsAllowed = false, Toilet = true, Kitchen = false, numberofTelevisions = 1 };
            //model.holidayHome = new HolidayHome() { HolidayHomeId = 3, Price = 200, numberofGuests = 1, numberofBeds = 1, doubleBed = false, petsAllowed = true, Toilet = true, Kitchen = false, numberofTelevisions = 1, numberofFloors = 1 };
            HolidayHome hhome = new HolidayHome()
            {
                HolidayHomeId = 3, Price = 200, numberofGuests = 1, numberofBeds = 1, doubleBed = false, petsAllowed = true, Toilet = true, Kitchen = false, numberofTelevisions = 1, numberofFloors = 1
            };

            List <DateTime> listDateTime = new List <DateTime>();

            listDateTime.Add(new DateTime(2019, 4, 9));
            listDateTime.Add(new DateTime(2019, 4, 10));
            listDateTime.Add(new DateTime(2019, 4, 11));
            listDateTime.Add(new DateTime(2019, 4, 12));



            ReverveHolidayHomeModel reservemodel = new ReverveHolidayHomeModel();

            reservemodel.dateFrom      = new DateTime(2019, 4, 6);
            reservemodel.dateTo        = new DateTime(2019, 4, 5);
            reservemodel.holidayhomeId = 3;



            Mock <IHolidaysRepository> mock = new Mock <IHolidaysRepository>();

            mock.Setup(r => r.GetHolidayHomeById(It.IsAny <int>())).Returns(hhome);
            mock.Setup(r => r.GetDaysBookedHolidayHome(It.IsAny <int>())).Returns(listDateTime);


            ClientController controller = new ClientController(mock.Object);
            ViewResult       result     = (ViewResult)(controller.ReserveHolidayHome(reservemodel));

            Assert.AreEqual("~/Views/Client/BookHolidayHome.cshtml", result.ViewName);
            BookViewModel bookviewmodel = (BookViewModel)result.Model;

            Assert.AreEqual(hhome, bookviewmodel.holidayhome);
        }
        public ActionResult ReserveHolidayHome(ReverveHolidayHomeModel model)
        {
            if (model.dateTo <= model.dateFrom)
            {
                ModelState.AddModelError("dateTo", "Date should be later than above");
            }

            if (model.dateFrom == null)
            {
                ModelState.AddModelError("dateFrom", "Pole nie moze być puste");
            }


            if (ModelState.IsValid)
            {
                //repository.BookHolidayHome(model.holidayhomeId, model.dateFrom, model.dateTo);

                CheckBookingModel modelbook = repository.bookholidayhome(model.holidayhomeId, model.dateFrom, model.dateTo);
                ViewBag.checkbookingmodel = modelbook;

                return(RedirectToAction("ShowDetailsHolidayHome", "Home", new { Id = model.holidayhomeId }));
            }
            else
            {
                HolidayHome     holidayhome = repository.GetHolidayHomeById(model.holidayhomeId);
                List <DateTime> list        = repository.GetDaysBookedHolidayHome(model.holidayhomeId);
                List <string>   liststring  = new List <string>();

                foreach (var item in list)
                {
                    liststring.Add(item.ToShortDateString());
                }

                BookViewModel viewmodel = new BookViewModel();
                viewmodel.holidayhome = holidayhome;
                viewmodel.list        = liststring;



                //return View("~/Views/Client/Book/HolidayHome.cshtml", viewmodel);
                return(View("~/Views/Client/BookHolidayHome.cshtml", viewmodel));
            }
        }
Ejemplo n.º 3
0
        public void when_calling_ReserveHolidayHome_returns_model()
        {
            CheckBookingModel model = new CheckBookingModel();

            model.Available          = true;
            model.DaysAvailable      = 3;
            model.FirstDateAvailable = new DateTime(2019, 4, 13);
            model.room = new Room()
            {
                Price = 100, numberofGuests = 1, numberofBeds = 1, doubleBed = false, petsAllowed = false, Toilet = true, Kitchen = false, numberofTelevisions = 1
            };
            model.holidayHome = new HolidayHome()
            {
                HolidayHomeId = 3, Price = 200, numberofGuests = 1, numberofBeds = 1, doubleBed = false, petsAllowed = true, Toilet = true, Kitchen = false, numberofTelevisions = 1, numberofFloors = 1
            };


            ReverveHolidayHomeModel reservemodel = new ReverveHolidayHomeModel();

            reservemodel.dateFrom      = new DateTime(2019, 4, 2);
            reservemodel.dateTo        = new DateTime(2019, 4, 5);
            reservemodel.holidayhomeId = 3;



            Mock <IHolidaysRepository> mock = new Mock <IHolidaysRepository>();

            mock.Setup(r => r.bookholidayhome(It.IsAny <int>(), It.IsAny <DateTime>(), It.IsAny <DateTime>())).Returns(model);

            ClientController      controller = new ClientController(mock.Object);
            RedirectToRouteResult result     = (RedirectToRouteResult)(controller.ReserveHolidayHome(reservemodel));

            Assert.AreEqual("ShowDetailsHolidayHome", result.RouteValues["action"]);
            Assert.AreEqual("Home", result.RouteValues["controller"]);
            Assert.AreEqual(3, result.RouteValues["Id"]);
        }