public void GivenAResourceWrapper_WhenConvertingToAHistoryObject_ThenTheCorrectPropertiesAreUpdated() { var wrapper = Samples.GetJsonSample <FhirCosmosResourceWrapper>("ResourceWrapperNoVersion"); var id = wrapper.Id; var lastModified = new DateTimeOffset(2017, 1, 1, 1, 1, 1, TimeSpan.Zero); var historyRecord = new FhirCosmosResourceWrapper( id, "version1", wrapper.ResourceTypeName, wrapper.RawResource, wrapper.Request, lastModified, wrapper.IsDeleted, true, null, null, null); Assert.Equal($"{id}_{historyRecord.Version}", historyRecord.Id); Assert.Equal(lastModified, historyRecord.LastModified); Assert.True(historyRecord.IsHistory); Assert.Equal("version1", historyRecord.Version); }
private async Task <(ResourceWrapper original, ResourceWrapper updated)> CreateUpdatedWrapperFromExistingResource( SaveOutcome upsertResult, string updatedId = null) { // Get wrapper from data store directly ResourceKey resourceKey = new ResourceKey(upsertResult.RawResourceElement.InstanceType, upsertResult.RawResourceElement.Id, upsertResult.RawResourceElement.VersionId); FhirCosmosResourceWrapper originalWrapper = (FhirCosmosResourceWrapper)await _dataStore.GetAsync(resourceKey, CancellationToken.None); // Add new search index entry to existing wrapper. SearchParameterInfo searchParamInfo = new SearchParameterInfo("newSearchParam"); SearchIndexEntry searchIndex = new SearchIndexEntry(searchParamInfo, new NumberSearchValue(12)); List <SearchIndexEntry> searchIndices = new List <SearchIndexEntry>() { searchIndex }; var updatedWrapper = new ResourceWrapper( updatedId == null ? originalWrapper.Id : updatedId, originalWrapper.Version, originalWrapper.ResourceTypeName, originalWrapper.RawResource, originalWrapper.Request, originalWrapper.LastModified, deleted: false, searchIndices, originalWrapper.CompartmentIndices, originalWrapper.LastModifiedClaims); return(originalWrapper, updatedWrapper); }
public async Task <UpsertWithHistoryModel> Execute(Scripts client, FhirCosmosResourceWrapper resource, string matchVersionId, bool allowCreate, bool keepHistory, CancellationToken cancellationToken) { EnsureArg.IsNotNull(client, nameof(client)); EnsureArg.IsNotNull(resource, nameof(resource)); StoredProcedureExecuteResponse <UpsertWithHistoryModel> results = await ExecuteStoredProc <UpsertWithHistoryModel>(client, resource.PartitionKey, cancellationToken, resource, matchVersionId, allowCreate, keepHistory); return(results.Resource); }
public async Task <FhirCosmosResourceWrapper> Execute(Scripts client, FhirCosmosResourceWrapper resource, string matchVersionId, CancellationToken cancellationToken) { EnsureArg.IsNotNull(client, nameof(client)); EnsureArg.IsNotNull(resource, nameof(resource)); StoredProcedureExecuteResponse <FhirCosmosResourceWrapper> result = await ExecuteStoredProc <FhirCosmosResourceWrapper>( client, resource.PartitionKey, cancellationToken, resource, matchVersionId); return(result.Resource); }
public async Task <UpsertWithHistoryModel> Execute(IDocumentClient client, Uri collection, FhirCosmosResourceWrapper resource, string matchVersionId, bool allowCreate, bool keepHistory) { EnsureArg.IsNotNull(client, nameof(client)); EnsureArg.IsNotNull(collection, nameof(collection)); EnsureArg.IsNotNull(resource, nameof(resource)); StoredProcedureResponse <UpsertWithHistoryModel> results = await ExecuteStoredProc <UpsertWithHistoryModel>(client, collection, resource.PartitionKey, resource, matchVersionId, allowCreate, keepHistory); return(results.Response); }