public void GivenAPatientResponse_WhenPropertySetterIsUsed_ThenCorrectValueShouldBeSet()
        {
            FhirTransactionResponseEntry expectedResponse = ExecutePropertySetter(nameof(FhirTransactionRequest.Patient));

            Assert.Same(_fhirTransactionResponse.Patient, expectedResponse);
            Assert.Null(_fhirTransactionResponse.ImagingStudy);
            Assert.Null(_fhirTransactionResponse.Endpoint);
        }
        private FhirTransactionResponseEntry ExecutePropertySetter(string propertyName)
        {
            FhirTransactionRequestResponsePropertyAccessor propertyAccessor = GetPropertyAccessor(propertyName);

            var expectedResponse = new FhirTransactionResponseEntry(new Bundle.ResponseComponent(), new Patient());

            propertyAccessor.ResponseEntrySetter(_fhirTransactionResponse, expectedResponse);

            return(expectedResponse);
        }
        public void GiveTheResponseEntryGetter_WhenInvoked_ThenCorrectValueShouldBeSet()
        {
            var responseEntry = new FhirTransactionResponseEntry(
                new Bundle.ResponseComponent(),
                new Patient());

            _patientPropertyAccessor.ResponseEntrySetter(_fhirTransactionResponse, responseEntry);

            Assert.Same(
                responseEntry,
                _fhirTransactionResponse.Patient);
        }
Exemple #4
0
        public async Task GivenAResourceToProcess_WhenProcessed_ThenTransactionShouldBeExecuted(FhirTransactionRequestMode requestMode)
        {
            // Setup the pipeline step to simulate creating/updating patient.
            var patientRequest = new FhirTransactionRequestEntry(
                requestMode,
                new Bundle.RequestComponent(),
                new ClientResourceId(),
                new Patient());

            var pipelineStep = new MockFhirTransactionPipelineStep()
            {
                OnPrepareRequestAsyncCalled = (context, cancellationToken) =>
                {
                    context.Request.Patient = patientRequest;

                    Assert.Equal(DefaultCancellationToken, cancellationToken);
                },
            };

            _fhirTransactionPipelineSteps.Add(pipelineStep);

            // Setup the transaction executor to return response.
            var responseBundle = new Bundle();

            var responseEntry = new Bundle.EntryComponent()
            {
                Response = new Bundle.ResponseComponent(),
                Resource = new Patient(),
            };

            responseBundle.Entry.Add(responseEntry);

            _fhirTransactionExecutor.ExecuteTransactionAsync(
                Arg.Any <Bundle>(),
                DefaultCancellationToken)
            .Returns(call =>
            {
                // Make sure the request bundle is correct.
                Bundle requestBundle = call.ArgAt <Bundle>(0);

                Assert.NotNull(requestBundle);
                Assert.Equal(Bundle.BundleType.Transaction, requestBundle.Type);

                Assert.Collection(
                    requestBundle.Entry,
                    entry =>
                {
                    Assert.Equal(patientRequest.ResourceId.ToString(), entry.FullUrl);
                    Assert.Equal(patientRequest.Request, entry.Request);
                    Assert.Equal(patientRequest.Resource, entry.Resource);
                });

                return(responseBundle);
            });

            // Process
            await _fhirTransactionPipeline.ProcessAsync(ChangeFeedGenerator.Generate(), DefaultCancellationToken);

            // The response should have been processed.
            Assert.NotNull(_capturedFhirTransactionContext);

            FhirTransactionResponseEntry patientResponse = _capturedFhirTransactionContext.Response.Patient;

            Assert.NotNull(patientResponse);
            Assert.Equal(responseEntry.Response, patientResponse.Response);
            Assert.Equal(responseEntry.Resource, patientResponse.Resource);
        }