public override async Task InitializeAsync() { await base.InitializeAsync(); HttpClient = TestServer.CreateClient(); _userLogin = TestServer.Host.Services.GetRequiredService <IOptions <UserLoginOption> >()?.Value; HttpServiceTest = TestServer.Host.Services.GetRequiredService <IHttpServiceTest>(); _adminToken = await HttpServiceTest.GetAuthorizationToken(_userLogin); AccountAdmin = await HttpServiceTest.CreateNewTestUser(FormCreateUserModel(ConstTest.Role.AccountAdmin), _adminToken); OperationAdmin = await HttpServiceTest.CreateNewTestUser(FormCreateUserModel(ConstTest.Role.OperationAdmin), _adminToken); SystemAdmin = await HttpServiceTest.CreateNewTestUser(FormCreateUserModel(ConstTest.Role.SystemAdmin), _adminToken); Manager = await HttpServiceTest.CreateNewTestUser(FormCreateUserModel(ConstTest.Role.Manager), _adminToken); Company = await HttpServiceTest.GetTestCompany(ConstTest.DefaultCompanyName, _adminToken); CompanyWithoutAnyBranch = await HttpServiceTest.GetTestCompany(ConstTest.DefaultCompanyNameNotBindAnyBranch, _adminToken); Branch = await HttpServiceTest.GetTestBranch(ConstTest.DefaultBranchName, _adminToken); Supervisor = await HttpServiceTest.CreateNewTestUser(FormCreateUserModel(ConstTest.Role.Supervisor, Company.Id, Branch.Id), _adminToken); SupervisorWithCompanyWithoutBranch = await HttpServiceTest.CreateNewTestUser(FormCreateUserModel(ConstTest.Role.Supervisor, CompanyWithoutAnyBranch.Id), _adminToken); Users = FillingUser(); }
public async Task InitializeAsync() { lock (_lock) { var builder = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: true); var configuration = builder.Build(); IWebHostBuilder webHostBuild = WebHost.CreateDefaultBuilder() .UseStartup <TestStartUp>() .UseWebRoot(Directory.GetCurrentDirectory()) .UseContentRoot(Directory.GetCurrentDirectory()); var cableDbConnectionString = configuration.GetConnectionString("cpdb"); var dbConnectionString = configuration.GetConnectionString("db"); if (string.IsNullOrWhiteSpace(cableDbConnectionString) || string.IsNullOrWhiteSpace(dbConnectionString)) { throw new ApplicationException("Missing the connection string to database"); } ; webHostBuild.ConfigureServices(service => { service.AddDbContextPool <CablePortalAppDataContext>(ctxOptions => { ctxOptions.UseInMemoryDatabase(cableDbConnectionString).EnableSensitiveDataLogging(); ctxOptions.ConfigureWarnings(x => x.Ignore(InMemoryEventId.TransactionIgnoredWarning)); }); service.AddDbContextPool <AppDataContext>(ctxOptions => { ctxOptions.UseInMemoryDatabase(dbConnectionString).EnableSensitiveDataLogging(); ctxOptions.ConfigureWarnings(x => x.Ignore(InMemoryEventId.TransactionIgnoredWarning)); }); service.Configure <UserLoginOption>(options => configuration.Bind("TestUserCredential", options)); service.AddScoped <IHttpServiceTest, HttpServiceTest>(); string azureStorageConnectionString = configuration["connectionStrings:storageAccount"]; if (!CloudStorageAccount.TryParse(azureStorageConnectionString, out CloudStorageAccount storageAccount)) { throw new ApplicationException("Missing Azure Blob Storage settings"); } var blobStorageClient = storageAccount.CreateCloudBlobClient(); _cloudBlobContainer = blobStorageClient.GetContainerReference(DefaultCompanyId.ToString()); if (_cloudBlobContainer == null) { throw new ApplicationException("Blob container not exist"); } }); TestServer = new TestServer(webHostBuild); CableDbContext = TestServer.Host.Services.GetRequiredService <CablePortalAppDataContext>(); DbContext = TestServer.Host.Services.GetRequiredService <AppDataContext>(); TestSeed = TestServer.Host.Services.GetRequiredService <TestSeed>(); HttpClient = TestServer.CreateClient(); Fixture = new Fixture(); Fixture.Customizations.Add(new IgnoreVirtualMembers()); _userLogin = TestServer.Host.Services.GetRequiredService <IOptions <UserLoginOption> >()?.Value; HttpServiceTest = TestServer.Host.Services.GetRequiredService <IHttpServiceTest>(); } AdminToken = await HttpServiceTest.GetAuthorizationToken(_userLogin); AdminProfile = await HttpServiceTest.GetUserProfile(AdminToken); }