public async Task BlockUnblockUserByIdAsyncShouldUnBlockUserSuccessfully() { var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new MyCalisthenicAppDbContext(options); IHttpContextAccessor httpContextAccessor = new HttpContextAccessor(); var mockMapper = new MapperConfiguration(cfg => { cfg.AddProfile(new MyCalisthenicAppProfile()); }); var mapper = mockMapper.CreateMapper(); var usersService = new UsersService(httpContextAccessor, dbContext, mapper); for (int i = 0; i < 3; i++) { var user = new ApplicationUser { FirstName = UserFirstName, LastName = UserLastName, }; await dbContext.Users.AddAsync(user); await dbContext.SaveChangesAsync(); } var userToDelete = new ApplicationUser { Id = UserId, FirstName = UserFirstName, LastName = UserLastName, IsDeleted = true, }; await dbContext.Users.AddAsync(userToDelete); await dbContext.SaveChangesAsync(); var expected = await usersService.BlockUnblockUserByIdAsync(UserId); Assert.False(expected.IsDeleted); }
public async Task BlockUnblockUserByIdAsyncShouldThrowExceptionIfUserIsNull() { var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new MyCalisthenicAppDbContext(options); IHttpContextAccessor httpContextAccessor = new HttpContextAccessor(); var mockMapper = new MapperConfiguration(cfg => { cfg.AddProfile(new MyCalisthenicAppProfile()); }); var mapper = mockMapper.CreateMapper(); var usersService = new UsersService(httpContextAccessor, dbContext, mapper); var exception = await Assert.ThrowsAsync <NullReferenceException>(async() => await usersService.BlockUnblockUserByIdAsync(UserId)); Assert.IsType <NullReferenceException>(exception); }