Beispiel #1
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            try
            {
                if (filterContext.HttpContext.Session.GetInt32("RoleId") == null)
                {
                    filterContext.HttpContext.Response.Redirect("/Home/Login?error=2");
                }

                var             roleId = filterContext.HttpContext.Session.GetInt32("RoleId");
                AuthorizeEngine engine = new AuthorizeEngine();

                bool grantAccess = engine.Authorize(task, Convert.ToInt32(roleId));

                if (!grantAccess)
                {
                    var controller = (ControllerBase)filterContext.Controller;
                    filterContext.Result = controller.RedirectToAction("UnAuthorized", "Home");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        public void Authorize_TestUsingPractitionerStaffRole_ExpedAuthorization(Tasks task, bool expectedOutcome)
        {
            //Arrange
            AuthorizeEngine engine = new AuthorizeEngine();
            int             practitionerStaffRoleId = 3;

            //Act
            bool authorization = engine.Authorize(task, practitionerStaffRoleId);

            //Assert
            Assert.That(authorization, Is.EqualTo(expectedOutcome));
        }
        public void Authorize_UsingInvalidRoleId_ExpedAuthorization()
        {
            //Arrange
            AuthorizeEngine engine        = new AuthorizeEngine();
            int             invalidRoleId = -1;

            //Act
            bool authorization = engine.Authorize(Tasks.ViewAppointments, invalidRoleId);

            //Assert
            Assert.That(authorization, Is.EqualTo(false));
        }