Beispiel #1
0
        public void OnActionExecuting_UnauthorizedResult()
        {
            // Arrange

            var filter = new AuthorizeFilter();

            Controller = new CustomerController(null)
            {
                AccountService = AccountService,

                AccountTicket = null
            };

            var actionExecutingContext =
                MockHelper.ActionExecutingContext(Controller);

            // Act

            filter.OnActionExecuting(actionExecutingContext);

            // Assert

            Assert.IsNotNull(actionExecutingContext.Result);

            Assert.IsInstanceOf <UnauthorizedResult>
                (actionExecutingContext.Result);
        }
Beispiel #2
0
        public void OnActionExecuting_Area_UnauthorizedResult
            (ModeEnum mode)
        {
            // Arrange

            var filter = new AuthorizeFilter
                             (AreaEnum.Customer, mode);

            var access = new AreaAccess
            {
                AreaId = (int)AreaEnum.Customer,
                Group  = new Group
                {
                    Name       = "Test",
                    UserGroups = new[]
                    {
                        new UserGroup
                        {
                            UserId = AccountTicket.Id
                        }
                    }
                },
                CanRead = true
            };

            DbContext.AreaAccess.Add(access);

            DbContext.SaveChanges();

            Controller = new CustomerController(null)
            {
                AccountService = AccountService,

                AccountTicket = AccountTicket
            };

            var actionExecutingContext =
                MockHelper.ActionExecutingContext(Controller);

            // Act

            filter.OnActionExecuting(actionExecutingContext);

            // Assert

            Assert.IsNotNull(actionExecutingContext.Result);

            Assert.IsInstanceOf <UnauthorizedResult>
                (actionExecutingContext.Result);
        }
Beispiel #3
0
        public void OnActionExecuting_Area(ModeEnum mode)
        {
            // Arrange

            var filter = new AuthorizeFilter
                             (AreaEnum.Customer, mode);

            var access = new AreaAccess
            {
                AreaId = (int)AreaEnum.Customer,
                Group  = new Group
                {
                    Name       = "Test",
                    UserGroups = new[]
                    {
                        new UserGroup
                        {
                            UserId = AccountTicket.Id
                        }
                    }
                },
                CanRead   = mode.HasFlag(ModeEnum.Read),
                CanCreate = mode.HasFlag(ModeEnum.Create),
                CanModify = mode.HasFlag(ModeEnum.Modify),
                CanDelete = mode.HasFlag(ModeEnum.Delete)
            };

            DbContext.AreaAccess.Add(access);

            DbContext.SaveChanges();

            Controller = new CustomerController(null)
            {
                AccountService = AccountService,

                AccountTicket = AccountTicket
            };

            var actionExecutingContext =
                MockHelper.ActionExecutingContext(Controller);

            // Act

            filter.OnActionExecuting(actionExecutingContext);

            // Assert

            Assert.IsNull(actionExecutingContext.Result);
        }
Beispiel #4
0
        public void OnActionExecuting_Policy_UnauthorizedResult()
        {
            // Arrange

            var filter = new AuthorizeFilter
                             (PolicyEnum.User_ChangePassword);

            var access = new PolicyAccess
            {
                PolicyId = (int)PolicyEnum.User_ChangeEmail,
                Group    = new Group
                {
                    Name       = "Test",
                    UserGroups = new[]
                    {
                        new UserGroup
                        {
                            UserId = AccountTicket.Id
                        }
                    }
                }
            };

            DbContext.PolicyAccess.Add(access);

            DbContext.SaveChanges();

            Controller = new CustomerController(null)
            {
                AccountService = AccountService,

                AccountTicket = AccountTicket
            };

            var actionExecutingContext =
                MockHelper.ActionExecutingContext(Controller);

            // Act

            filter.OnActionExecuting(actionExecutingContext);

            // Assert

            Assert.IsNotNull(actionExecutingContext.Result);

            Assert.IsInstanceOf <UnauthorizedResult>
                (actionExecutingContext.Result);
        }