public async Task AddAdministratorShouldAddUserWithGivenEmailAsAdministrator() { var userEmail = "[email protected]"; var roleName = "Administrator"; var user = new ApplicationUser() { Email = userEmail, }; var role = new ApplicationRole() { Name = roleName, }; var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("authtestr"); var db = new ApplicationDbContext(options.Options); await db.Users.AddAsync(user); await db.Roles.AddAsync(role); await db.SaveChangesAsync(); var service = new AuthorizationsService(db); await service.AddAdministrator(userEmail); var userRole = db.UserRoles.FirstOrDefault(ur => ur.UserId == user.Id && ur.RoleId == role.Id); Assert.NotNull(userRole); }
/// <summary> /// Get the <see cref="InfluxDB.Client.Api.Domain.Authorization" /> client. /// </summary> /// <returns>the new client instance for Authorization API</returns> public AuthorizationsApi GetAuthorizationsApi() { var service = new AuthorizationsService((Configuration)_apiClient.Configuration) { ExceptionFactory = _exceptionFactory }; return(new AuthorizationsApi(service)); }
public async Task AddAdministratorShouldThrowArgumentNullExceptionIfGivenInvalidEmail() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("authtest"); var db = new ApplicationDbContext(options.Options); var service = new AuthorizationsService(db); await Assert.ThrowsAsync <ArgumentNullException>(async() => await service.AddAdministrator("[email protected]")); }
public async Task AddAdministratorShouldThrowInvalidOperationExceptionIfThereIsNoAdministrationRole() { var userEmail = "[email protected]"; var user = new ApplicationUser() { Email = userEmail, }; var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("authtest"); var db = new ApplicationDbContext(options.Options); await db.Users.AddAsync(user); await db.SaveChangesAsync(); var service = new AuthorizationsService(db); await Assert.ThrowsAsync <InvalidOperationException>(async() => await service.AddAdministrator(user.Email)); }
protected internal AuthorizationsApi(AuthorizationsService service) { Arguments.CheckNotNull(service, nameof(service)); _service = service; }