public TestBase(Role?role = null, bool periodicalsEnabled = false, bool createLibrary = true) { _periodicalsEnabled = periodicalsEnabled; _role = role; var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); var projectDir = Directory.GetCurrentDirectory(); var configPath = Path.Combine(projectDir, "appsettings.json"); _factory = new WebApplicationFactory <Startup>() .WithWebHostBuilder(builder => { builder.ConfigureAppConfiguration((context, conf) => { conf.AddJsonFile(configPath); if (!string.IsNullOrWhiteSpace(environment)) { conf.AddJsonFile(Path.Combine(projectDir, $"appsettings.json"), true); //conf.AddJsonFile(Path.Combine(projectDir, $"appsettings.{environment}.json"), true); } }); builder.ConfigureTestServices(services => ConfigureServices(services)); }); var settings = Services.GetService <Settings>(); AccountBuilder = _factory.Services.GetService <AccountDataBuilder>(); if (role.HasValue) { AccountBuilder = AccountBuilder.As(_role.Value).Verified(); _account = AccountBuilder.Build(); } if (createLibrary) { var builder = LibraryBuilder.WithPeriodicalsEnabled(_periodicalsEnabled); if (_account != null && role.HasValue) { builder.AssignToUser(AccountId, _role.Value); } Library = builder.Build(); } Client = _factory.CreateClient(); if (_account != null) { var token = TokenBuilder.GenerateToken(settings, _account.Id); Client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token); } }
public async Task Setup() { var library = LibraryBuilder.Build(); var account = AccountBuilder.As(Domain.Models.Role.Admin).Verified().InLibrary(library.Id).Build(); _authResponse = await AccountBuilder.Authenticate(Client, account.Email); AuthenticateClientWithToken(_authResponse.JwtToken); _response = await Client.PostObject("/accounts/refresh-token", new RefreshTokenRequest { RefreshToken = _authResponse.RefreshToken }); _refreshResponse = await _response.GetContent <AuthenticateResponse>(); }
public async Task Setup() { var library = LibraryBuilder.Build(); var account = AccountBuilder.As(Role.Reader) .InLibrary(library.Id) .Verified() .Build(); _response = await Client.PostObject($"/accounts/invite/library/{library.Id}", new InviteUserRequest { Email = account.Email, Role = Role.Reader }); }
public async Task Setup() { _library1 = LibraryBuilder.Build(); _account = AccountBuilder.As(Role.Reader) .InLibrary(_library1.Id) .Verified() .Build(); _library2 = LibraryBuilder.Build(); _response = await Client.PostObject($"/accounts/invite/library/{_library2.Id}", new InviteUserRequest { Email = _account.Email, Role = Role.LibraryAdmin }); }
public async Task Setup() { var account2 = AccountBuilder.As(Role.Reader).Build(); var books = BookBuilder.WithLibrary(LibraryId) .WithCategories(2) .WithAuthors(2) .AddToFavorites(AccountId) .AddToRecentReads(AccountId) .AddToFavorites(account2.Id) .AddToRecentReads(account2.Id) .IsPublic() .Build(20); _response = await Client.GetAsync($"/libraries/{LibraryId}/books?pageNumber=1&pageSize=12"); _assert = new PagingAssert <BookView>(_response); }