Exemple #1
0
        public void should_use_authorizationprovider()
        {
            // Arrange
            WebApiAdminRequiredAttributeMock attribute = new WebApiAdminRequiredAttributeMock();

            attribute.AuthorizationProvider = new AuthorizationProviderMock()
            {
                IsAdminResult = true
            };
            attribute.ApplicationSettings = _applicationSettings;
            attribute.UserService         = _userService;

            IdentityStub identity = new IdentityStub()
            {
                Name = Guid.NewGuid().ToString(), IsAuthenticated = true
            };
            PrincipalStub principal = new PrincipalStub()
            {
                Identity = identity
            };

            Thread.CurrentPrincipal = principal;

            // Act
            bool isAuthorized = attribute.CallAuthorize(new HttpActionContext());

            // Assert
            Assert.That(isAuthorized, Is.True);
        }
Exemple #2
0
        public void Should_Throw_SecurityException_When_AuthorizationProvider_Is_Null()
        {
            // Arrange
            WebApiAdminRequiredAttributeMock attribute = new WebApiAdminRequiredAttributeMock();

            attribute.AuthorizationProvider = null;

            IdentityStub identity = new IdentityStub()
            {
                Name = Guid.NewGuid().ToString(), IsAuthenticated = true
            };
            PrincipalStub principal = new PrincipalStub()
            {
                Identity = identity
            };

            Thread.CurrentPrincipal = principal;

            // Act + Assert
            attribute.CallAuthorize(new HttpActionContext());
        }