コード例 #1
0
        public void Given_not_got_a_valid_custom_principle_When_OnActionExecuting_Then_should_throw_401_not_authorised_exception()
        {
            // Given
            var fakePrincipal = new FakePrincipal();
            var filterContext = new ActionExecutingContext
            {
                HttpContext = MvcMockHelpers.FakeHttpContext(fakePrincipal)
            };

            var permissionFilterAttribute = new PermissionFilterAttribute(Permissions.ViewSiteDetails);


            // When
            permissionFilterAttribute.OnActionExecuting(filterContext);

            // Then
            Assert.That(filterContext.Result, Is.TypeOf<HttpUnauthorizedResult>());

        }
コード例 #2
0
        public void Given_not_got_a_valid_custom_principle_When_OnActionExecuting_Then_should_throw_401_not_authorised_exception()
        {
            // Given
            var fakePrincipal = new FakePrincipal();
            var actionParameters = new Dictionary<string, object> { { "companyId", 1000 } };
            
            var filterContext = new ActionExecutingContext
            {
                HttpContext = MvcMockHelpers.FakeHttpContext(fakePrincipal),
                ActionParameters = actionParameters
            };

            var urlHackingFilter = new UrlHackingFilter();


            // When
            urlHackingFilter.OnActionExecuting(filterContext);

            // Then
            Assert.That(filterContext.Result, Is.TypeOf<HttpUnauthorizedResult>());

        }