示例#1
0
        public void Item7_ForceCancelButton()
        {
            //Inject the configurations value - no need to change values in this block
            var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            config.AppSettings.Settings.Clear();
            config.AppSettings.Settings.Add("FromEmailAddress", "*****@*****.**");
            config.AppSettings.Settings.Add("FromEmailDisplayName", "Booking Admin");
            config.AppSettings.Settings.Add("FromEmailPassWord", "obsg11s2");
            config.AppSettings.Settings.Add("SMTPHost", "smtp.gmail.com");
            config.AppSettings.Settings.Add("SMTPPort", "587");
            config.AppSettings.Settings.Add("EnableSSL", "true");

            config.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection("appSettings");
            //End Injection

            var context = new Mock <ControllerContext>();
            var session = new MockHttpSession();

            var serverMock = new Mock <HttpServerUtilityBase>(MockBehavior.Loose);

            //NOTE: you need to change the parameter in below Returns function to the path on your machine.
            //The path should be "Your Project Foder Path\Views\Shared\_TemplateSendEmail.cshtml"
            serverMock.Setup(x => x.MapPath("~/Views/Shared/_TemplateSendEmail.cshtml")).
            Returns(@"D:\Webapp\OBS\Views\Shared\_TemplateSendEmail.cshtml");

            context.Setup(m => m.HttpContext.Session).Returns(session);
            context.Setup(x => x.HttpContext.Server).Returns(serverMock.Object);

            RoomUsageController rc = new RoomUsageController();

            rc.ControllerContext   = context.Object;
            rc.Session["UserName"] = "******";   // this is the login account to obs.

            RoomUsageDetailsViewModel roomUsage = new RoomUsageDetailsViewModel()
            {
                Page = 1, PageSize = 999
            };

            var bookingHis = rc.GetAllBookingHistory(roomUsage) as PartialViewResult;
            IEnumerable <RoomUsageDetailsViewModel> mds = bookingHis.Model as IEnumerable <RoomUsageDetailsViewModel>;
            int beforeCancel = mds.Count(); // get number of booking before clicking force cancel

            rc.DeleteRoomUsageDetails(61);  // Force Cancel one booking, value 62 is the parameter of a booking on 16Sep.

            /* Use below query to know the exact booking id in database:
             *
             *  select	ID,*
             *  from	RoomUsages
             *  where	IsActive = 1
             *
             */
            var currentBooking = rc.GetAllBookingHistory(roomUsage) as PartialViewResult;
            IEnumerable <RoomUsageDetailsViewModel> currB = currentBooking.Model as IEnumerable <RoomUsageDetailsViewModel>;
            int afterCancel = currB.Count(); // get number of booking after clicking force cancel


            Assert.AreEqual(beforeCancel - 1, afterCancel); // compare number of bookings before and after cancel
        }
示例#2
0
        public void Item6_ViewAllBookingswithAdmin()
        {
            var context = new Mock <ControllerContext>();
            var session = new MockHttpSession();

            context.Setup(m => m.HttpContext.Session).Returns(session);
            RoomUsageController rc = new RoomUsageController();

            rc.ControllerContext   = context.Object;
            rc.Session["UserName"] = "******";   // this is the login account to obs.

            var result = rc.GetAllBookingHistory() as PartialViewResult;

            IEnumerable <RoomUsageDetailsViewModel> mds = result.Model as IEnumerable <RoomUsageDetailsViewModel>;

            //the count value may be diferent. At the time for testing this function, there are total 29 MyBookings

            /* Use below query to know the exact booking number in database:
             *
             *  select	count(*)
             *  from	RoomUsages
             *  where	IsActive = 1
             *
             */
            Assert.AreEqual(29, mds.Count());
        }
示例#3
0
        public void Item5_MyBookings()
        {
            var context = new Mock <ControllerContext>();
            var session = new MockHttpSession();

            context.Setup(m => m.HttpContext.Session).Returns(session);
            RoomUsageController rc = new RoomUsageController();

            rc.ControllerContext   = context.Object;
            rc.Session["UserName"] = "******";

            var result = rc.GetAllBookingHistory() as PartialViewResult;

            IEnumerable <RoomUsageDetailsViewModel> mds = result.Model as IEnumerable <RoomUsageDetailsViewModel>;

            //the count value may be diferent. At the time for testing this function, there are total 9 MyBookings
            Assert.AreEqual(9, mds.Count());
        }