Ejemplo n.º 1
0
        public void UnallocateUsers(TestContext context)
        {
            if (context?.Apis?.TestApi == null)
            {
                return;
            }
            if (context.Test.Users.IsNullOrEmpty())
            {
                return;
            }

            var usernames = context.Test.Users.Select(user => user.Username).ToList();

            if (usernames.Count <= 0)
            {
                return;
            }

            var request = new UnallocateUsersRequest()
            {
                Usernames = usernames
            };

            var response = context.Apis.TestApi.UnallocateUsers(request);

            response.StatusCode.Should().Be(HttpStatusCode.OK);
        }
        public async Task <IActionResult> UnallocateUsersByUsername(UnallocateUsersRequest request)
        {
            _logger.LogDebug("UnallocateUsersByUsername");

            var allocations = new List <Allocation>();

            foreach (var username in request.Usernames)
            {
                var user = await GetUserByUsername(username);

                if (user == null)
                {
                    return(NotFound());
                }

                var allocation = await GetAllocationByUsername(user.Username);

                if (allocation == null)
                {
                    return(BadRequest($"No allocation exists for user with username {user.Username}"));
                }

                await Unallocate(username);

                allocation = await GetAllocationByUsername(user.Username);

                allocations.Add(allocation);
            }

            var response = allocations.Select(AllocationToDetailsResponseMapper.MapToResponse).ToList();

            _logger.LogInformation($"Unallocated {response.Count} user(s)");

            return(Ok(response));
        }
        public void UnallocateUsers(TestContext context)
        {
            if (context?.Api == null)
            {
                return;
            }
            if (context.Users == null)
            {
                return;
            }

            var usernames = context.Users.Where(user => user.UserType != UserType.Judge).Select(user => user.Username).ToList();

            if (usernames.Count <= 0)
            {
                return;
            }

            var request = new UnallocateUsersRequest()
            {
                Usernames = usernames
            };

            var response = context.Api.UnallocateUsers(request);

            response.StatusCode.Should().Be(HttpStatusCode.OK);
        }
Ejemplo n.º 4
0
        public void UnallocateUsers(TestContext context)
        {
            if (context?.TestApi == null)
            {
                return;
            }
            if (context.CurrentUser == null)
            {
                return;
            }

            var request = new UnallocateUsersRequest()
            {
                Usernames = new List <string> {
                    context.CurrentUser.Username
                }
            };

            if (context.Test?.AllocateUsername != null)
            {
                request.Usernames.Add(context.Test.AllocateUsername);
            }

            var response = context.TestApi.UnallocateUsers(request);

            response.StatusCode.Should().Be(HttpStatusCode.OK);
        }
Ejemplo n.º 5
0
        public async Task Should_unallocate_users()
        {
            const UserType FIRST_USER_TYPE  = UserType.Judge;
            const UserType SECOND_USER_TYPE = UserType.Individual;
            const UserType THIRD_USER_TYPE  = UserType.Representative;

            var firstUser         = CreateUser(FIRST_USER_TYPE);
            var firstAllocation   = CreateAllocation(firstUser);
            var firstUnallocation = Unallocate(firstAllocation);

            var secondUser         = CreateUser(SECOND_USER_TYPE);
            var secondAllocation   = CreateAllocation(secondUser);
            var secondUnallocation = Unallocate(secondAllocation);

            var thirdUser         = CreateUser(THIRD_USER_TYPE);
            var thirdAllocation   = CreateAllocation(thirdUser);
            var thirdUnallocation = Unallocate(thirdAllocation);

            var request = new UnallocateUsersRequest
            {
                Usernames = new List <string> {
                    firstUser.Username, secondUser.Username, thirdUser.Username
                }
            };

            QueryHandler
            .SetupSequence(x => x.Handle <GetUserByUsernameQuery, UserDto>(It.IsAny <GetUserByUsernameQuery>()))
            .ReturnsAsync(firstUser)
            .ReturnsAsync(secondUser)
            .ReturnsAsync(thirdUser);

            QueryHandler
            .SetupSequence(x =>
                           x.Handle <GetAllocationByUsernameQuery, Allocation>(It.IsAny <GetAllocationByUsernameQuery>()))
            .ReturnsAsync(firstAllocation)
            .ReturnsAsync(firstUnallocation)
            .ReturnsAsync(secondAllocation)
            .ReturnsAsync(secondUnallocation)
            .ReturnsAsync(thirdAllocation)
            .ReturnsAsync(thirdUnallocation);

            var response = await Controller.UnallocateUsersByUsername(request);

            response.Should().NotBeNull();

            var result = (OkObjectResult)response;

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

            var allocationDetailsResponses = (List <AllocationDetailsResponse>)result.Value;

            allocationDetailsResponses.Count.Should().Be(3);
            allocationDetailsResponses[0].Should().BeEquivalentTo(firstAllocation, options => options.Excluding(x => x.User));
            allocationDetailsResponses[1].Should().BeEquivalentTo(secondAllocation, options => options.Excluding(x => x.User));
            allocationDetailsResponses[2].Should().BeEquivalentTo(thirdAllocation, options => options.Excluding(x => x.User));
        }
Ejemplo n.º 6
0
 public UnallocateUsersBuilder()
 {
     _request = new UnallocateUsersRequest()
     {
         Usernames = new List <string>()
         {
             $"{UserData.JUDGE}{UserData.USERNAME_STEM}"
         }
     };
 }
        public async Task Should_pass_validation()
        {
            var request = new UnallocateUsersRequest
            {
                Usernames = new List <string> {
                    USERNAME
                }
            };

            var result = await _validator.ValidateAsync(request);

            result.IsValid.Should().BeTrue();
        }
        public async Task Should_return_empty_usernames_error()
        {
            var request = new UnallocateUsersRequest
            {
                Usernames = new List <string>()
            };

            var result = await _validator.ValidateAsync(request);

            result.IsValid.Should().BeFalse();
            result.Errors.Count.Should().Be(1);
            result.Errors.First().ErrorMessage.Should()
            .Be(UnallocateUsersRequestValidator.EMPTY_USERNAMES_ERROR_MESSAGE);
        }
        public async Task <IActionResult> UnallocateUsersByUsername(UnallocateUsersRequest request)
        {
            _logger.LogDebug("UnallocateUsersByUsername");

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

                _logger.LogInformation("Unallocated {count} user(s)", response.Count);
                return(Ok(response));
            }
            catch (TestApiException e)
            {
                _logger.LogError(e, "Unable to unallocate users: {usernames}", request.Usernames);
                return(StatusCode(e.StatusCode, e.Response));
            }
        }
Ejemplo n.º 10
0
        public async Task Should_return_not_found_if_user_does_not_exist()
        {
            var request = new UnallocateUsersRequest
            {
                Usernames = new List <string> {
                    "*****@*****.**"
                }
            };

            var response = await Controller.UnallocateUsersByUsername(request);

            response.Should().NotBeNull();

            var result = (NotFoundResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.NotFound);
        }
        public async Task Should_unallocate_list_of_users()
        {
            var judgeUser = await Context.Data.SeedUser();

            await Context.Data.SeedAllocation(judgeUser.Id);

            await Context.Data.AllocateUser(judgeUser.Id);

            var individualUser = await Context.Data.SeedUser(UserType.Individual);

            await Context.Data.SeedAllocation(individualUser.Id);

            await Context.Data.AllocateUser(individualUser.Id);

            var representativeUser = await Context.Data.SeedUser(UserType.Representative);

            await Context.Data.SeedAllocation(representativeUser.Id);

            await Context.Data.AllocateUser(representativeUser.Id);

            var caseAdminUser = await Context.Data.SeedUser(UserType.CaseAdmin);

            await Context.Data.SeedAllocation(caseAdminUser.Id);

            await Context.Data.AllocateUser(caseAdminUser.Id);

            var usernames = new List <string>()
            {
                judgeUser.Username, individualUser.Username, representativeUser.Username, caseAdminUser.Username
            };

            var request = new UnallocateUsersRequest()
            {
                Usernames = usernames
            };
            var uri = ApiUriFactory.AllocationEndpoints.UnallocateUsers;

            await SendPatchRequest(uri, RequestHelper.Serialise(request));

            VerifyResponse(HttpStatusCode.OK, true);
            var response = RequestHelper.Deserialise <List <AllocationDetailsResponse> >(Json);

            response.Should().NotBeNull();
            Verify.AllocationDetailsResponse(response, usernames);
        }
Ejemplo n.º 12
0
        public async Task Should_return_bad_request_if_allocation_does_not_exist()
        {
            var user = CreateUser(UserType.Judge);

            var request = new UnallocateUsersRequest
            {
                Usernames = new List <string> {
                    user.Username
                }
            };

            QueryHandler
            .Setup(x => x.Handle <GetUserByUsernameQuery, UserDto>(It.IsAny <GetUserByUsernameQuery>()))
            .ReturnsAsync(user);

            var response = await Controller.UnallocateUsersByUsername(request);

            response.Should().NotBeNull();

            var result = (BadRequestObjectResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.BadRequest);
            result.Value.Should().Be($"No allocation exists for user with username {user.Username}");
        }
        public async Task Should_create_hearing_and_allocate_users()
        {
            var userTypes = new List <UserType>()
            {
                UserType.Judge,
                UserType.VideoHearingsOfficer,
                UserType.CaseAdmin,
                UserType.Individual,
                UserType.Representative,
                UserType.Individual,
                UserType.Representative,
                UserType.Interpreter,
                UserType.Observer,
                UserType.PanelMember,
                UserType.Witness
            };

            var allocateRequest = new AllocateUsersRequestBuilder()
                                  .WithUserTypes(userTypes)
                                  .ForApplication(Application.TestApi)
                                  .Build();

            var allocateUsersUri = ApiUriFactory.AllocationEndpoints.AllocateUsers;

            await SendPatchRequest(allocateUsersUri, RequestHelper.Serialise(allocateRequest));

            VerifyResponse(HttpStatusCode.OK, true);
            var usersDetails = RequestHelper.Deserialise <List <UserDetailsResponse> >(Json);

            usersDetails.Should().NotBeNull();
            Verify.UsersDetailsResponse(usersDetails, userTypes);

            var users = UserDetailsResponseToUserMapper.Map(usersDetails);

            var hearingRequest = new HearingBuilder(users)
                                 .TypeOfTest(TestType.Automated)
                                 .Build();

            var createHearingUri = ApiUriFactory.HearingEndpoints.CreateHearing;

            await SendPostRequest(createHearingUri, RequestHelper.Serialise(hearingRequest));

            VerifyResponse(HttpStatusCode.Created, true);

            var hearing = RequestHelper.Deserialise <HearingDetailsResponse>(Json);

            hearing.Should().NotBeNull();
            HearingsToDelete.Add(hearing);

            var caseAdmin = hearingRequest.Users.First(x => x.UserType == UserType.CaseAdmin);

            var request = new UpdateBookingRequestBuilder().Build();

            var uri = ApiUriFactory.HearingEndpoints.ConfirmHearing(hearing.Id);

            await SendPatchRequest(uri, RequestHelper.Serialise(request));

            VerifyResponse(HttpStatusCode.Created, true);
            var conference = RequestHelper.Deserialise <ConferenceDetailsResponse>(Json);

            conference.Should().NotBeNull();
            Verify.ConferenceDetailsResponse(conference, hearing);

            var unallocateUsersRequest = new UnallocateUsersRequest()
            {
                Usernames = users.Select(user => user.Username).ToList()
            };

            var unallocateUri = ApiUriFactory.AllocationEndpoints.UnallocateUsers;

            await SendPatchRequest(unallocateUri, RequestHelper.Serialise(unallocateUsersRequest));

            VerifyResponse(HttpStatusCode.OK, true);
        }
 public UnallocateUsersControllerTests()
 {
     _loggerMock = new Mock <ILogger <AllocationController> >();
     _request    = new UnallocateUsersBuilder().Build();
 }