public LargeDocumentStore(IDocumentDbAccessProvider dbAccessProvider) : base(dbAccessProvider, false) { var config = new DocumentStoreConfigBuilder("LargeStore"); var largeDocumentType = config.AddDocument("LargeDocument"); var attachmentDocumentType = config.AddDocument("AttachmentDocument"); var attachmentType = attachmentDocumentType.AddAttachment("Attachment"); _largeMapping = config.AddDocumentMapping <LargeDocument>(largeDocumentType.Name) .SetIdMapper(x => x.Id.ToString()) .SetPartitionMapper(x => x.Id.ToString()) .Finish(); _smallMapping = config.AddDocumentMapping <SmallDocumentWithLargeAttachment>(attachmentDocumentType.Name) .SetIdMapper(x => x.Id.ToString()) .SetPartitionMapper(x => x.Id.ToString()) .Finish(); _attachmentMapping = _smallMapping.AddAttachmentMapping <LargeDocument>(attachmentType.Name) .Finish(); _config = config.Finish(); _client = CreateStoreLogic(DbAccess, _config); DbAccess.ConfigRegistry.RegisterStoreConfigSource(this); }
private IDocumentStoreConfigSource CreateConfigSource(DocumentStoreConfigBuilder storeBuilder) { var configSource = Substitute.For <IDocumentStoreConfigSource>(); configSource.GetConfig().Returns(storeBuilder.Finish()); return(configSource); }
public void CreateSignatureForEqualConfigsWithSingleInput() { DocumentStoreConfigBuilder storeABuilder = new DocumentStoreConfigBuilder("StoreA"); storeABuilder.AddDocument("DocA"); storeABuilder.AddDocument("DocB"); storeABuilder.AddDocument("DocC"); DoSignatureTest(new[] { storeABuilder.Finish() }); }
private IDocumentStoreConfigSource CreateConfigSource(string storeName) { DocumentStoreConfigBuilder storeABuilder = new DocumentStoreConfigBuilder(storeName); storeABuilder.AddDocument("DocA"); var configSource = Substitute.For <IDocumentStoreConfigSource>(); configSource.GetConfig().Returns(storeABuilder.Finish()); return(configSource); }
public FlowerStore(IDocumentDbAccessProvider dbAccessProvider) : base(dbAccessProvider, false) { var config = new DocumentStoreConfigBuilder("Flowers"); var documentType = config.AddDocument("Daisy").Finish(); _mapping = config.AddDocumentMapping <Daisy>(documentType.DocumentName) .SetIdMapper(x => x.Id.ToString()) .SetPartitionMapper(x => x.Id.ToString()) .Finish(); _config = config.Finish(); _client = CreateStoreLogic(DbAccess, _config); DbAccess.ConfigRegistry.RegisterStoreConfigSource(this); }
public OrderStore( IDocumentDbAccessProvider dbAccessProvider, IDocumentMetadataSource metadataSource) : base(dbAccessProvider) { var config = new DocumentStoreConfigBuilder("Orders"); var orderDocumentType = config.AddDocument("Order").Finish(); _orderMapping = config.AddDocumentMapping <Order>(orderDocumentType.DocumentName) .SetIdMapper(x => x.Id.ToString()) .SetPartitionMapper(x => x.Id.ToString()) .Finish(); _config = config.Finish(); _client = CreateStoreLogic(DbAccess, _config, metadataSource); }
public void CreateSignatureForEqualConfigsWithMultipleInputs() { DocumentStoreConfigBuilder builderA = new DocumentStoreConfigBuilder("StoreA"); builderA.AddDocument("DocA"); builderA.AddDocument("DocB"); builderA.AddDocument("DocC"); DocumentStoreConfigBuilder builderB = new DocumentStoreConfigBuilder("StoreB"); builderB.AddDocument("DocA"); builderB.AddDocument("DocB"); DocumentStoreConfigBuilder builderC = new DocumentStoreConfigBuilder("StoreC"); builderB.AddDocument("DocD"); DoSignatureTest(new[] { builderA, builderB, builderC }.Select(x => x.Finish()).ToArray()); }
public EmailStore(IDocumentDbAccessProvider dbAccessProvider) : base(dbAccessProvider, false) { var config = new DocumentStoreConfigBuilder("EmailClient"); var documentType = config.AddDocument("Email"); var attachmentType = documentType.AddAttachment("EmailAttachment"); _mapping = config.AddDocumentMapping <Email>(documentType.Name) .SetIdMapper(x => x.Id.ToString()) .SetPartitionMapper(x => x.Id.ToString()) .Finish(); _attachmentMapping = _mapping.AddAttachmentMapping <EmailAttachment>(attachmentType.Name) .Finish(); _config = config.Finish(); _client = CreateStoreLogic(DbAccess, _config); DbAccess.ConfigRegistry.RegisterStoreConfigSource(this); }
public void CreateSignatureForInequalConfigs() { DocumentStoreConfigBuilder builder = new DocumentStoreConfigBuilder("StoreA"); builder.AddDocument("DocA"); DocumentStoreConfigBuilder builderChangedStoreName = new DocumentStoreConfigBuilder("StoreB"); builderChangedStoreName.AddDocument("DocA"); DocumentStoreConfigBuilder builderChangedDocName = new DocumentStoreConfigBuilder("StoreA"); builderChangedDocName.AddDocument("DocC"); var configA = new[] { builder.Finish() }; var configB = new[] { builderChangedStoreName.Finish() }; var configC = new[] { builderChangedDocName.Finish() }; DoSignatureInequalTest(new IList <DocumentStoreConfig>[] { configA, configB, configC }); }
public DocumentStore(IDocumentDbAccessProvider dbAccessProvider) : base(dbAccessProvider) { var config = new DocumentStoreConfigBuilder("Documents"); var documentType = config.AddDocument("Document1"); var document2Type = config.AddDocument("Document2"); _documentMapping = config.AddDocumentMapping <Document1>(documentType.Name) .SetIdMapper(x => x.Id.ToString()) .SetPartitionMapper(x => x.Id.ToString()) .Finish(); _document2Mapping = config.AddDocumentMapping <Document2>(document2Type.Name) .SetIdMapper(x => x.Id.ToString()) .SetPartitionMapper(x => x.Id.ToString()) .Finish(); _config = config.Finish(); _client = CreateStoreLogic(DbAccess, _config); }
public FlowerStore( IDocumentDbAccessProvider dbAccessProvider, IDocumentMetadataSource metadataSource) : base(dbAccessProvider, false) { var config = new DocumentStoreConfigBuilder("Flowers"); var daisyDocumentType = config.AddDocument("Daisy").Finish(); var roseDocumentType = config.AddDocument("Rose").Finish(); _daisyMapping = config.AddDocumentMapping <Daisy>(daisyDocumentType.DocumentName) .SetIdMapper(x => x.Id.ToString()) .SetPartitionMapper(x => x.Id.ToString()) .Finish(); _gardenMapping = config.AddDocumentMapping <Garden>(roseDocumentType.DocumentName) .SetIdMapper(x => x.Id.ToString()) .SetPartitionMapper(x => x.Id.ToString()) .Finish(); _config = config.Finish(); _client = CreateStoreLogic(DbAccess, _config, metadataSource); }
public FruitStore(IDocumentDbAccessProvider dbAccessProvider, IDocumentMetadataSource metadataSource) : base(dbAccessProvider, false) { var config = new DocumentStoreConfigBuilder("Fruit"); var appleDocumentType = config.AddDocument("Apple").Finish(); var pearDocumentType = config.AddDocument("Pear").Finish(); _appleMapping = config.AddDocumentMapping <Apple>(appleDocumentType.DocumentName) .SetIdMapper(x => x.Id.ToString()) .SetPartitionMapper(x => x.Id.ToString()) .Finish(); _pearMapping = config.AddDocumentMapping <Pear>(pearDocumentType.DocumentName) .SetIdMapper(x => x.Id.ToString()) .SetPartitionMapper(x => x.Id.ToString()) .Finish(); _config = config.Finish(); _client = CreateStoreLogic(DbAccess, _config, metadataSource); DbAccess.ConfigRegistry.RegisterStoreConfigSource(this); }
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>()); }