예제 #1
0
        public async Task WhenThrowAnExceptionInProcess_ThrowTheSameException()
        {
            var pipelineStep = new MockFhirTransactionPipelineStep()
            {
                OnPrepareRequestAsyncCalled = (context, cancellationToken) =>
                {
                    throw new Exception();
                },
            };

            _fhirTransactionPipelineSteps.Add(pipelineStep);

            // Process
            await Assert.ThrowsAsync <Exception>(() => _fhirTransactionPipeline.ProcessAsync(ChangeFeedGenerator.Generate(), DefaultCancellationToken));
        }
예제 #2
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);
        }