Beispiel #1
0
        public async Task ChangeUserRoleShouldChangeRole()
        {
            //Arrange

            var adminService = new AdminUserService(Context, UserManager);

            User user = new User()
            {
                Name          = "User",
                Email         = "*****@*****.**",
                SecurityStamp = Guid.NewGuid().ToString()
            };

            await UserManager.AddToRoleAsync(user, WebConstants.AdministratorRole);

            await Context.AddAsync(user);

            await Context.SaveChangesAsync();

            //Act

            var newUser = await Context.Users.FirstOrDefaultAsync(u => u.Name == user.Name);

            newUser.UserName = "******";

            var roleChange = WebConstants.AuthorRole;
            var result     = await adminService.ChangeUserRoleAsync(newUser, roleChange);

            //Assert
            var userRole = await UserManager.IsInRoleAsync(newUser, roleChange);

            var userRoles = await UserManager.GetRolesAsync(newUser);

            userRole.Should().Be(true);
            userRoles.Count.Should().Be(1);
        }