public async Task UnbanAsync_ShouldSuccessfullyUnbanBannedUser() { var testUsername = "******"; // Arrange var serviceFactory = new ServiceFactory(); var userRepository = new EfDeletableEntityRepository <ApplicationUser>(serviceFactory.Context); var usersService = new UsersService(userRepository, serviceFactory.UserManager); await serviceFactory.SeedRoleAsync(GlobalConstants.BannedRoleName); var user = new ApplicationUser() { UserName = testUsername, }; await userRepository.AddAsync(user); await userRepository.SaveChangesAsync(); var userFromDb = userRepository.All().FirstOrDefault(x => x.UserName == testUsername); var userId = user.Id; await usersService.BanAsync(userId); // Act await usersService.UnbanAsync(userId); // Assert Assert.True(!await serviceFactory.UserManager.IsInRoleAsync(userFromDb, GlobalConstants.BannedRoleName)); }
public async Task IsBannedAsync_WhenUserIsBanned_ShouldReturnCorrectResult() { var testUsername = "******"; // Arrange var serviceFactory = new ServiceFactory(); var userRepository = new EfDeletableEntityRepository <ApplicationUser>(serviceFactory.Context); var usersService = new UsersService(userRepository, serviceFactory.UserManager); await serviceFactory.SeedRoleAsync(GlobalConstants.BannedRoleName); var user = new ApplicationUser() { UserName = testUsername, }; await userRepository.AddAsync(user); await userRepository.SaveChangesAsync(); var userFromDb = userRepository.All().FirstOrDefault(x => x.UserName == testUsername); var userId = user.Id; await usersService.BanAsync(userId); // Act var actualResult = await usersService.IsBannedAsync(userId); // Assert Assert.True(actualResult); }
public async Task BanAsync_WithIncorrectData_ShouldThrowArgumentNullException(string incorrectId) { // Arrange var serviceFactory = new ServiceFactory(); var userRepository = new EfDeletableEntityRepository <ApplicationUser>(serviceFactory.Context); var usersService = new UsersService(userRepository, serviceFactory.UserManager); // Act // Assert await Assert.ThrowsAsync <ArgumentException>(async() => { await usersService.BanAsync(incorrectId); }); }