public async Task GivenAResourceWithLargeNumberOfHistory_WhenHardDeleting_ThenServerShouldDeleteAllRelatedResourcesSuccessfully() { List <string> versionIds = new List <string>(); using FhirResponse <Observation> response = await _client.CreateAsync(Samples.GetDefaultObservation ().ToPoco <Observation>()); Observation observation = response.Resource; string resourceId = observation.Id; versionIds.Add(observation.Meta.VersionId); // Update the observation. for (int i = 0; i < 50; i++) { using FhirResponse <Observation> loopResponse = await _client.UpdateAsync(observation); versionIds.Add(loopResponse.Resource.Meta.VersionId); } // Hard-delete the resource. await _client.HardDeleteAsync(observation); // Getting the resource should result in NotFound. await ExecuteAndValidateNotFoundStatus(() => _client.ReadAsync <Observation>(ResourceType.Observation, resourceId)); // Each version read should also result in NotFound. foreach (string versionId in versionIds) { await ExecuteAndValidateNotFoundStatus(() => _client.VReadAsync <Observation>(ResourceType.Observation, resourceId, versionId)); } // History API should return NotFound. await ExecuteAndValidateNotFoundStatus(() => _client.SearchAsync($"Observation/{resourceId}/_history")); async Task ExecuteAndValidateNotFoundStatus(Func <Task> action) { FhirException exception = null; do { if (exception?.StatusCode == (HttpStatusCode)429) { // Wait for a little bit before retrying if we are geting throttled. await Task.Delay(500); } exception = await Assert.ThrowsAsync <FhirException>(action); }while (exception.StatusCode == (HttpStatusCode)429); Assert.Equal(HttpStatusCode.NotFound, exception.StatusCode); exception.Dispose(); } }
private async Task GivenExecuteAndValidateNotFoundStatus(Func <Task> action) { FhirException exception = null; do { if (exception?.StatusCode == (HttpStatusCode)429) { // Wait for a little bit before retrying if we are geting throttled. await Task.Delay(500); } exception = await Assert.ThrowsAsync <FhirException>(action); }while (exception.StatusCode == (HttpStatusCode)429); Assert.Equal(HttpStatusCode.NotFound, exception.StatusCode); exception.Dispose(); }