示例#1
0
        public async Task AddPermissionsToRoleAsyncTest(string roleName, string permissionName, bool successful)
        {
            var role = await DbContext.Set <Role>().FirstAsync(x => x.Name == roleName);

            var permission = await DbContext.Set <Permission>().FirstOrDefaultAsync(x => x.Name == permissionName);

            await repository.AddPermissionsToRoleAsync(role.Id,
                                                       new List <string> {
                permissionName
            });

            if (successful)
            {
                Assert.That(permission, Is.Not.Null);
                Assert.That(await DbContext.Set <RolePermission>()
                            .AnyAsync(x => x.PermissionId == permission !.Id && x.RoleId == role.Id),
                            Is.True);
            }
            else if (permission != null)
            {
                Assert.That(await DbContext.Set <RolePermission>()
                            .AnyAsync(x => x.PermissionId == permission !.Id && x.RoleId == role.Id),
                            Is.False);
            }
        }