示例#1
0
        public bool DoesUserHavePermission(UserPermissionsApiModel userPermissions, string permission)
        {
            if (userPermissions == null)
            {
                return(false);
            }

            CheckIfStringNullOrEmpty(permission, nameof(permission));

            return(userPermissions.Permissions.Any(p => p == permission));
        }
        public void DoesUserHavePermission_NullUserPermissions_False()
        {
            // Arrange
            string permission = "awesomepermission";
            UserPermissionsApiModel userPermissions = null;

            // Act
            var result = _subject.DoesUserHavePermission(userPermissions, permission);

            //Assert
            Assert.False(result);
        }
        public void DoesUserHavePermission_NullPermission_ThrowAuthorizationException()
        {
            // Arrange
            string permission      = null;
            var    userPermissions = new UserPermissionsApiModel();

            // Act
            try
            {
                _subject.DoesUserHavePermission(userPermissions, permission);
            }
            catch (Exception exc)
            {
                // Assert
                var authorizationException = exc as AuthorizationException;
                Assert.NotNull(authorizationException);
                Assert.Contains("Value permission cannot be null or empty.", exc.Message);
            }
        }
 /// <summary>
 /// This is the test initializer.
 /// </summary>
 public AuthorizationClientTests()
 {
     _client             = new HttpClient();
     _client.BaseAddress = new Uri("https://example.com/authorization2/");
     _subject            = new AuthorizationClient(_client);
     _userPermission     = new UserPermissionsApiModel
     {
         PermissionRequestContexts = new List <PermissionRequestContext>
         {
             new PermissionRequestContext
             {
                 RequestedGrain         = "app",
                 RequestedSecurableItem = "unit-test"
             }
         },
         Permissions = new List <string>
         {
             "edit",
             "view"
         }
     };
 }