public void Index_UserIsSecretary()
        {
            PracticeHomeController homeController;
            var mr = new MockRepository();

            try
            {
                var milena = Firestarter.CreateSecretary_Milena(this.db, this.db.Practices.First());
                mr.SetCurrentUser(milena.Users.Single(), "milena");
                mr.SetRouteData("Index", "practicehome", "App", "consultoriodrhouse");

                homeController = mr.CreateController <PracticeHomeController>(callOnActionExecuting: false);
            }
            catch (Exception ex)
            {
                InconclusiveInit(ex);
                return;
            }

            // Execute test: owner must have access to this view.
            var actionResult = Mvc3TestHelper.RunOnAuthorization(homeController, "Index")
                               ?? Mvc3TestHelper.RunOnActionExecuting(homeController, "Index")
                               ?? homeController.Index();

            // Asserts
            Assert.IsInstanceOfType(actionResult, typeof(ViewResult));
            Assert.AreEqual(null, ((ViewResult)actionResult).View);
        }
        public void Index_UserIsAdministrator()
        {
            PracticeHomeController homeController;
            var mr = new MockRepository();

            try
            {
                mr.SetCurrentUser_Miguel_CorrectPassword();
                mr.SetRouteData_ConsultorioDrHouse_GregoryHouse(typeof(PracticeHomeController), "Index");

                homeController = mr.CreateController <PracticeHomeController>(callOnActionExecuting: false);
            }
            catch (Exception ex)
            {
                InconclusiveInit(ex);
                return;
            }

            // Execute test: owner must have access to this view.
            var actionResult = Mvc3TestHelper.RunOnAuthorization(homeController, "Index")
                               ?? Mvc3TestHelper.RunOnActionExecuting(homeController, "Index")
                               ?? homeController.Index();

            // Asserts
            Assert.IsInstanceOfType(actionResult, typeof(ViewResult));
            Assert.AreEqual(null, ((ViewResult)actionResult).View);
        }
        public void EditPost_UserIsSecretary()
        {
            PracticeHomeController homeController;
            var mr = new MockRepository();

            try
            {
                var milena = Firestarter.CreateSecretary_Milena(this.db, this.db.Practices.First());
                mr.SetCurrentUser(milena.Users.Single(), "milena");
                mr.SetRouteData("Edit", "practicehome", "App", "consultoriodrhouse");

                homeController = mr.CreateController <PracticeHomeController>(callOnActionExecuting: false);
            }
            catch (Exception ex)
            {
                InconclusiveInit(ex);
                return;
            }

            // Execute test: owner must have access to this view.
            var actionResult = Mvc3TestHelper.RunOnAuthorization(homeController, "Edit", "POST")
                               ?? Mvc3TestHelper.RunOnActionExecuting(homeController, "Edit", "POST")
                               ?? homeController.Edit(new PracticeHomeControllerViewModel
            {
                PracticeName     = "My New Practice Name",
                PracticeTimeZone = 3
            });

            // Asserts
            Assert.IsInstanceOfType(actionResult, typeof(UnauthorizedResult));
        }
        public void EditPost_UserIsAdministrator()
        {
            PracticeHomeController homeController;
            var mr = new MockRepository();

            try
            {
                mr.SetCurrentUser_Miguel_CorrectPassword();
                mr.SetRouteData_ConsultorioDrHouse_GregoryHouse(typeof(PracticeHomeController), "Edit");

                homeController = mr.CreateController <PracticeHomeController>(callOnActionExecuting: false);
            }
            catch (Exception ex)
            {
                InconclusiveInit(ex);
                return;
            }

            // Execute test: owner must have access to this view.
            var actionResult = Mvc3TestHelper.RunOnAuthorization(homeController, "Edit", "POST")
                               ?? Mvc3TestHelper.RunOnActionExecuting(homeController, "Edit", "POST")
                               ?? homeController.Edit(new PracticeHomeControllerViewModel
            {
                PracticeName     = "My New Practice Name",
                PracticeTimeZone = 3
            });

            // Asserts
            Assert.IsInstanceOfType(actionResult, typeof(RedirectToRouteResult));
            var redirectResult = (RedirectToRouteResult)actionResult;

            Assert.AreEqual(2, redirectResult.RouteValues.Count);
            Assert.AreEqual("practicehome", string.Format("{0}", redirectResult.RouteValues["controller"]), ignoreCase: true);
            Assert.AreEqual("Index", string.Format("{0}", redirectResult.RouteValues["action"]), ignoreCase: true);
        }
        public void EditPost_UserIsOwner_WithInvalidData()
        {
            PracticeHomeController homeController;
            var mr = new MockRepository();

            try
            {
                mr.SetCurrentUser_Andre_CorrectPassword();
                mr.SetRouteData_ConsultorioDrHouse_GregoryHouse(typeof(PracticeHomeController), "Edit");

                homeController = mr.CreateController <PracticeHomeController>(callOnActionExecuting: false);
            }
            catch (Exception ex)
            {
                InconclusiveInit(ex);
                return;
            }

            var viewModel = new PracticeHomeControllerViewModel
            {
                PracticeName     = "", // Cannot set practice name to empty
                PracticeTimeZone = 3
            };

            Mvc3TestHelper.SetModelStateErrors(homeController, viewModel);

            // Execute test: owner must have access to this view.
            var actionResult = Mvc3TestHelper.RunOnAuthorization(homeController, "Edit", "POST")
                               ?? Mvc3TestHelper.RunOnActionExecuting(homeController, "Edit", "POST")
                               ?? homeController.Edit(viewModel);

            // Asserts
            Assert.IsInstanceOfType(actionResult, typeof(ViewResult));
            Assert.AreEqual(null, ((ViewResult)actionResult).View);
        }
예제 #6
0
        public void Test_RunOnActionExecuting()
        {
            var controller = new MyController();

            controller.CallInitialize();
            Mvc3TestHelper.RunOnActionExecuting(controller, "Action");
            Assert.IsTrue(controller.OnActionExecutingCalled);
            Assert.IsTrue(controller.Attribute_OnActionExecutingCalled);
        }
        public void EditPost_UserIsOwner_WithValidData()
        {
            PracticeHomeController homeController;
            var mr = new MockRepository();

            try
            {
                mr.SetCurrentUser_Andre_CorrectPassword();
                mr.SetRouteData_ConsultorioDrHouse_GregoryHouse(typeof(PracticeHomeController), "Edit");

                homeController = mr.CreateController <PracticeHomeController>(callOnActionExecuting: false);
            }
            catch (Exception ex)
            {
                InconclusiveInit(ex);
                return;
            }

            var viewModel = new PracticeHomeControllerViewModel
            {
                PracticeName     = "K!",
                PracticeTimeZone = 3,
                PhoneMain        = "(32)91272552",
                Address          = new AddressViewModel
                {
                    StateProvince = "MG",
                    CEP           = "36030-000",
                    City          = "Juiz de Fora",
                    Complement    = "Sta Luzia",
                    Street        = "Rua Sem Saída",
                }
            };

            Mvc3TestHelper.SetModelStateErrors(homeController, viewModel);

            // Execute test: owner must have access to this view.
            var actionResult = Mvc3TestHelper.RunOnAuthorization(homeController, "Edit", "POST")
                               ?? Mvc3TestHelper.RunOnActionExecuting(homeController, "Edit", "POST")
                               ?? homeController.Edit(viewModel);

            // Asserts
            Assert.IsInstanceOfType(actionResult, typeof(RedirectToRouteResult));
            var redirectResult = (RedirectToRouteResult)actionResult;

            Assert.AreEqual(2, redirectResult.RouteValues.Count);
            Assert.AreEqual("practicehome", string.Format("{0}", redirectResult.RouteValues["controller"]), ignoreCase: true);
            Assert.AreEqual("Index", string.Format("{0}", redirectResult.RouteValues["action"]), ignoreCase: true);
        }