private async Task InitOnce()
    {
      if (_app != null) return;

      _app = new DefaultWebApplicationFactory();
      var options = new WebApplicationFactoryClientOptions()
      {
        AllowAutoRedirect = false
      };
      _httpClient = _app.CreateClient(options);
      _apiClient = new ApiClient(_httpClient, _app.GetLogger<ApiClient>());

      // create tenants here
      await _apiClient.AsSiteAdminAsync(_httpClient);
      _gryffindorHouse = await TestTenants.CreateTenantWithRolesAndUsers(_apiClient, _httpClient, TestTenants.GryffindorHouse);
      await TestBranchOffice.SeedDefaultBranchOffice(_apiClient, _httpClient, _gryffindorHouse);
      await TestDepartment.SeedDefaultDepartments(_apiClient, _gryffindorHouse);
      await TestPosition.SeedDefaultPosition(_apiClient, _gryffindorHouse);
      await TestEmployees.SeedDefaultEmployees(_apiClient, _gryffindorHouse);
      _gryffindorEmployees = (await _apiClient.GetEmployeesAsync()).ToList();

      await _apiClient.AsSiteAdminAsync(_httpClient);
      _slytherinHouse = await TestTenants.CreateTenantWithRolesAndUsers(_apiClient, _httpClient, TestTenants.SlytherinHouse);
      await TestBranchOffice.SeedDefaultBranchOffice(_apiClient, _httpClient, _slytherinHouse);
      await TestDepartment.SeedDefaultDepartments(_apiClient, _slytherinHouse);
      await TestPosition.SeedDefaultPosition(_apiClient, _slytherinHouse);
      await TestEmployees.SeedDefaultEmployees(_apiClient, _slytherinHouse);
    }
Beispiel #2
0
        private async Task InitOnce()
        {
            if (_app != null)
            {
                return;
            }

            LogHelper.ConfigureConsoleLogger();

            _app = new DefaultWebApplicationFactory();

            var options = new WebApplicationFactoryClientOptions {
                AllowAutoRedirect = false
            };

            _httpClient = _app.CreateClient(options);

            var apiClient = new ApiClient(_httpClient, _app.GetLogger <ApiClient>());

            apiClient.TraceResponseOnException = true;

            _apiClient = apiClient;

            // site admin creates 2 tenants
            await _apiClient.AsSiteAdminAsync(_httpClient);

            _gryffindorHouse = await TestTenants.CreateTenantWithRolesAndUsers(_apiClient, _httpClient, TestTenants.GryffindorHouse);

            await _apiClient.AsSiteAdminAsync(_httpClient);

            _slytherinHouse = await TestTenants.CreateTenantWithRolesAndUsers(_apiClient, _httpClient, TestTenants.SlytherinHouse);

            // Slytherin House admin creates branch office and departments
            await _apiClient.AsSlytherinAdminAsync(_httpClient);

            TestBranchOffice.SeedDefaultBranchOffice(_apiClient, _httpClient, _slytherinHouse).Wait();
            TestDepartment.SeedDefaultDepartments(_apiClient, _slytherinHouse).Wait();
            TestPosition.SeedDefaultPosition(_apiClient, _slytherinHouse).Wait();
            TestEmployees.SeedDefaultEmployees(_apiClient, _slytherinHouse).Wait();

            // Gryffindor House admin creates branch office and departments
            await _apiClient.AsGryffindorAdminAsync(_httpClient);

            TestBranchOffice.SeedDefaultBranchOffice(_apiClient, _httpClient, _gryffindorHouse).Wait();
            TestDepartment.SeedDefaultDepartments(_apiClient, _gryffindorHouse).Wait();
            TestPosition.SeedDefaultPosition(_apiClient, _gryffindorHouse).Wait();
            TestEmployees.SeedDefaultEmployees(_apiClient, _gryffindorHouse).Wait();

            _workDepartmentId = _gryffindorHouse.Department_1_2.Department.Id;
        }