Пример #1
0
        public async Task CreateDepartment_ShouldSucceed_GivenDuplicateNames_InTwoTenants()//
        {
            // Given
            // user authenticated in tenant #1 (Gryffindor House)
            var departmentDto = new DepartmentDto
            {
                Name           = "Department #101",
                BranchOfficeId = _gryffindorHouse.BranchOffice_One.Id.ToString()
            };
            // created a tenant with the name "Department #100"
            var createdDepartmentId_t1 = await _apiClient.PostDepartmentAsync(departmentDto);

            Console.WriteLine($"Create {departmentDto} => {createdDepartmentId_t1}");

            // switch to tenant #2
            await _apiClient.AsSlytherinAdminAsync(_httpClient);

            // When
            // user from different tenant creates a Department with the name
            // duplicating name of a Department in a different tenant...
            departmentDto.BranchOfficeId = _slytherinHouse.BranchOffice_One.Id.ToString();
            departmentDto.Id             = null;
            var createdDepartmentId_t2 = await _apiClient.PostDepartmentAsync(departmentDto);;

            // Then
            // the request should succeed -- no exception has been thrown
            Console.WriteLine($"Create {departmentDto} => {createdDepartmentId_t2}");
        }
Пример #2
0
        public async Task CreateEmployee_ShouldSucceed_GivenDuplicateNames_InTwoTenants()//
        {
            // Given
            // user authenticated in tenant #1 (Gryffindor House)
            var employeeDto = new EmployeePostDto
            {
                FirstName    = "First Name #101",
                LastName     = "Last Name #101",
                DepartmentId = _gryffindorHouse.Department_1_1.Department.Id,
                PositionId   = _gryffindorHouse.Position_Default.Id
            };
            // created an employee with the name above
            await _apiClient.PostEmployeeAsync(employeeDto);

            // switch to tenant #2
            await _apiClient.AsSlytherinAdminAsync(_httpClient);

            // When
            // user from different tenant creates a Employee with the name
            // duplicating name of a Employee in a different tenant...

            var employeeDto2 = new EmployeePostDto
            {
                FirstName    = "First Name #101",
                LastName     = "Last Name #101",
                DepartmentId = _slytherinHouse.Department_1_1.Department.Id,
                PositionId   = _slytherinHouse.Position_Default.Id
            };

            await _apiClient.PostEmployeeAsync(employeeDto2);

            // Then
            // the request should succeed
        }
        public async Task CreatePosition_ShouldSucceed_GivenSameNames_InTwoTenants()//
        {
            // Given
            // user authenticated in tenant #1 (Gryffindor House)
            var positionDto = new PositionDto
            {
                Name = "Position #101"
            };
            // created a tenant with the name "Position #100"
            var newGryffindorPositionId = await _apiClient.PostPositionAsync(positionDto);

            // switch to tenant #2
            await _apiClient.AsSlytherinAdminAsync(_httpClient);

            // When
            // user from different tenant creates a Position with the name
            // duplicating name of a Position in a different tenant...
            positionDto.Id = null;
            var newSlytherinPositionId = await _apiClient.PostPositionAsync(positionDto);

            // Then
            // the request should succeed

            Assert.That(newSlytherinPositionId, Is.Not.EqualTo(newGryffindorPositionId));
        }
    private async Task SeedTestInspections(IApiClient apiClient)
    {
      {
        await apiClient.AsGryffindorAdminAsync(_httpClient);

        var newEmployee = new EmployeeDto
        {
          FirstName = "John",
          LastName = "Doe",
          Patronymic = "Alan",
          PositionId = _gryffindorHouse.Position_Default.Id,
          DepartmentId = _gryffindorHouse.Department_1_1.Department.Id,
          BranchOfficeId = _gryffindorHouse.BranchOffice_One.Id
        };
        var employeeId = await apiClient.PostEmployeeAsync(newEmployee);

        var gryInspection = new InspectionDto
        {
          Id = Guid.NewGuid().ToString(),
          MethodSetId = "Method_Set_Id",
          StartTime = DateTime.Now - TimeSpan.FromMinutes(700),
          FinishTime = DateTime.Now - TimeSpan.FromMinutes(700),
          InspectionPlace = InspectionPlace.OnWorkplace,
          InspectionType = InspectionType.PreShift,
          EmployeeId = employeeId.ToString(),
          MachineName = "HOST002-gry",
          MethodSetVersion = "Version 16"
        };
        _gryffindorInspectionId = await PostManyInspections(apiClient, gryInspection);
      }
      {
        await apiClient.AsSlytherinAdminAsync(_httpClient);

        var newEmployee = new EmployeeDto
        {
          FirstName = "John",
          LastName = "Doe",
          Patronymic = "Alan",
          PositionId = _slytherinHouse.Position_Default.Id,
          DepartmentId = _slytherinHouse.Department_1_1.Department.Id,
          BranchOfficeId = _slytherinHouse.BranchOffice_One.Id
        };
        var employeeId = await apiClient.PostEmployeeAsync(newEmployee);

        var slyInspection = new InspectionDto
        {
          Id = Guid.NewGuid().ToString(),
          MethodSetId = "Method_Set_Id",
          StartTime = DateTime.Now - TimeSpan.FromMinutes(700),
          FinishTime = DateTime.Now - TimeSpan.FromMinutes(700),
          InspectionPlace = InspectionPlace.OnWorkplace,
          InspectionType = InspectionType.PreShift,
          EmployeeId = employeeId.ToString(),
          MachineName = "HOST002-sly",
          MethodSetVersion = "Version 16"
        };
        _slytherinInspectionId = await PostManyInspections(apiClient, slyInspection);
      }
    }
Пример #5
0
        private async Task InitOnce()
        {
            if (_app != null)
            {
                return;
            }

            LogHelper.ConfigureConsoleLogger();

            _app = new DefaultWebApplicationFactory();

            var options = new WebApplicationFactoryClientOptions()
            {
                AllowAutoRedirect = false
            };

            _httpClient = _app.CreateClient(options);

            _unauthorizedHttpClient = _app.CreateClient(options);
            _unauthorizedHttpClient.DefaultRequestHeaders.Add("accept", "application/json");

            _apiClient = new ApiClient(_httpClient, _app.GetLogger <ApiClient>());
            await _apiClient.AsSiteAdminAsync(_httpClient);

            _siteAdminUser = await _apiClient.GetCurrentUserAsync();

            _siteRoles = (await _apiClient.GetRolesAsync()).ToList();

            {
                var gryffindorTenant = await TestTenants.CreateTenantWithRolesAndUsers(
                    _apiClient, _httpClient, TestTenants.GryffindorHouse);

                _gryffindorAdminUser = gryffindorTenant.AdminUser;

                await _apiClient.AsGryffindorAdminAsync(_httpClient);

                _gryffindorRoles = (await _apiClient.GetRolesAsync()).ToList();

                _gryffindorAdminRoleId = gryffindorTenant.TenantAdminRoleId.ToString();
            }

            await _apiClient.AsSiteAdminAsync(_httpClient);

            {
                var slytherinTenant = await TestTenants.CreateTenantWithRolesAndUsers(
                    _apiClient, _httpClient, TestTenants.SlytherinHouse);

                _slytherinAdminUser = slytherinTenant.AdminUser;

                await _apiClient.AsSlytherinAdminAsync(_httpClient);

                _slytherinRoles = (await _apiClient.GetRolesAsync()).ToList();

                _slytherinAdminRoleId = slytherinTenant.TenantAdminRoleId.ToString();
            }
        }
Пример #6
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;
        }
Пример #7
0
        public async Task Get_Summary_Should_Return_403_Given_Wrong_Tenant()
        {
            // Given
            // client authenticated as operator workplace in Gryffindor
            await _apiClient.SignInWithWorkplaceCredentialsAsync(
                _operatorWorkplaceCredentials.ClientId,
                _operatorWorkplaceCredentials.ClientSecret,
                PskOnlineScopes.DeptOperatorWorkplace);

            var employees = await _apiClient.GetDepartmentEmployeesAsync(_workDepartmentId);

            var branchOfficeId = _apiClient.GetIdToken().GetBranchOfficeIdClaimValue();
            var departmentId   = _apiClient.GetIdToken().GetDepartmentIdClaimValue();

            var inspectionData = GetInspectionData(
                employees.First(),
                GetCurrentIrkutskTimeWithOffset(TimeSpan.FromMinutes(5)),
                SampleTestDataJson.Sample_995_Hrv_Pass,
                SampleTestDataJson.Sample_995_Svmr_
                );
            var completionResponse = await UploadInspectionData(inspectionData);

            // having submitted a new inspection with a special Rushydro method set ID
            var rushydroResult = completionResponse
                                 .PluginResults.FirstOrDefault(p => p.PluginType == RusHydroPluginTypeId);

            // When
            // a user from a different tenant requests the summary for the completed inspection
            await _apiClient.AsSlytherinAdminAsync(_httpClient);

            AsyncTestDelegate action = async() =>
                                       await _apiClient.HttpGetAsJsonFromRelativeUriAsync <PsaSummaryDto>(rushydroResult.ResultsUrl);

            // Then
            // the request should return 403 - Unauthorized
            Assert.ThrowsAsync <ItemNotFoundException>(action);

            // And the same URL requested by Gryffindor admin should succeed
            await _apiClient.AsGryffindorAdminAsync(_httpClient);

            var summary = await _apiClient.HttpGetAsJsonFromRelativeUriAsync <PsaSummaryDto>(rushydroResult.ResultsUrl);

            Assert.That(summary.BranchOfficeId, Is.EqualTo(branchOfficeId));
        }
Пример #8
0
        private async Task InitOnce()
        {
            if (_app != null)
            {
                return;
            }

            LogHelper.ConfigureConsoleLogger();

            _app = new DefaultWebApplicationFactory();

            var options = new WebApplicationFactoryClientOptions()
            {
                AllowAutoRedirect = false
            };

            _httpClient = _app.CreateClient(options);

            _apiClient = new ApiClient(_httpClient, _app.GetLogger <ApiClient>());
            // admin creates Gryffindor tenant and initializes default branch office
            await _apiClient.AsSiteAdminAsync(_httpClient);

            _siteAdminUser = await _apiClient.GetCurrentUserAsync();

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

            await _apiClient.AsGryffindorAdminAsync(_httpClient);

            await TestBranchOffice.SeedDefaultBranchOffice(_apiClient, _httpClient, _gryffindorHouse);

            // admin creates Slytherin tenant and initializes default branch office
            await _apiClient.AsSiteAdminAsync(_httpClient);

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

            await _apiClient.AsSlytherinAdminAsync(_httpClient);

            await TestBranchOffice.SeedDefaultBranchOffice(_apiClient, _httpClient, _slytherinHouse);
        }
Пример #9
0
        public async Task Create_ShouldSucceed_SameNameDifferentTenants()
        {
            // Given
            // Gryffindor admin user having just created a user of the specified name
            var sharedUserName = "******";

            {
                await _apiClient.AsGryffindorAdminAsync(_httpClient);

                var user = new UserEditDto
                {
                    UserName    = sharedUserName,
                    NewPassword = "******",
                    FirstName   = "First Name",
                    LastName    = "Last Name",
                    Patronymic  = "Patronymic",
                    Email       = sharedUserName + "@psk-online.ru",
                    IsEnabled   = true,
                    Roles       = _mapper.Map <List <UserRoleInfo> >(_gryffindorRoles)
                };
                var tenantId      = _apiClient.GetIdToken().GetTenantIdClaimValue();
                var opsStatBefore = await _apiClient.GetTenantOperationsSummaryAsync(tenantId);

                var usersBefore = opsStatBefore.ServiceActualUsers;

                var createUserResponse = _httpClient.PostAsJsonAsync(_url, user).Result;
                Console.WriteLine("create in Gryffindor => \r\n" + createUserResponse.Content.ReadAsStringAsync().Result);

                Assert.That(
                    createUserResponse.StatusCode,
                    Is.EqualTo(HttpStatusCode.Created)
                    );

                var opsStatAfter = await _apiClient.GetTenantOperationsSummaryAsync(tenantId);

                var usersAfter = opsStatAfter.ServiceActualUsers;

                Assert.That(
                    usersBefore + 1,
                    Is.EqualTo(usersAfter));

                await _apiClient.SignInWithUserPassword_WithSlug_Async(
                    user.UserName, user.NewPassword,
                    _httpClient, TestData.TestTenants.GryffindorHouse.Slug);
            }

            // When
            // Slytherin admin atempts to create a user of the same name and email
            {
                await _apiClient.AsSlytherinAdminAsync(_httpClient);

                var user = new UserEditDto
                {
                    UserName    = sharedUserName,
                    NewPassword = "******",
                    FirstName   = "First Name",
                    LastName    = "Last Name",
                    Patronymic  = "Patronymic",
                    Email       = sharedUserName + "@psk-online.ru",
                    IsEnabled   = true,
                    Roles       = _mapper.Map <List <UserRoleInfo> >(_slytherinRoles)
                };
                var tenantId      = _apiClient.GetIdToken().GetTenantIdClaimValue();
                var opsStatBefore = await _apiClient.GetTenantOperationsSummaryAsync(tenantId);

                var usersBefore = opsStatBefore.ServiceActualUsers;

                var createUserResponse = _httpClient.PostAsJsonAsync(_url, user).Result;
                Console.WriteLine("create in Slytherin => \r\n=> " + createUserResponse.Content.ReadAsStringAsync().Result);

                // Then
                // the request should succeed
                Assert.That(
                    createUserResponse.StatusCode,
                    Is.EqualTo(HttpStatusCode.Created)
                    );

                var opsStatAfter = await _apiClient.GetTenantOperationsSummaryAsync(tenantId);

                var usersAfter = opsStatAfter.ServiceActualUsers;

                Assert.That(
                    usersBefore + 1,
                    Is.EqualTo(usersAfter));

                await _apiClient.SignInWithUserPassword_WithSlug_Async(
                    user.UserName, user.NewPassword,
                    _httpClient, TestData.TestTenants.SlytherinHouse.Slug);
            }
        }