예제 #1
0
        public async Task Should_create_hearing_with_all_user_types()
        {
            var judge       = CreateUser(UserType.Judge);
            var observer    = CreateUser(UserType.Observer);
            var panelMember = CreateUser(UserType.PanelMember);
            var caseAdmin   = CreateUser(UserType.CaseAdmin);
            var vho         = CreateUser(UserType.VideoHearingsOfficer);
            var individual  = CreateUser(UserType.Individual);

            var users = new List <UserDto> {
                judge, observer, panelMember, caseAdmin, vho, individual
            };

            var createHearingRequest   = new HearingBuilder(users).Build();
            var bookHearingRequest     = new BookHearingRequestBuilder(createHearingRequest).Build();
            var hearingDetailsResponse = new HearingDetailsResponseBuilder(bookHearingRequest).Build();

            BookingsApiClient
            .Setup(x => x.BookNewHearingAsync(It.IsAny <BookNewHearingRequest>()))
            .ReturnsAsync(hearingDetailsResponse);

            var response = await Controller.CreateHearing(createHearingRequest);

            var result = (ObjectResult)response;

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

            var hearingDetails = (HearingDetailsResponse)result.Value;

            hearingDetails.Should().NotBeNull();
        }
        public async Task Should_get_person()
        {
            var hearingDetailsResponse = CreateHearingDetailsResponse();
            var individual             = hearingDetailsResponse.Participants.First(x => x.UserRoleName.Equals("Individual"));

            var personResponse = new PersonResponse()
            {
                ContactEmail    = individual.ContactEmail,
                FirstName       = individual.FirstName,
                Id              = Guid.NewGuid(),
                LastName        = individual.LastName,
                MiddleNames     = individual.MiddleNames,
                Organisation    = individual.Organisation,
                TelephoneNumber = individual.TelephoneNumber,
                Title           = individual.Title,
                Username        = individual.Username
            };

            BookingsApiClient
            .Setup(x => x.GetPersonByUsernameAsync(It.IsAny <string>()))
            .ReturnsAsync(personResponse);

            var response = await Controller.GetPersonByUsername(individual.Username);

            response.Should().NotBeNull();

            var result = (ObjectResult)response;

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

            var answers = (PersonResponse)result.Value;

            answers.Should().NotBeNull();
            answers.Should().BeEquivalentTo(personResponse);
        }
예제 #3
0
        public async Task Should_create_hearing_without_specifying_the_case_type()
        {
            var judge      = CreateUser(UserType.Judge);
            var individual = CreateUser(UserType.Individual);

            var users = new List <UserDto> {
                judge, individual
            };

            var createHearingRequest   = new HearingBuilder(users).WithoutACaseType().Build();
            var bookHearingRequest     = new BookHearingRequestBuilder(createHearingRequest).Build();
            var hearingDetailsResponse = new HearingDetailsResponseBuilder(bookHearingRequest).Build();

            BookingsApiClient
            .Setup(x => x.BookNewHearingAsync(It.IsAny <BookNewHearingRequest>()))
            .ReturnsAsync(hearingDetailsResponse);

            var response = await Controller.CreateHearing(createHearingRequest);

            var result = (ObjectResult)response;

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

            var hearingDetails = (HearingDetailsResponse)result.Value;

            hearingDetails.Should().NotBeNull();
            hearingDetails.Should().BeEquivalentTo(hearingDetailsResponse);
        }
        public async Task Should_confirm_hearing()
        {
            var hearingId = Guid.NewGuid();
            var conferenceDetailsResponse = CreateConferenceDetailsResponse();

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

            BookingsApiClient
            .Setup(x => x.UpdateBookingStatusAsync(It.IsAny <Guid>(), It.IsAny <UpdateBookingStatusRequest>()))
            .Returns(Task.CompletedTask);

            VideoApiService
            .Setup(x => x.GetConferenceByHearingIdPolling(It.IsAny <Guid>()))
            .ReturnsAsync(conferenceDetailsResponse);

            var response = await Controller.ConfirmHearingById(hearingId, request);

            response.Should().NotBeNull();

            var result = (ObjectResult)response;

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

            var conferenceDetails = (ConferenceDetailsResponse)result.Value;

            conferenceDetails.Should().BeEquivalentTo(conferenceDetailsResponse);
        }
예제 #5
0
        public async Task Should_create_hearings_for_other_applications()
        {
            var judge      = CreateUser(UserType.Judge);
            var individual = CreateUser(UserType.Individual);

            var users = new List <UserDto> {
                judge, individual
            };

            var createHearingRequest = new HearingBuilder(users)
                                       .TypeOfTest(TestType.Automated)
                                       .ForApplication(Application.QueueSubscriber)
                                       .Build();

            var bookHearingRequest     = new BookHearingRequestBuilder(createHearingRequest).Build();
            var hearingDetailsResponse = new HearingDetailsResponseBuilder(bookHearingRequest).Build();

            BookingsApiClient
            .Setup(x => x.BookNewHearingAsync(It.IsAny <BookNewHearingRequest>()))
            .ReturnsAsync(hearingDetailsResponse);

            var response = await Controller.CreateHearing(createHearingRequest);

            var result = (ObjectResult)response;

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

            var hearingDetails = (HearingDetailsResponse)result.Value;

            hearingDetails.Should().NotBeNull();
            hearingDetails.Should().BeEquivalentTo(hearingDetailsResponse);
        }
예제 #6
0
        public async Task Should_return_hearing()
        {
            var hearingDetailsResponse = CreateHearingDetailsResponse();
            var listOfHearingSResponse = new List <HearingDetailsResponse> {
                hearingDetailsResponse
            };

            BookingsApiClient
            .Setup(x => x.GetHearingsByUsernameAsync(It.IsAny <string>()))
            .ReturnsAsync(listOfHearingSResponse);

            var response =
                await Controller.GetHearingsByUsername(hearingDetailsResponse.Participants.First().Username);

            response.Should().NotBeNull();

            var result = (OkObjectResult)response;

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

            var hearingDetails = (List <HearingDetailsResponse>)result.Value;

            hearingDetails.Should().NotBeNull();
            hearingDetails.Should().BeEquivalentTo(listOfHearingSResponse);
        }
예제 #7
0
        public async Task Should_create_hearing_with_audio_recording()
        {
            var firstUser  = CreateUser(UserType.Judge);
            var secondUser = CreateUser(UserType.Individual);
            var thirdUser  = CreateUser(UserType.Representative);
            var fourthUser = CreateUser(UserType.CaseAdmin);

            var users = new List <UserDto> {
                firstUser, secondUser, thirdUser, fourthUser
            };

            var createHearingRequest = new HearingBuilder(users)
                                       .AudioRecordingRequired()
                                       .Build();

            var bookHearingRequest     = new BookHearingRequestBuilder(createHearingRequest).Build();
            var hearingDetailsResponse = new HearingDetailsResponseBuilder(bookHearingRequest).Build();

            BookingsApiClient
            .Setup(x => x.BookNewHearingAsync(It.IsAny <BookNewHearingRequest>()))
            .ReturnsAsync(hearingDetailsResponse);

            var response = await Controller.CreateHearing(createHearingRequest);

            var result = (ObjectResult)response;

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

            var hearingDetails = (HearingDetailsResponse)result.Value;

            hearingDetails.Should().NotBeNull();
            hearingDetails.Should().BeEquivalentTo(hearingDetailsResponse);
        }
예제 #8
0
        public async Task Should_return_not_found_for_non_existent_hearing_id_or_participant_id()
        {
            BookingsApiClient
            .Setup(x => x.UpdateSuitabilityAnswersAsync(It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <List <SuitabilityAnswersRequest> >()))
            .ThrowsAsync(CreateBookingsApiException("Hearing id and participant id not found", HttpStatusCode.NotFound));

            var response = await Controller.UpdateSuitabilityAnswers(Guid.NewGuid(), Guid.NewGuid(), new List <SuitabilityAnswersRequest>());

            response.Should().NotBeNull();

            var result = (ObjectResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.NotFound);
        }
예제 #9
0
        public async Task Should_return_bad_request_for_invalid_request()
        {
            BookingsApiClient
            .Setup(x => x.UpdateSuitabilityAnswersAsync(It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <List <SuitabilityAnswersRequest> >()))
            .ThrowsAsync(CreateBookingsApiException("Request invalid", HttpStatusCode.BadRequest));

            var response = await Controller.UpdateSuitabilityAnswers(Guid.NewGuid(), Guid.NewGuid(), new List <SuitabilityAnswersRequest>());

            response.Should().NotBeNull();

            var result = (ObjectResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.BadRequest);
        }
예제 #10
0
        public async Task Should_update_suitability_answers()
        {
            BookingsApiClient
            .Setup(x => x.UpdateSuitabilityAnswersAsync(It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <List <SuitabilityAnswersRequest> >()))
            .Returns(Task.CompletedTask);

            var response = await Controller.UpdateSuitabilityAnswers(Guid.NewGuid(), Guid.NewGuid(), new List <SuitabilityAnswersRequest>());

            response.Should().NotBeNull();

            var result = (NoContentResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.NoContent);
        }
예제 #11
0
        public async Task Should_throw_error_with_empty_username()
        {
            BookingsApiClient
            .Setup(x => x.GetHearingsByUsernameAsync(string.Empty))
            .ThrowsAsync(CreateBookingsApiException("Username cannot be empty", HttpStatusCode.BadRequest));

            var response = await Controller.GetHearingsByUsername(string.Empty);

            response.Should().NotBeNull();

            var result = (ObjectResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.BadRequest);
        }
        public async Task Should_throw_error_for_all_hearings_by_default_case_type()
        {
            BookingsApiClient
            .Setup(
                x => x.GetHearingsByTypesAsync(It.IsAny <IEnumerable <int> >(), It.IsAny <string>(), It.IsAny <int>()))
            .ThrowsAsync(CreateBookingsApiException("Failed", HttpStatusCode.InternalServerError));

            var response = await Controller.GetAllHearings();

            response.Should().NotBeNull();

            var result = (ObjectResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.InternalServerError);
        }
예제 #13
0
        public async Task Should_return_not_found_for_non_existent_hearing()
        {
            var nonExistentHearingId = Guid.NewGuid();

            BookingsApiClient
            .Setup(x => x.GetHearingDetailsByIdAsync(nonExistentHearingId))
            .ThrowsAsync(CreateBookingsApiException("Hearing not found", HttpStatusCode.NotFound));

            var response = await Controller.GetHearingById(nonExistentHearingId);

            response.Should().NotBeNull();

            var result = (ObjectResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.NotFound);
        }
        public async Task Should_return_not_found_for_a_non_existent_username()
        {
            const string USERNAME = EmailData.NON_EXISTENT_USERNAME;

            BookingsApiClient
            .Setup(x => x.GetPersonByUsernameAsync(It.IsAny <string>()))
            .ThrowsAsync(CreateBookingsApiException("Person not found", HttpStatusCode.NotFound));

            var response = await Controller.GetPersonByUsername(USERNAME);

            response.Should().NotBeNull();

            var result = (ObjectResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.NotFound);
        }
예제 #15
0
        public async Task Should_throw_api_error()
        {
            const string USERNAME = EmailData.NON_EXISTENT_USERNAME;

            BookingsApiClient
            .Setup(x => x.GetPersonSuitabilityAnswersAsync(It.IsAny <string>()))
            .ThrowsAsync(CreateBookingsApiException("Hearing error", HttpStatusCode.InternalServerError));

            var response = await Controller.GetSuitabilityAnswers(USERNAME);

            response.Should().NotBeNull();

            var result = (ObjectResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.InternalServerError);
        }
        public async Task Should_return_error_when_failing_to_delete_hearing()
        {
            var hearingId = Guid.NewGuid();

            BookingsApiClient
            .Setup(x => x.RemoveHearingAsync(It.IsAny <Guid>()))
            .ThrowsAsync(CreateBookingsApiException("Delete error", HttpStatusCode.InternalServerError));

            var response = await Controller.DeleteHearingById(hearingId);

            response.Should().NotBeNull();

            var result = (ObjectResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.InternalServerError);
        }
        public async Task Should_return_not_found_for_non_existent_hearing_id()
        {
            var hearingId = Guid.NewGuid();

            BookingsApiClient
            .Setup(x => x.RemoveHearingAsync(It.IsAny <Guid>()))
            .ThrowsAsync(CreateBookingsApiException("Hearing not found", HttpStatusCode.NotFound));

            var response = await Controller.DeleteHearingById(hearingId);

            response.Should().NotBeNull();

            var result = (ObjectResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.NotFound);
        }
        public async Task Should_throw_not_found_for_non_existent_hearing_id()
        {
            var hearingId = Guid.NewGuid();

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

            BookingsApiClient
            .Setup(x => x.GetHearingDetailsByIdAsync(It.IsAny <Guid>()))
            .Throws(CreateBookingsApiException("Hearing not found", HttpStatusCode.NotFound));

            var response = await Controller.ConfirmHearingById(hearingId, request);

            response.Should().NotBeNull();

            var result = (ObjectResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.NotFound);
        }
        public async Task Should_return_okay_if_no_hearings_found()
        {
            BookingsApiClient
            .Setup(
                x => x.GetHearingsByTypesAsync(It.IsAny <IEnumerable <int> >(), It.IsAny <string>(), It.IsAny <int>()))
            .ThrowsAsync(CreateBookingsApiException("Failed", HttpStatusCode.NotFound));

            var response = await Controller.GetAllHearings();

            response.Should().NotBeNull();

            var result = (OkObjectResult)response;

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

            var responses = (List <BookingsHearingResponse>)result.Value;

            responses.Should().BeEmpty();
        }
예제 #20
0
        public async Task Should_get_suitability_answers()
        {
            const string USERNAME = EmailData.NON_EXISTENT_USERNAME;

            var answersResponse = new List <PersonSuitabilityAnswerResponse>()
            {
                new PersonSuitabilityAnswerResponse()
                {
                    Answers = new List <SuitabilityAnswerResponse>()
                    {
                        new SuitabilityAnswerResponse()
                        {
                            Answer         = "Answer",
                            Key            = "Key",
                            ExtendedAnswer = "ExtendedAnswer"
                        }
                    },
                    HearingId = Guid.NewGuid(),
                    QuestionnaireNotRequired = false,
                    ParticipantId            = Guid.NewGuid(),
                    ScheduledAt = DateTime.UtcNow,
                    UpdatedAt   = DateTime.UtcNow
                }
            };

            BookingsApiClient
            .Setup(x => x.GetPersonSuitabilityAnswersAsync(It.IsAny <string>()))
            .ReturnsAsync(answersResponse);

            var response = await Controller.GetSuitabilityAnswers(USERNAME);

            response.Should().NotBeNull();

            var result = (ObjectResult)response;

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

            var answers = (List <PersonSuitabilityAnswerResponse>)result.Value;

            answers.Should().NotBeNull();
            answers.Should().BeEquivalentTo(answersResponse);
        }
        public async Task Should_delete_hearing_without_removing_audio_application_with_no_audio_application()
        {
            var hearingId = Guid.NewGuid();

            BookingsApiClient
            .Setup(x => x.RemoveHearingAsync(It.IsAny <Guid>()))
            .Returns(Task.CompletedTask);

            VideoApiClient
            .Setup(x => x.DeleteAudioApplicationAsync(It.IsAny <Guid>()))
            .ThrowsAsync(CreateVideoApiException("No audio application found", HttpStatusCode.NotFound));

            var response = await Controller.DeleteHearingById(hearingId);

            response.Should().NotBeNull();

            var result = (NoContentResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.NoContent);
        }
예제 #22
0
        public async Task Should_return_empty_list_for_non_existent_username()
        {
            const string USERNAME = EmailData.NON_EXISTENT_USERNAME;

            BookingsApiClient
            .Setup(x => x.GetHearingsByUsernameAsync(It.IsAny <string>()))
            .ReturnsAsync(new List <HearingDetailsResponse>());

            var response = await Controller.GetHearingsByUsername(USERNAME);

            response.Should().NotBeNull();

            var result = (OkObjectResult)response;

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

            var hearingDetails = (List <HearingDetailsResponse>)result.Value;

            hearingDetails.Count.Should().Be(0);
        }
        public async Task Should_delete_hearing()
        {
            var hearingId = Guid.NewGuid();

            BookingsApiClient
            .Setup(x => x.RemoveHearingAsync(It.IsAny <Guid>()))
            .Returns(Task.CompletedTask);

            VideoApiClient
            .Setup(x => x.DeleteAudioApplicationAsync(It.IsAny <Guid>()))
            .Returns(Task.CompletedTask);

            var response = await Controller.DeleteHearingById(hearingId);

            response.Should().NotBeNull();

            var result = (NoContentResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.NoContent);
        }
        public async Task Should_return_all_hearings_by_default_case_type()
        {
            var bookingDetailsResponse  = CreateBookingDetailsResponse();
            var bookingDetailsResponses = new List <BookingsHearingResponse> {
                bookingDetailsResponse
            };
            var bookingsByDateResponses = new List <BookingsByDateResponse>()
            {
                new BookingsByDateResponse()
                {
                    Hearings      = bookingDetailsResponses,
                    ScheduledDate = DateTime.UtcNow
                }
            };

            const int LIMIT = HearingData.GET_HEARINGS_LIMIT;

            var bookingResponse = new BookingsResponse()
            {
                Hearings = bookingsByDateResponses,
                Limit    = LIMIT
            };

            BookingsApiClient
            .Setup(
                x => x.GetHearingsByTypesAsync(It.IsAny <IEnumerable <int> >(), It.IsAny <string>(), It.IsAny <int>()))
            .ReturnsAsync(bookingResponse);

            var response = await Controller.GetAllHearings();

            response.Should().NotBeNull();

            var result = (OkObjectResult)response;

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

            var responses = (List <BookingsHearingResponse>)result.Value;

            responses.Should().NotBeEmpty();
            responses.Any(x => x.HearingName.Equals(bookingDetailsResponse.HearingName)).Should().BeTrue();
        }
예제 #25
0
        public async Task Should_return_empty_list_for_a_non_existent_username()
        {
            const string USERNAME = EmailData.NON_EXISTENT_USERNAME;

            BookingsApiClient
            .Setup(x => x.GetPersonSuitabilityAnswersAsync(It.IsAny <string>()))
            .ReturnsAsync(new List <PersonSuitabilityAnswerResponse>());

            var response = await Controller.GetSuitabilityAnswers(USERNAME);

            response.Should().NotBeNull();

            var result = (ObjectResult)response;

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

            var answers = (List <PersonSuitabilityAnswerResponse>)result.Value;

            answers.Should().NotBeNull();
            answers.Should().BeEmpty();
        }
예제 #26
0
        public async Task Should_return_hearing()
        {
            var hearingDetailsResponse = CreateHearingDetailsResponse();

            BookingsApiClient
            .Setup(x => x.GetHearingDetailsByIdAsync(hearingDetailsResponse.Id))
            .ReturnsAsync(hearingDetailsResponse);

            var response = await Controller.GetHearingById(hearingDetailsResponse.Id);

            response.Should().NotBeNull();

            var result = (OkObjectResult)response;

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

            var hearingDetails = (HearingDetailsResponse)result.Value;

            hearingDetails.Should().NotBeNull();
            hearingDetails.Should().BeEquivalentTo(hearingDetailsResponse);
        }
예제 #27
0
        public async Task Should_return_bad_request_with_invalid_request()
        {
            var firstUser  = CreateUser(UserType.Judge);
            var secondUser = CreateUser(UserType.Individual);
            var thirdUser  = CreateUser(UserType.Representative);
            var fourthUser = CreateUser(UserType.CaseAdmin);

            var users = new List <UserDto> {
                firstUser, secondUser, thirdUser, fourthUser
            };

            var createHearingRequest = new HearingBuilder(users).Build();

            BookingsApiClient
            .Setup(x => x.BookNewHearingAsync(It.IsAny <BookNewHearingRequest>()))
            .ThrowsAsync(CreateBookingsApiException("Hearing not created", HttpStatusCode.BadRequest));

            var response = await Controller.CreateHearing(createHearingRequest);

            var result = (ObjectResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.BadRequest);
        }