コード例 #1
0
        private async void ErrorOnDuplicateRequestId()
        {
            const string linkReferenceNumber   = "linkreference";
            const string programRefNo          = "129";
            var          expectedErrorResponse =
                new ErrorRepresentation(new Error(ErrorCode.DuplicateRequestId, ErrorMessage.DuplicateRequestId));
            var patientReferenceRequest = getPatientReferenceRequest(programRefNo);

            guidGenerator.Setup(x => x.NewGuid()).Returns(linkReferenceNumber);
            patientVerification.Setup(x => x.SendTokenFor(new Session(linkReferenceNumber
                                                                      , new Communication(CommunicationMode.MOBILE, testPatient.PhoneNumber),
                                                                      new OtpGenerationDetail(TestBuilder.Faker().Random.Word(), OtpAction.LINK_PATIENT_CARECONTEXT.ToString()))))
            .ReturnsAsync((OtpMessage)null);
            linkRepository.Setup(x => x.SaveRequestWith(linkReferenceNumber,
                                                        patientReferenceRequest.Patient.ConsentManagerId,
                                                        patientReferenceRequest.Patient.ConsentManagerUserId,
                                                        patientReferenceRequest.Patient.ReferenceNumber, new[] { programRefNo }))
            .ReturnsAsync(new Tuple <LinkEnquires, Exception>(null, null));
            linkRepository.Setup(x => x.Save(patientReferenceRequest.RequestId,
                                             patientReferenceRequest.TransactionId,
                                             linkReferenceNumber))
            .ReturnsAsync(Option.None <InitiatedLinkRequest>());
            patientRepository.Setup(x => x.PatientWithAsync(testPatient.Identifier))
            .ReturnsAsync(Option.Some(testPatient));
            var(_, errorRepresentation) = await linkPatient.LinkPatients(patientReferenceRequest);

            patientVerification.Verify();
            linkRepository.Verify();
            guidGenerator.Verify();

            errorRepresentation.Should().BeEquivalentTo(expectedErrorResponse);
        }
コード例 #2
0
        private async void ReturnNoPatientFoundErrorWhenVerifiedIdentifierIs(IEnumerable <Identifier> identifiers)
        {
            var patientDiscovery = new PatientDiscovery(
                matchingRepository.Object,
                discoveryRequestRepository.Object,
                linkPatientRepository.Object,
                patientRepository.Object,
                logger.Object);
            var consentManagerUserId = Faker().Random.String();
            var expectedError        = new ErrorRepresentation(new Error(ErrorCode.NoPatientFound, "No patient found"));
            var patientRequest       = new PatientEnquiry(consentManagerUserId,
                                                          identifiers,
                                                          new List <Identifier>(),
                                                          null,
                                                          HipLibrary.Patient.Model.Gender.M,
                                                          2019);
            var discoveryRequest = new DiscoveryRequest(patientRequest, Faker().Random.String(), RandomString(),
                                                        DateTime.Now);

            linkPatientRepository.Setup(e => e.GetLinkedCareContexts(consentManagerUserId))
            .ReturnsAsync(new Tuple <IEnumerable <LinkedAccounts>, Exception>(new List <LinkedAccounts>(), null));

            var(discoveryResponse, error) = await patientDiscovery.PatientFor(discoveryRequest);

            discoveryResponse.Should().BeNull();
            error.Should().BeEquivalentTo(expectedError);
        }
コード例 #3
0
        public ErrorRepresentation Index(int statusCode)
        {
            var f   = HttpContext.Features.Get <IStatusCodeReExecuteFeature>();
            var uri = UriHelper.BuildAbsolute(Request.Scheme, Request.Host, f.OriginalPathBase, f.OriginalPath);

            return(ErrorRepresentation.MakeSparse(uri));
        }
コード例 #4
0
        private void ButTheDataSourceIsNotReachable(out ErrorRepresentation errorRepresentation)
        {
            patientDiscoveryMock
            .Setup(patientDiscovery => patientDiscovery.PatientFor(It.IsAny <DiscoveryRequest>()))
            .Returns(async() => throw new Exception("Exception coming from tests"));

            errorRepresentation = new ErrorRepresentation(new Error(ErrorCode.ServerInternalError, "Unreachable external service"));
        }
コード例 #5
0
        private void ShouldReturnNoPatientFoundError()
        {
            var(patient, error) =
                DiscoveryUseCase.DiscoverPatient(new List <PatientEnquiryRepresentation>().AsQueryable());
            var expectedError = new ErrorRepresentation(new Error(ErrorCode.NoPatientFound, "No patient found"));

            patient.Should().BeNull();
            error.Should().BeEquivalentTo(expectedError);
        }
コード例 #6
0
        private async void ShouldReturnPatientNotFoundError()
        {
            var patientReferenceRequest = getPatientReferenceRequest("129");
            var expectedError           = new ErrorRepresentation(new Error(ErrorCode.NoPatientFound, ErrorMessage.NoPatientFound));

            var(_, error) = await linkPatient.LinkPatients(patientReferenceRequest);

            error.Should().BeEquivalentTo(expectedError);
        }
コード例 #7
0
        private void AndTheUserDoesNotMatchAnyPatientBecauseOf(ErrorCode errorCode, out ErrorRepresentation errorRepresentation)
        {
            var error = new ErrorRepresentation(new Error(ErrorCode.NoPatientFound, "unusedMessage"));

            patientDiscoveryMock
            .Setup(patientDiscovery => patientDiscovery.PatientFor(It.IsAny <DiscoveryRequest>()))
            .Returns(async() => (null, error));

            errorRepresentation = new ErrorRepresentation(new Error(ErrorCode.NoPatientFound, "unusedMessage"));
        }
コード例 #8
0
        public async Task <Tuple <HealthInformationTransactionResponse, ErrorRepresentation> > HealthInformationRequestFor(
            HealthInformationRequest request,
            string gatewayId,
            string correlationId)
        {
            var consent = await consentRepository.GetFor(request.Consent.Id);

            if (consent == null)
            {
                return(ConsentArtefactNotFound());
            }

            var dataRequest = new DataRequest(consent.ConsentArtefact.CareContexts,
                                              request.DateRange,
                                              request.DataPushUrl,
                                              consent.ConsentArtefact.HiTypes,
                                              request.TransactionId,
                                              request.KeyMaterial,
                                              gatewayId,
                                              consent.ConsentArtefactId,
                                              consent.ConsentArtefact.ConsentManager.Id,
                                              correlationId);
            var result = await dataFlowRepository.SaveRequest(request.TransactionId, request).ConfigureAwait(false);

            var(response, errorRepresentation) = result.Map(r =>
            {
                var errorResponse = new ErrorRepresentation(new Error(ErrorCode.ServerInternalError,
                                                                      ErrorMessage.InternalServerError));
                return(new Tuple <HealthInformationTransactionResponse, ErrorRepresentation>(null, errorResponse));
            }).ValueOr(new Tuple <HealthInformationTransactionResponse,
                                  ErrorRepresentation>(new HealthInformationTransactionResponse(request.TransactionId), null));

            if (errorRepresentation != null)
            {
                logger.Log(LogLevel.Error,
                           LogEvents.DataFlow,
                           "Failed to save data request: {@ErrorRepresentation}",
                           errorRepresentation);
                return(new Tuple <HealthInformationTransactionResponse, ErrorRepresentation>(null, errorRepresentation));
            }

            if (IsExpired(request.KeyMaterial.DhPublicKey.Expiry))
            {
                var errorResponse = new ErrorRepresentation(new Error(ErrorCode.ExpiredKeyPair,
                                                                      ErrorMessage.ExpiredKeyPair));
                logger.Log(LogLevel.Error,
                           LogEvents.DataFlow,
                           "Encryption key expired: {@ErrorRepresentation}",
                           errorResponse);
                return(new Tuple <HealthInformationTransactionResponse, ErrorRepresentation>(null, errorResponse));
            }

            PublishDataRequest(dataRequest);
            return(new Tuple <HealthInformationTransactionResponse, ErrorRepresentation>(response, null));
        }
コード例 #9
0
        private async void ShouldGetHealthInformationNotFound()
        {
            var linkId = TestBuilder.Faker().Random.Hash();

            var(_, errorRepresentation) = await dataFlowService.HealthInformationFor(linkId, "token");

            var expectedError = new ErrorRepresentation(
                new Error(ErrorCode.HealthInformationNotFound, ErrorMessage.HealthInformationNotFound));

            errorRepresentation.Should().BeEquivalentTo(expectedError);
        }
コード例 #10
0
        private async void ShouldGetMultiplePatientsFoundErrorWhenSameUnverifiedIdentifiersAlsoMatch()
        {
            var patientDiscovery = new PatientDiscovery(
                matchingRepository.Object,
                discoveryRequestRepository.Object,
                linkPatientRepository.Object,
                patientRepository.Object,
                logger.Object);
            var expectedError =
                new ErrorRepresentation(new Error(ErrorCode.MultiplePatientsFound, "Multiple patients found"));
            var          patientReferenceNumber = Faker().Random.String();
            var          consentManagerUserId   = Faker().Random.String();
            const ushort yearOfBirth            = 2019;
            var          gender = Faker().PickRandom <HipLibrary.Patient.Model.Gender>();
            var          name   = Faker().Name.FullName();
            var          verifiedIdentifiers   = new[] { new Identifier(IdentifierType.MOBILE, Faker().Phone.PhoneNumber()) };
            var          unverifiedIdentifiers = new[] { new Identifier(IdentifierType.MR, patientReferenceNumber) };
            var          patientRequest        = new PatientEnquiry(consentManagerUserId,
                                                                    verifiedIdentifiers,
                                                                    unverifiedIdentifiers,
                                                                    name,
                                                                    gender,
                                                                    yearOfBirth);
            var discoveryRequest = new DiscoveryRequest(patientRequest, Faker().Random.String(), RandomString(),
                                                        DateTime.Now);

            linkPatientRepository.Setup(e => e.GetLinkedCareContexts(consentManagerUserId))
            .ReturnsAsync(new Tuple <IEnumerable <LinkedAccounts>, Exception>(new List <LinkedAccounts>(), null));

            matchingRepository
            .Setup(repo => repo.Where(discoveryRequest))
            .Returns(Task.FromResult(new List <HipLibrary.Patient.Model.Patient>
            {
                new HipLibrary.Patient.Model.Patient
                {
                    Identifier  = patientReferenceNumber,
                    YearOfBirth = yearOfBirth,
                    Gender      = gender,
                    Name        = name
                },
                new HipLibrary.Patient.Model.Patient
                {
                    Identifier  = patientReferenceNumber,
                    YearOfBirth = yearOfBirth,
                    Gender      = gender,
                    Name        = name
                }
            }.AsQueryable()));

            var(discoveryResponse, error) = await patientDiscovery.PatientFor(discoveryRequest);

            discoveryResponse.Should().BeNull();
            error.Should().BeEquivalentTo(expectedError);
        }
コード例 #11
0
 private ActionResult ServerResponseFor(ErrorRepresentation errorResponse)
 {
     return(errorResponse.Error.Code switch
     {
         ErrorCode.ServerInternalError => StatusCode(StatusCodes.Status500InternalServerError, errorResponse),
         ErrorCode.ContextArtefactIdNotFound => StatusCode(StatusCodes.Status404NotFound, errorResponse),
         ErrorCode.InvalidToken => StatusCode(StatusCodes.Status403Forbidden, errorResponse),
         ErrorCode.HealthInformationNotFound => StatusCode(StatusCodes.Status404NotFound, errorResponse),
         ErrorCode.LinkExpired => StatusCode(StatusCodes.Status403Forbidden, errorResponse),
         ErrorCode.ExpiredKeyPair => StatusCode(StatusCodes.Status400BadRequest, errorResponse),
         _ => Problem(errorResponse.Error.Message)
     });
コード例 #12
0
        public async Task LinkPatient(LinkReferenceRequest request)
        {
            var cmUserId = request.Patient.Id;
            var cmSuffix = cmUserId.Substring(
                cmUserId.LastIndexOf("@", StringComparison.Ordinal) + 1);
            var patient = new LinkEnquiry(
                cmSuffix,
                cmUserId,
                request.Patient.ReferenceNumber,
                request.Patient.CareContexts);

            try
            {
                var doesRequestExists = await discoveryRequestRepository.RequestExistsFor(
                    request.TransactionId,
                    request.Patient?.Id,
                    request.Patient?.ReferenceNumber);

                ErrorRepresentation errorRepresentation = null;
                if (!doesRequestExists)
                {
                    errorRepresentation = new ErrorRepresentation(
                        new Error(ErrorCode.DiscoveryRequestNotFound, ErrorMessage.DiscoveryRequestNotFound));
                }

                var patientReferenceRequest =
                    new PatientLinkEnquiry(request.TransactionId, request.RequestId, patient);
                var patientLinkEnquiryRepresentation = new PatientLinkEnquiryRepresentation();

                var(linkReferenceResponse, error) = errorRepresentation != null
                    ? (patientLinkEnquiryRepresentation, errorRepresentation)
                    : await linkPatient.LinkPatients(patientReferenceRequest);

                var linkedPatientRepresentation = new LinkEnquiryRepresentation();
                if (linkReferenceResponse != null)
                {
                    linkedPatientRepresentation = linkReferenceResponse.Link;
                }
                var response = new GatewayLinkResponse(
                    linkedPatientRepresentation,
                    error?.Error,
                    new Resp(request.RequestId),
                    request.TransactionId,
                    DateTime.Now.ToUniversalTime(),
                    Guid.NewGuid());

                await gatewayClient.SendDataToGateway(PATH_ON_LINK_INIT, response, cmSuffix);
            }
            catch (Exception exception)
            {
                Log.Error(exception, exception.StackTrace);
            }
        }
コード例 #13
0
        private async void ReturnNoPatientFoundErrorWhenVerifiedIdentifierIs(IEnumerable <Identifier> identifiers)
        {
            var expectedError    = new ErrorRepresentation(new Error(ErrorCode.NoPatientFound, "No patient found"));
            var discoveryRequest = discoveryRequestBuilder.Build();

            SetupLinkRepositoryWithLinkedPatient();
            SetupMatchingRepositoryForDiscoveryRequest(discoveryRequest, numberOfPatients: 0);

            var(discoveryResponse, error) = await patientDiscovery.PatientFor(discoveryRequest);

            discoveryResponse.Should().BeNull();
            error.Should().BeEquivalentTo(expectedError);
        }
コード例 #14
0
        private async void ShouldGetNoPatientFoundErrorWhenNoPatientMatchedInOpenMrs()
        {
            var expectedError    = new ErrorRepresentation(new Error(ErrorCode.NoPatientFound, "No patient found"));
            var discoveryRequest = discoveryRequestBuilder.Build();

            SetupLinkRepositoryWithLinkedPatient();
            SetupMatchingRepositoryForDiscoveryRequest(discoveryRequest, numberOfPatients: 0);

            var(discoveryResponse, error) = await patientDiscovery.PatientFor(discoveryRequest);

            discoveryResponse.Should().BeNull();
            error.Should().BeEquivalentTo(expectedError);
        }
コード例 #15
0
        private async void ShouldGetMultiplePatientsFoundErrorWhenSameUnverifiedIdentifiersAlsoMatch()
        {
            var expectedError =
                new ErrorRepresentation(new Error(ErrorCode.MultiplePatientsFound, "Multiple patients found"));
            var discoveryRequest = discoveryRequestBuilder.Build();

            SetupLinkRepositoryWithLinkedPatient();
            SetupMatchingRepositoryForDiscoveryRequest(discoveryRequest, numberOfPatients: 2);

            var(discoveryResponse, error) = await patientDiscovery.PatientFor(discoveryRequest);

            discoveryResponse.Should().BeNull();
            error.Should().BeEquivalentTo(expectedError);
        }
コード例 #16
0
        private async void ShouldReturnPatientNotFoundError()
        {
            IEnumerable <CareContextEnquiry> careContexts = new[] { new CareContextEnquiry("129") };
            var patient = new LinkEnquiry(TestBuilders.Faker().Random.Hash(),
                                          TestBuilders.Faker().Random.Hash(), "1234", careContexts);
            var patientReferenceRequest = new PatientLinkEnquiry(TestBuilders.Faker().Random.Hash(),
                                                                 TestBuilders.Faker().Random.Hash(), patient);
            var expectedError =
                new ErrorRepresentation(new Error(ErrorCode.NoPatientFound, ErrorMessage.NoPatientFound));

            var(_, error) = await linkPatient.LinkPatients(patientReferenceRequest);

            error.Should().BeEquivalentTo(expectedError);
        }
コード例 #17
0
        private async void ShouldReturnCareContextNotFoundError()
        {
            var patientReferenceRequest = getPatientReferenceRequest("1234");

            patientRepository.Setup(e => e.PatientWithAsync(testPatient.Identifier))
            .ReturnsAsync(Option.Some(testPatient));
            var expectedError = new ErrorRepresentation(
                new Error(ErrorCode.CareContextNotFound, ErrorMessage.CareContextNotFound));

            var(_, error) = await linkPatient.LinkPatients(patientReferenceRequest);

            patientRepository.Verify();
            discoveryRequestRepository.Invocations.Count.Should().Be(0);
            error.Should().BeEquivalentTo(expectedError);
        }
コード例 #18
0
        private async void ShouldReturnAnErrorWhenDiscoveryRequestAlreadyExists()
        {
            var expectedError =
                new ErrorRepresentation(new Error(ErrorCode.DuplicateDiscoveryRequest,
                                                  "Discovery Request already exists"));
            var transactionId    = RandomString();
            var discoveryRequest = new DiscoveryRequest(null, RandomString(), transactionId, DateTime.Now);

            discoveryRequestRepository.Setup(repository => repository.RequestExistsFor(transactionId))
            .ReturnsAsync(true);

            var(discoveryResponse, error) = await patientDiscovery.PatientFor(discoveryRequest);

            discoveryResponse.Should().BeNull();
            error.Should().BeEquivalentTo(expectedError);
        }
コード例 #19
0
        private async void ShouldGetHealthInformationNotFound()
        {
            var linkId        = TestBuilder.Faker().Random.Hash();
            var transactionId = TestBuilder.Faker().Random.Hash();
            var expectedError = new ErrorRepresentation(
                new Error(ErrorCode.HealthInformationNotFound, ErrorMessage.HealthInformationNotFound));
            var token = TestBuilder.Faker().Random.String();

            dataFlow.Setup(x => x.HealthInformationFor(linkId, token))
            .ReturnsAsync(new Tuple <HealthInformationResponse, ErrorRepresentation>(null, expectedError));

            var healthInformation = await dataFlowController
                                    .HealthInformation(linkId, token) as ObjectResult;

            healthInformation.StatusCode.Should().Be(StatusCodes.Status404NotFound);
            healthInformation.Value.Should().BeEquivalentTo(expectedError);
        }
コード例 #20
0
        private async void ShouldGetLinkExpiredOnGetHealthInformation()
        {
            var linkId            = TestBuilder.Faker().Random.Hash();
            var token             = TestBuilder.Faker().Random.Hash();
            var healthInformation = TestBuilder.HealthInformation(token, TestBuilder.Faker().Date.Past());

            healthInformationRepository.Setup(x => x.GetAsync(linkId))
            .ReturnsAsync(Option.Some(healthInformation));

            var(_, errorRepresentation) =
                await dataFlowService.HealthInformationFor(linkId, token);

            var expectedError = new ErrorRepresentation(
                new Error(ErrorCode.LinkExpired, ErrorMessage.LinkExpired));

            errorRepresentation.Should().BeEquivalentTo(expectedError);
        }
コード例 #21
0
        private async void ShouldReturnErrorIfFailedToFetchCareContexts()
        {
            var expectedError =
                new ErrorRepresentation(new Error(ErrorCode.CareContextConfiguration, "HIP configuration error. If you encounter this issue repeatedly, please report it"));
            var discoveryRequest = discoveryRequestBuilder.WithUnverifiedIdentifiers(null).Build();

            SetupLinkRepositoryWithLinkedPatient();
            SetupMatchingRepositoryForDiscoveryRequest(discoveryRequest);

            careContextRepository
            .Setup(e => e.GetCareContexts(openMrsPatientReferenceNumber))
            .Throws <OpenMrsFormatException>();

            var(discoveryResponse, error) = await patientDiscovery.PatientFor(discoveryRequest);

            discoveryResponse.Should().BeNull();
            error.Should().BeEquivalentTo(expectedError);
        }
コード例 #22
0
        private async void ShouldReturnErrorIfFailedToConnectToOpenMrsServer()
        {
            var expectedError =
                new ErrorRepresentation(new Error(ErrorCode.OpenMrsConnection, "HIP connection error"));
            var discoveryRequest = discoveryRequestBuilder.WithUnverifiedIdentifiers(null).Build();

            SetupLinkRepositoryWithLinkedPatient();
            SetupMatchingRepositoryForDiscoveryRequest(discoveryRequest);

            matchingRepository
            .Setup(e => e.Where(discoveryRequest))
            .Throws <OpenMrsConnectionException>();

            var(discoveryResponse, error) = await patientDiscovery.PatientFor(discoveryRequest);

            discoveryResponse.Should().BeNull();
            error.Should().BeEquivalentTo(expectedError);
        }
コード例 #23
0
        private async void ErrorOnInvalidLinkReferenceNumber()
        {
            var sessionId             = TestBuilders.Faker().Random.Hash();
            var otpToken              = TestBuilders.Faker().Random.Number().ToString();
            var patientLinkRequest    = new LinkConfirmationRequest(otpToken, sessionId);
            var expectedErrorResponse =
                new ErrorRepresentation(new Error(ErrorCode.NoLinkRequestFound, "No request found"));

            patientVerification.Setup(e => e.Verify(sessionId, otpToken))
            .ReturnsAsync((OtpMessage)null);
            linkRepository.Setup(e => e.GetPatientFor(sessionId))
            .ReturnsAsync(new Tuple <LinkEnquires, Exception>(null, new Exception()));


            var(_, cmId, error) = await linkPatient.VerifyAndLinkCareContext(patientLinkRequest);

            patientVerification.Verify();
            error.Should().BeEquivalentTo(expectedErrorResponse);
        }
コード例 #24
0
        private void MapToRepresentation(Exception e, HttpRequestMessage req)
        {
            if (e is WithContextNOSException)
            {
                ArgumentsRepresentation.Format format = e is BadPersistArgumentsException ? ArgumentsRepresentation.Format.Full : ArgumentsRepresentation.Format.MembersOnly;
                RestControlFlags flags = e is BadPersistArgumentsException ? ((BadPersistArgumentsException)e).Flags : RestControlFlags.DefaultFlags();

                var contextNosException = e as WithContextNOSException;

                if (contextNosException.Contexts.Any(c => c.ErrorCause == Cause.Disabled || c.ErrorCause == Cause.Immutable))
                {
                    representation = NullRepresentation.Create();
                }
                else if (e is BadPersistArgumentsException && contextNosException.ContextFacade != null && contextNosException.Contexts.Any())
                {
                    representation = ArgumentsRepresentation.Create(oidStrategy, req, contextNosException.ContextFacade, contextNosException.Contexts, format, flags, UriMtHelper.GetJsonMediaType(RepresentationTypes.BadArguments));
                }
                else if (contextNosException.ContextFacade != null)
                {
                    representation = ArgumentsRepresentation.Create(oidStrategy, req, contextNosException.ContextFacade, format, flags, UriMtHelper.GetJsonMediaType(RepresentationTypes.BadArguments));
                }
                else if (contextNosException.Contexts.Any())
                {
                    representation = ArgumentsRepresentation.Create(oidStrategy, req, contextNosException.Contexts, format, flags, UriMtHelper.GetJsonMediaType(RepresentationTypes.BadArguments));
                }
                else
                {
                    representation = NullRepresentation.Create();
                }
            }
            else if (e is ResourceNotFoundNOSException ||
                     e is NotAllowedNOSException ||
                     e is PreconditionFailedNOSException ||
                     e is PreconditionHeaderMissingNOSException ||
                     e is NoContentNOSException)
            {
                representation = NullRepresentation.Create();
            }
            else
            {
                representation = ErrorRepresentation.Create(oidStrategy, e);
            }
        }
コード例 #25
0
        private async void CheckInternalServerErrorOnSaveDataFailure()
        {
            var consentMangerId = TestBuilder.Faker().Random.String();
            var request         = TestBuilder.HealthInformationRequest(TestBuilder.Faker().Random.Hash());
            var expectedError   = new ErrorRepresentation(new Error(ErrorCode.ServerInternalError,
                                                                    ErrorMessage.InternalServerError));

            dataFlow.Setup(d => d.HealthInformationRequestFor(request, consentMangerId))
            .ReturnsAsync(
                new Tuple <HealthInformationTransactionResponse, ErrorRepresentation>(null, expectedError));

            var response =
                await dataFlowController.HealthInformationRequestFor(request, consentMangerId) as ObjectResult;

            dataFlow.Verify();
            response.StatusCode
            .Should()
            .Be(StatusCodes.Status500InternalServerError);
        }
コード例 #26
0
        private async void ShouldReturnCareContextNotFoundError()
        {
            IEnumerable <CareContextEnquiry> careContexts = new[] { new CareContextEnquiry("1234") };
            var patient = new LinkEnquiry(TestBuilders.Faker().Random.Hash(),
                                          TestBuilders.Faker().Random.Hash(), "4", careContexts);
            var patientReferenceRequest = new PatientLinkEnquiry(TestBuilders.Faker().Random.Hash(),
                                                                 TestBuilders.Faker().Random.Hash(), patient);

            patientRepository.Setup(e => e.PatientWith(testPatient.Identifier))
            .Returns(Option.Some(testPatient));
            var expectedError = new ErrorRepresentation(
                new Error(ErrorCode.CareContextNotFound, ErrorMessage.CareContextNotFound));

            var(_, error) = await linkPatient.LinkPatients(patientReferenceRequest);

            patientRepository.Verify();
            discoveryRequestRepository.Invocations.Count.Should().Be(0);
            error.Should().BeEquivalentTo(expectedError);
        }
コード例 #27
0
        private async void ReturnErrorOnFailure()
        {
            var consentMangerId = TestBuilder.Faker().Random.String();

            var transactionId = TestBuilder.Faker().Random.Hash();
            var request       = TestBuilder.HealthInformationRequest(transactionId);

            dataFlowRepository.Setup(d => d.SaveRequest(transactionId, request))
            .ReturnsAsync(Option.Some(new Exception()));
            var expectedError = new ErrorRepresentation(new Error(ErrorCode.ServerInternalError,
                                                                  ErrorMessage.InternalServerError));

            consentRepository.Setup(d => d.GetFor(request.Consent.Id))
            .ReturnsAsync(TestBuilder.DataFlowConsent());

            var(_, errorResponse) = await dataFlowService.HealthInformationRequestFor(request, consentMangerId);

            dataFlowRepository.Verify();
            errorResponse.Should().BeEquivalentTo(expectedError);
        }
コード例 #28
0
        private void ShouldReturnMultiplePatientsFoundError()
        {
            var patient1 = new PatientEnquiryRepresentation("123", "Jack", new List <CareContextRepresentation>(), new List <string>
            {
                Match.Name.ToString()
            });
            var patient2 = new PatientEnquiryRepresentation("123", "Jack", new List <CareContextRepresentation>(), new List <string>
            {
                Match.Name.ToString()
            });

            var(patient, error) =
                DiscoveryUseCase.DiscoverPatient(new List <PatientEnquiryRepresentation> {
                patient1, patient2
            }.AsQueryable());
            var expectedError = new ErrorRepresentation(new Error(ErrorCode.MultiplePatientsFound, "Multiple patients found"));

            patient.Should().BeNull();
            error.Should().BeEquivalentTo(expectedError);
        }
コード例 #29
0
        private async void ReturnOtpExpired()
        {
            var sessionId          = TestBuilders.Faker().Random.Hash();
            var otpToken           = TestBuilders.Faker().Random.Number().ToString();
            var dateTimeStamp      = DateTime.Now.ToUniversalTime().ToString(Constants.DateTimeFormat);
            var testOtpMessage     = new OtpMessage(ResponseType.OtpExpired, "Otp Expired");
            var patientLinkRequest = new LinkConfirmationRequest(otpToken, sessionId);
            var linkEnquires       = new LinkEnquires("", "", "ncg", "",
                                                      dateTimeStamp, new List <CareContext>());
            var expectedErrorResponse =
                new ErrorRepresentation(new Error(ErrorCode.OtpExpired, testOtpMessage.Message));

            linkRepository.Setup(e => e.GetPatientFor(sessionId))
            .ReturnsAsync(new Tuple <LinkEnquires, Exception>(linkEnquires, null));
            patientVerification.Setup(e => e.Verify(sessionId, otpToken))
            .ReturnsAsync(testOtpMessage);

            var(_, cmId, error) = await linkPatient.VerifyAndLinkCareContext(patientLinkRequest);

            patientVerification.Verify();
            error.Should().BeEquivalentTo(expectedErrorResponse);
        }
コード例 #30
0
 private static void AndTheResponseShouldContainTheErrorDetails(GatewayDiscoveryRepresentation actualResponse,
                                                                ErrorRepresentation errorRepresentation)
 {
     actualResponse.Error.Code.Should().Be(errorRepresentation.Error.Code);
     actualResponse.Error.Message.Should().Be(errorRepresentation.Error.Message);
 }