Ejemplo n.º 1
0
        private void ShouldReturnDataToGateway()
        {
            var handlerMock          = new Mock <HttpMessageHandler>(MockBehavior.Strict);
            var httpClient           = new HttpClient(handlerMock.Object);
            var gatewayConfiguration = new GatewayConfiguration {
                Url = "http://someUrl"
            };
            var authenticationUri            = new Uri($"{gatewayConfiguration.Url}/{PATH_SESSIONS}");
            var expectedUri                  = new Uri($"{gatewayConfiguration.Url}{PATH_ON_DISCOVER}");
            var patientEnquiryRepresentation = new PatientEnquiryRepresentation(
                "123",
                "Jack",
                new List <CareContextRepresentation>(),
                new List <string>());
            var gatewayDiscoveryRepresentation = new GatewayDiscoveryRepresentation(
                patientEnquiryRepresentation,
                Guid.NewGuid(),
                DateTime.Now,
                "transactionId",
                null,
                new Resp("requestId"));
            var gatewayClient = new GatewayClient(httpClient, gatewayConfiguration);
            var definition    = new { accessToken = "Whatever", tokenType = "Bearer" };
            var result        = JsonConvert.SerializeObject(definition);
            var correlationId = Uuid.Generate().ToString();

            handlerMock
            .Protected()
            .Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.IsAny <HttpRequestMessage>(),
                ItExpr.IsAny <CancellationToken>())
            .ReturnsInOrder(() => Task.FromResult(new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(result)
            }), () => Task.FromResult(new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK
            }));

            gatewayClient.SendDataToGateway(PATH_ON_DISCOVER, gatewayDiscoveryRepresentation, "ncg", correlationId);

            handlerMock.Protected().Verify(
                "SendAsync",
                Times.Exactly(1),
                ItExpr.Is <HttpRequestMessage>(message => message.Method == HttpMethod.Post &&
                                               message.RequestUri == expectedUri),
                ItExpr.IsAny <CancellationToken>());
            handlerMock.Protected().Verify(
                "SendAsync",
                Times.Exactly(1),
                ItExpr.Is <HttpRequestMessage>(message => message.Method == HttpMethod.Post &&
                                               message.RequestUri == authenticationUri),
                ItExpr.IsAny <CancellationToken>());
        }
 private static void AndTheSentResponseShouldContainTheFoundPatient(GatewayDiscoveryRepresentation actualResponse,
                                                                    PatientEnquiryRepresentation patientEnquiry)
 {
     actualResponse.Patient.ReferenceNumber.Should().Be(patientEnquiry.ReferenceNumber);
     actualResponse.Patient.Display.Should().Be(patientEnquiry.Display);
     actualResponse.Patient.CareContexts.Count().Should().Be(patientEnquiry.CareContexts.Count());
     foreach (CareContextRepresentation careContext in patientEnquiry.CareContexts)
     {
         actualResponse.Patient.CareContexts.Should().ContainEquivalentOf(careContext);
     }
 }
Ejemplo n.º 3
0
 public GatewayDiscoveryRepresentation(PatientEnquiryRepresentation patient,
                                       Guid requestId,
                                       DateTime timestamp,
                                       string transactionId,
                                       Error error,
                                       DiscoveryResponse resp)
 {
     Patient       = patient;
     RequestId     = requestId;
     Timestamp     = timestamp;
     TransactionId = transactionId;
     Error         = error;
     Resp          = resp;
 }
Ejemplo n.º 4
0
        private void ShouldReturnAPatient()
        {
            var patient1 = new PatientEnquiryRepresentation("123", "Jack", new List <CareContextRepresentation>(), new List <string>
            {
                Match.Name.ToString()
            });

            var(patient, error) =
                DiscoveryUseCase.DiscoverPatient(new List <PatientEnquiryRepresentation> {
                patient1
            }.AsQueryable());

            error.Should().BeNull();
            patient.Should().BeEquivalentTo(patient1);
        }
Ejemplo n.º 5
0
        private void ShouldNotPostDataIfAuthenticationWithGatewayFailed()
        {
            var handlerMock          = new Mock <HttpMessageHandler>(MockBehavior.Strict);
            var httpClient           = new HttpClient(handlerMock.Object);
            var gatewayConfiguration = new GatewayConfiguration {
                Url = "http://someUrl"
            };
            var authenticationUri            = new Uri($"{gatewayConfiguration.Url}/{PATH_SESSIONS}");
            var patientEnquiryRepresentation = new PatientEnquiryRepresentation(
                "123",
                "Jack",
                new List <CareContextRepresentation>(),
                new List <string>());
            var gatewayDiscoveryRepresentation = new GatewayDiscoveryRepresentation(
                patientEnquiryRepresentation,
                Guid.NewGuid(),
                DateTime.Now,
                "transactionId",
                null,
                new Resp("requestId"));
            var gatewayClient = new GatewayClient(httpClient, gatewayConfiguration);
            var correlationId = Uuid.Generate().ToString();

            handlerMock
            .Protected()
            .Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.IsAny <HttpRequestMessage>(),
                ItExpr.IsAny <CancellationToken>())
            .ReturnsAsync(new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.BadGateway
            })
            .Verifiable();

            gatewayClient.SendDataToGateway(PATH_ON_DISCOVER, gatewayDiscoveryRepresentation, "ncg", correlationId);

            handlerMock.Protected().Verify(
                "SendAsync",
                Times.Exactly(1),
                ItExpr.Is <HttpRequestMessage>(message => message.Method == HttpMethod.Post &&
                                               message.RequestUri == authenticationUri),
                ItExpr.IsAny <CancellationToken>());
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        private async void ShouldReturnPatientForAlreadyLinkedPatient()
        {
            var patientDiscovery = new PatientDiscovery(
                matchingRepository.Object,
                discoveryRequestRepository.Object,
                linkPatientRepository.Object,
                patientRepository.Object,
                logger.Object);
            var phoneNumber           = Faker().Phone.PhoneNumber();
            var verifiedIdentifiers   = new[] { new Identifier(IdentifierType.MOBILE, phoneNumber) };
            var unverifiedIdentifiers = new[] { new Identifier(IdentifierType.MR, Faker().Random.String()) };
            var patientId             = Faker().Random.String();
            var name          = Faker().Name.FullName();
            var alreadyLinked =
                new CareContextRepresentation(Faker().Random.Uuid().ToString(), Faker().Random.String());
            var unlinkedCareContext =
                new CareContextRepresentation(Faker().Random.Uuid().ToString(), Faker().Random.String());
            var expectedPatient = new PatientEnquiryRepresentation(
                patientId,
                name,
                new[] { unlinkedCareContext },
                new[] { Match.ConsentManagerUserId.ToString() });
            var transactionId  = Faker().Random.String();
            var patientRequest = new PatientEnquiry(patientId,
                                                    verifiedIdentifiers,
                                                    unverifiedIdentifiers,
                                                    name,
                                                    HipLibrary.Patient.Model.Gender.M,
                                                    2019);
            var discoveryRequest  = new DiscoveryRequest(patientRequest, RandomString(), transactionId, DateTime.Now);
            var sessionId         = Faker().Random.Hash();
            var linkedCareContext = new[] { alreadyLinked.ReferenceNumber };
            var testLinkAccounts  = new LinkedAccounts(patientId,
                                                       sessionId,
                                                       Faker().Random.Hash(),
                                                       It.IsAny <string>(),
                                                       linkedCareContext.ToList());
            var testPatient =
                new HipLibrary.Patient.Model.Patient
            {
                PhoneNumber  = phoneNumber,
                Identifier   = patientId,
                Gender       = Faker().PickRandom <HipLibrary.Patient.Model.Gender>(),
                Name         = name,
                CareContexts = new[]
                {
                    alreadyLinked,
                    unlinkedCareContext
                }
            };

            linkPatientRepository.Setup(e => e.GetLinkedCareContexts(patientId))
            .ReturnsAsync(new Tuple <IEnumerable <LinkedAccounts>, Exception>(
                              new List <LinkedAccounts> {
                testLinkAccounts
            },
                              null));
            patientRepository.Setup(x => x.PatientWith(testPatient.Identifier))
            .Returns(Option.Some(testPatient));

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

            discoveryResponse.Patient.Should().BeEquivalentTo(expectedPatient);
            discoveryRequestRepository.Verify(
                x => x.Add(It.Is <HipService.Discovery.Model.DiscoveryRequest>(
                               r => r.TransactionId == transactionId && r.ConsentManagerUserId == patientId)),
                Times.Once);
            error.Should().BeNull();
        }
Ejemplo n.º 8
0
        private async void ShouldReturnAPatientWhenUnverifiedIdentifierIsNull()
        {
            var patientDiscovery = new PatientDiscovery(
                matchingRepository.Object,
                discoveryRequestRepository.Object,
                linkPatientRepository.Object,
                patientRepository.Object,
                logger.Object);
            var          referenceNumber      = Faker().Random.String();
            var          consentManagerUserId = Faker().Random.String();
            var          transactionId        = Faker().Random.String();
            var          name        = Faker().Name.FullName();
            const ushort yearOfBirth = 2019;
            var          phoneNumber = Faker().Phone.PhoneNumber();
            var          careContextRepresentations = new[]
            {
                new CareContextRepresentation(Faker().Random.String(), Faker().Random.String()),
                new CareContextRepresentation(Faker().Random.String(), Faker().Random.String())
            };
            var expectedPatient = new PatientEnquiryRepresentation(
                referenceNumber,
                name,
                careContextRepresentations,
                new List <string>
            {
                Match.Mobile.ToString(),
                Match.Name.ToString(),
                Match.Gender.ToString()
            });
            var verifiedIdentifiers = new[] { new Identifier(IdentifierType.MOBILE, phoneNumber) };
            var patientRequest      = new PatientEnquiry(consentManagerUserId,
                                                         verifiedIdentifiers,
                                                         null,
                                                         name,
                                                         HipLibrary.Patient.Model.Gender.M,
                                                         yearOfBirth);
            var discoveryRequest = new DiscoveryRequest(patientRequest, RandomString(), transactionId, 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
                {
                    Gender       = HipLibrary.Patient.Model.Gender.M,
                    Identifier   = referenceNumber,
                    Name         = name,
                    CareContexts = careContextRepresentations,
                    PhoneNumber  = phoneNumber,
                    YearOfBirth  = yearOfBirth
                }
            }.AsQueryable()));

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

            discoveryResponse.Patient.Should().BeEquivalentTo(expectedPatient);
            discoveryRequestRepository.Verify(
                x => x.Add(It.Is <HipService.Discovery.Model.DiscoveryRequest>(
                               r => r.TransactionId == transactionId && r.ConsentManagerUserId == consentManagerUserId)),
                Times.Once);
            error.Should().BeNull();
        }
Ejemplo n.º 9
0
 public DiscoveryRepresentation(PatientEnquiryRepresentation patient)
 {
     Patient = patient;
 }