示例#1
0
        public void WhenBatchSubmittedWithInvalidItem_AllActionsExecuted()
        {
            var updateResource = (Observation)_resource.DeepCopy();

            updateResource.Id = Guid.NewGuid().ToString();

            // Per the spec, a create is handled via a post and update is handled via a put.
            // In a put "The request body SHALL be a Resource with an id element that has an identical value to the [id] in the URL. If no id element is provided, or the value is wrong, the server SHALL respond with an HTTP 400 error code..."
            var transaction = new TransactionBuilder(_fhirClient.Endpoint)
                              .Create(_resource)
                              .Update(Guid.NewGuid().ToString(), updateResource); // Pass a different id than the update resource id.

            var bundle = transaction.ToBundle();

            bundle.Type = Bundle.BundleType.Batch;

            BundleHelper.CleanEntryRequestUrls(bundle, _fhirClient.Endpoint);

            var batchResult = _fhirClient.Transaction(bundle);

            Assert.NotNull(batchResult);
            Assert.Equal(2, batchResult.Entry.Count);

            var createResult = batchResult.Entry[0];

            AssertHelper.CheckStatusCode(HttpStatusCode.Created, createResult.Response.Status);

            var updateResult = batchResult.Entry[1];

            AssertHelper.CheckStatusCode(HttpStatusCode.BadRequest, updateResult.Response.Status);

            AssertHelper.CheckStatusCode(HttpStatusCode.OK, _fhirClient.LastResult.Status);
        }