public async Task GivenACreateRequest_WithWithNoConsistencySpecifiedAndNoRequestOptions_ThenNoRequestOptionsAreCreated() { _innerClient.CreateDocumentAsync("coll", (1, 2)).Returns(CreateResourceResponse(new Document(), HttpStatusCode.OK, new NameValueCollection())); await _fhirClient.CreateDocumentAsync("coll", (1, 2)); await _innerClient.Received().CreateDocumentAsync("coll", (1, 2)); }
public async Task GivenACollection_WhenSettingUpCollection_ThenTheCollectionIndexIsUpdated() { var documentCollection = new DocumentCollection(); await UpdateCollectionAsync(documentCollection); await _client.Received(1).ReplaceDocumentCollectionAsync(Arg.Is(documentCollection)); }
public async Task GivenACreateRequest_WithWithNoConsistencySpecifiedAndNoRequestOptions_ThenNoRequestOptionsAreCreated() { _innerClient.CreateDocumentAsync("coll", (1, 2)).Returns(CosmosDbMockingHelper.CreateResourceResponse(new Document(), HttpStatusCode.OK, new NameValueCollection())); await _fhirClient.CreateDocumentAsync("coll", (1, 2)); await _innerClient.Received().CreateDocumentAsync("coll", (1, 2)); await _cosmosResponseProcessor.Received(1).ProcessResponse(Arg.Any <ResourceResponseBase>()); }
public async Task Document_AddAsyncCallsClient() { var model = new Test(); var uri = UriFactory.CreateDocumentCollectionUri("DB", "DOC"); var doc = new DocumentClientService.Document <Test>(_documentClient, "DB", "DOC"); await doc.AddOrUpdateAsync(model); _documentClient.Received().UpsertDocumentAsync(uri, model); }
public async void GivenAConfigurationWithDatabaseCreation_WhenInitializing_ThenCreateDatabaseIfNotExistsIsCalled() { cosmosDataStoreConfiguration.AllowDatabaseCreation = true; await _documentClientInitializer.InitializeDataStore(_documentClient, cosmosDataStoreConfiguration, _collectionInitializers); await _documentClient.Received(1).CreateDatabaseIfNotExistsAsync(Arg.Any <Database>(), Arg.Any <RequestOptions>()); }
public async Task GivenARegistryInitializer_WhenDatabaseIsNew_SearchParametersShouldBeUpserted() { IDocumentQuery <dynamic> documentQuery = Substitute.For <IDocumentQuery <dynamic> >(); _cosmosDocumentQueryFactory.Create <dynamic>(Arg.Any <IDocumentClient>(), Arg.Any <CosmosQueryContext>()) .Returns(documentQuery); documentQuery .ExecuteNextAsync() .Returns(new FeedResponse <dynamic>(new dynamic[0])); IDocumentClient documentClient = Substitute.For <IDocumentClient>(); var relativeCollectionUri = new Uri("/collection1", UriKind.Relative); await _initializer.ExecuteAsync(documentClient, new DocumentCollection(), relativeCollectionUri); await documentClient.Received().UpsertDocumentAsync( relativeCollectionUri, Arg.Is <SearchParameterStatusWrapper>(x => x.Uri == _testParameterUri)); }
public async void EnsureConfigCurrentWithChangedSignature() { var dbConfig = CreateDbConfig(); string oldSig = "old_sig"; string newSig = "new_sig"; var configDoc = CreateConfigDoc("Test", oldSig); DocumentStoreConfigBuilder storeABuilder = new DocumentStoreConfigBuilder("StoreA"); storeABuilder.AddDocument("DocA"); DocumentStoreConfigBuilder storeBBuilder = new DocumentStoreConfigBuilder("StoreB"); storeBBuilder.AddDocument("DocA"); storeBBuilder.AddDocument("DocB"); var configSourceA = CreateConfigSource(storeABuilder); var configSourceB = CreateConfigSource(storeBBuilder); _signatureGenerator.CreateSignature(Arg.Any <IList <DocumentStoreConfig> >()).Returns(newSig); _documentClient.ReadDocumentAsync(Arg.Any <Uri>(), Arg.Is <RequestOptions>(x => x.PartitionKey != null)).Returns(WrapResource(configDoc)); // Existing index that should remain. var includeIdx1 = new IncludedPath(); includeIdx1.Path = "/content_Test_StoreA_DocA/*"; includeIdx1.Indexes.Add(new HashIndex(DataType.String, -1)); // Existing index that should be removed. It is no longer present. var includeIdx2 = new IncludedPath(); includeIdx2.Path = "/content_Test_StoreB_DocA/PropA/*"; includeIdx2.Indexes.Add(new RangeIndex(DataType.String)); var col1 = new DocumentCollection(); col1.IndexingPolicy.IncludedPaths.Add(includeIdx1); col1.IndexingPolicy.IncludedPaths.Add(includeIdx2); _documentClient.ReadDocumentCollectionAsync(Arg.Any <Uri>()).Returns(WrapResource(col1)); var manager = new ServiceDbConfigManager("Test", _signatureGenerator); var foo = WrapResource(col1); _documentClient.ReplaceDocumentCollectionAsync(Arg.Any <DocumentCollection>(), Arg.Any <RequestOptions>()).Returns(foo); _documentClient.UpsertDocumentAsync( Arg.Any <Uri>(), Arg.Is <object>(r => ((ServiceDbConfigManager.ServiceConfigRecord)r).Signature == newSig), Arg.Any <RequestOptions>()) .Returns(WrapResource(CreateConfigDoc(configDoc.Id, newSig))); manager.RegisterStoreConfigSource(configSourceA); manager.RegisterStoreConfigSource(configSourceB); manager.EnsureConfigCurrent(_documentClient, dbConfig); await _documentClient.Received(1).UpsertDocumentAsync(Arg.Any <Uri>(), Arg.Any <object>(), Arg.Any <RequestOptions>()); await _documentClient.Received().ReplaceDocumentCollectionAsync( Arg.Is <DocumentCollection>(c => IncludedPathCheck( c.IndexingPolicy.IncludedPaths, "/content_Test_StoreA_DocA/*", "/content_Test_StoreB_DocA/*", "/content_Test_StoreB_DocB/*")), Arg.Any <RequestOptions>()); }