public IActionResult AllocateUsers(AllocateUsersRequest request)
        {
            _logger.LogDebug(
                "AllocateUsers No. of UserTypes: {count} Application: {application}", request.UserTypes.Count, request.Application);

            lock (AllocationLock)
            {
                var responses = new List <UserDetailsResponse>();

                foreach (var userType in request.UserTypes)
                {
                    var allocateRequest = new AllocateUserRequest()
                    {
                        AllocatedBy     = request.AllocatedBy,
                        Application     = request.Application,
                        ExpiryInMinutes = request.ExpiryInMinutes,
                        IsEjud          = request.IsEjud,
                        IsProdUser      = request.IsProdUser,
                        TestType        = request.TestType,
                        UserType        = userType
                    };

                    var user = Allocate(allocateRequest);
                    _logger.LogDebug("User '{username}' successfully allocated", user.Result.Username);
                    responses.Add(UserToDetailsResponseMapper.MapToResponse(user.Result));
                }

                _logger.LogInformation("Allocated {count} user(s)", responses.Count);

                return(Ok(responses));
            }
        }
Exemplo n.º 2
0
        private void AllocateUsers(List <UserType> userTypes)
        {
            var expiresIn = _scenario.ScenarioInfo.Tags.Any(x => x.Contains("HearingTest"))
                ? ALLOCATE_USERS_FOR_HEARING_TESTS
                : ALLOCATE_USERS_FOR_MINUTES;

            var request = new AllocateUsersRequest()
            {
                Application       = Application.VideoWeb,
                Expiry_in_minutes = expiresIn,
                Is_prod_user      = _c.VideoWebConfig.IsLive,
                Test_type         = TestType.Automated,
                User_types        = userTypes
            };

            if (_c.VideoWebConfig.SauceLabsConfiguration.RunningOnSauceLabs())
            {
                Thread.Sleep(TimeSpan.FromSeconds(GetRandomNumberForParallelExecution(15)));
            }

            var response = _c.Apis.TestApi.AllocateUsers(request);

            response.StatusCode.Should().Be(HttpStatusCode.OK);
            response.Should().NotBeNull();
            var users = RequestHelper.Deserialise <List <UserDetailsResponse> >(response.Content);

            users.Should().NotBeNullOrEmpty();
            _c.Test.Users = UserDetailsResponseToUsersMapper.Map(users);
            _c.Test.Users.Should().NotBeNullOrEmpty();
        }
Exemplo n.º 3
0
        private void AllocateUsers(List <UserType> userTypes)
        {
            var expiresIn = _scenario.ScenarioInfo.Tags.Any(x => x.Contains("HearingTest"))
                ? ALLOCATE_USERS_FOR_HEARING_TESTS
                : ALLOCATE_USERS_FOR_MINUTES;

            var request = new AllocateUsersRequest()
            {
                Application     = Application.VideoWeb,
                ExpiryInMinutes = expiresIn,
                IsEjud          = _c.VideoWebConfig.UsingEjud,
                IsProdUser      = _c.VideoWebConfig.IsLive,
                TestType        = TestType.Automated,
                UserTypes       = userTypes
            };

            var response = _c.Apis.TestApi.AllocateUsers(request);

            response.StatusCode.Should().Be(HttpStatusCode.OK);
            response.Should().NotBeNull();
            var users = RequestHelper.Deserialise <List <UserDetailsResponse> >(response.Content);

            users.Should().NotBeNullOrEmpty();
            _c.Test.Users = UserDetailsResponseToUsersMapper.Map(users);
            _c.Test.Users.Should().NotBeNullOrEmpty();
        }
Exemplo n.º 4
0
 public AllocateUsersBuilder()
 {
     _request = new AllocateUsersRequest()
     {
         Application     = AllocationData.APPLICATION,
         ExpiryInMinutes = AllocationData.EXPIRY_IN_MINUTES,
         IsProdUser      = UserData.IS_PROD_USER,
         TestType        = AllocationData.TEST_TYPE,
         UserTypes       = new List <UserType>()
     };
 }
        private void Allocate()
        {
            var userTypes = new List <UserType>
            {
                UserType.Judge,
                UserType.VideoHearingsOfficer
            };

            if (_scenario.ScenarioInfo.Tags.Contains(UserType.Individual.ToString()))
            {
                userTypes.Add(UserType.Individual);
            }
            else if (_scenario.ScenarioInfo.Tags.Contains(UserType.Representative.ToString()))
            {
                userTypes.Add(UserType.Representative);
            }
            else if (_scenario.ScenarioInfo.Tags.Contains(UserType.PanelMember.ToString()))
            {
                userTypes.Add(UserType.PanelMember);
                userTypes.Add(UserType.Individual);
            }
            else if (_scenario.ScenarioInfo.Tags.Contains(UserType.Winger.ToString()))
            {
                userTypes.Add(UserType.Winger);
                userTypes.Add(UserType.Individual);
            }
            else
            {
                userTypes.Add(UserType.Individual);
            }

            var request = new AllocateUsersRequest()
            {
                Application     = Application.ServiceWeb,
                ExpiryInMinutes = ALLOCATE_USERS_FOR_MINUTES,
                IsProdUser      = _c.WebConfig.IsLive,
                TestType        = TestType.Automated,
                UserTypes       = userTypes
            };

            var response = _c.Api.AllocateUsers(request);

            response.StatusCode.Should().Be(HttpStatusCode.OK);
            response.Should().NotBeNull();
            var users = RequestHelper.Deserialise <List <UserDetailsResponse> >(response.Content);

            users.Should().NotBeNullOrEmpty();
            _c.Users = UserDetailsResponseToUsersMapper.Map(users);
            _c.Users.Should().NotBeNullOrEmpty();
        }
        public async Task <IActionResult> AllocateUsers(AllocateUsersRequest request)
        {
            _logger.LogDebug("AllocateUsers No. of UserTypes: {count} Application: {application}", request.UserTypes.Count, request.Application);

            try
            {
                var response = await _testApiClient.AllocateMultipleUsersAsync(request);

                _logger.LogDebug("'{count}' users successfully allocated", response.Count);
                return(Ok(response));
            }
            catch (TestApiException e)
            {
                _logger.LogError(e, "Unable to allocate users: {userTypes}", request.UserTypes);
                return(StatusCode(e.StatusCode, e.Response));
            }
        }
Exemplo n.º 7
0
        public void Should_return_allocated_users()
        {
            const UserType JUDGE_USER_TYPE          = UserType.Judge;
            const UserType INDIVIDUAL_USER_TYPE     = UserType.Individual;
            const UserType REPRESENTATIVE_USER_TYPE = UserType.Representative;
            const UserType CASE_ADMIN_USER_TYPE     = UserType.CaseAdmin;

            var judgeUser = CreateUser(JUDGE_USER_TYPE);

            CreateAllocation(judgeUser);

            var individualUser = CreateUser(INDIVIDUAL_USER_TYPE);

            CreateAllocation(individualUser);

            var representativeUser = CreateUser(REPRESENTATIVE_USER_TYPE);

            CreateAllocation(representativeUser);

            var caseAdminUser = CreateUser(CASE_ADMIN_USER_TYPE);

            CreateAllocation(caseAdminUser);

            var request = new AllocateUsersRequest
            {
                Application = Application.TestApi,
                UserTypes   = new List <UserType>
                {
                    JUDGE_USER_TYPE, INDIVIDUAL_USER_TYPE, REPRESENTATIVE_USER_TYPE, CASE_ADMIN_USER_TYPE
                }
            };

            QueryHandler
            .SetupSequence(x =>
                           x.Handle <GetAllocatedUserByUserTypeQuery, UserDto>(It.IsAny <GetAllocatedUserByUserTypeQuery>()))
            .ReturnsAsync(judgeUser)
            .ReturnsAsync(individualUser)
            .ReturnsAsync(representativeUser)
            .ReturnsAsync(caseAdminUser);

            var response = Controller.AllocateUsers(request);

            response.Should().NotBeNull();

            var result = (OkObjectResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.OK);

            var userDetailsResponse = (List <UserDetailsResponse>)result.Value;

            userDetailsResponse.Count.Should().Be(4);

            userDetailsResponse[0].UserType.Should().Be(JUDGE_USER_TYPE);
            userDetailsResponse[0].Should().BeEquivalentTo(judgeUser);

            userDetailsResponse[1].UserType.Should().Be(INDIVIDUAL_USER_TYPE);
            userDetailsResponse[1].Should().BeEquivalentTo(individualUser);

            userDetailsResponse[2].UserType.Should().Be(REPRESENTATIVE_USER_TYPE);
            userDetailsResponse[2].Should().BeEquivalentTo(representativeUser);

            userDetailsResponse[3].UserType.Should().Be(CASE_ADMIN_USER_TYPE);
            userDetailsResponse[3].Should().BeEquivalentTo(caseAdminUser);
        }
Exemplo n.º 8
0
 public AllocateUsersControllerTests()
 {
     _loggerMock = new Mock <ILogger <AllocationController> >();
     _request    = new AllocateUsersBuilder().Judge().Individual().Representative().Build();
 }
Exemplo n.º 9
0
 public AllocateUsersRequestBuilder()
 {
     _request = new AllocateUsersRequest {
         ExpiryInMinutes = 1, TestType = TestType.Automated, IsEjud = false
     };
 }