public void Should_re_throw_exception_when_booking_client_error()
        {
            var serverErrorException = new BookingsApiException("msg", 500, "resp", null, null);

            _bookingsApiClient.Setup(x => x.GetParticipantsByUsernameAsync("someuser")).ThrowsAsync(serverErrorException);

            // the exception is rethrown
            Assert.ThrowsAsync <BookingsApiException>(async() => await _participantService.GetParticipantsByUsernameAsync("someuser"));
        }
        public void Should_throw_not_found_exception_when_hearing_not_found()
        {
            var serverErrorException = new BookingsApiException("msg", 500, "resp", null, null);

            _bookingsApiClient.Setup(x => x.UpdateSuitabilityAnswersAsync(_hearingId, _participantId, new List <SuitabilityAnswersRequest>())).ThrowsAsync(serverErrorException);

            // the exception is rethrown
            Assert.ThrowsAsync <BookingsApiException>(async() => await _participantService.UpdateSuitabilityAnswers(_hearingId, _participantId, new List <SuitabilityAnswer>()));
        }
        public void Should_rethrow_general_api_exceptions()
        {
            // given
            var serverErrorException = new BookingsApiException("msg", 500, "resp", null, null);

            _apiClient.Setup(x => x.GetHearingDetailsByIdAsync(_hearingId))
            .ThrowsAsync(serverErrorException);

            // the exception is rethrown
            Assert.ThrowsAsync <BookingsApiException>(() => _hearingService.GetHearingFor("username", _hearingId));
        }
        public void Should_throw_not_found_for_missing_hearings()
        {
            // given
            var notFoundException = new BookingsApiException("msg", 404, "resp", null, null);

            _apiClient.Setup(x => x.GetHearingDetailsByIdAsync(_hearingId))
            .ThrowsAsync(notFoundException);

            // another not found exception is raised
            Assert.ThrowsAsync <NotFoundException>(() => _hearingService.GetHearingFor("username", _hearingId));
        }
        public async Task Should_throw_not_found_exception_when_participant_not_found()
        {
            var          serverErrorException = new BookingsApiException("msg", 404, "resp", null, null);
            const string username             = "******";

            _bookingsApiClient.Setup(x => x.GetParticipantsByUsernameAsync(username)).ThrowsAsync(serverErrorException);

            var result = await _participantService.GetParticipantsByUsernameAsync(username);

            Assert.AreEqual(Enumerable.Empty <Participant>(), result);
        }
        public async Task Should_return_booking_api_exception_when_booking_api_not_found()
        {
            var exception = new BookingsApiException("Bookings api error", 404, "response", null, new Exception());

            _bookingsApiClientMock
            .Setup(x => x.GetCaseTypesAsync())
            .ThrowsAsync(exception);

            var response = await GetResponseFromHealthCheck();

            response.BookingsApiHealth.Successful.Should().BeTrue();
            response.BookingsApiHealth.ErrorMessage.Should().BeNullOrWhiteSpace();
        }