private async Task <DocumentCollection> RetrieveOrCreateCollectionAsync(DocDbCollectionSettings collectionSettings, Database db) { var collection = this.documentClient.CreateDocumentCollectionQuery(db.SelfLink).Where(d => d.Id == collectionSettings.CollectionName).AsEnumerable() .FirstOrDefault(); if (collection == null) { var documentCollection = collectionSettings.ToDocumentCollection(); //required to use partitioned collections var requestOptions = new RequestOptions(); //do not check documentCollection.PartitionKey property because //the partitionKey property creates a default value on calls to the getter and default values will fail //so make sure not to call it. Bad MS! if (collectionSettings.PartitionKeyType != DocDbCollectionSettings.PartitionKeyTypeEnum.None) { requestOptions.OfferThroughput = 2600; } collection = await this.documentClient.CreateDocumentCollectionAsync(db.SelfLink, documentCollection, requestOptions).ConfigureAwait(false); } return(collection); }
public static TestHarnessOptions Create(DocDbCollectionSettings collectionSettings) { return new TestHarnessOptions { CollectionSettings = collectionSettings }; }
public WhenDocumentsAreCreatedWithClassNameAsThePartitionKey() { //Given var collectionName = nameof(WhenDocumentsAreCreatedWithClassNameAsThePartitionKey); var docDbCollectionSettings = DocDbCollectionSettings.Create(collectionName, DocDbCollectionSettings.PartitionKeyTypeEnum.ClassName); this.testHarness = TestHarnessFunctions.GetDocumentDbTestHarness(collectionName, docDbCollectionSettings); //When for (var i = 0; i < 5; i++) { var car = new Car { id = Guid.NewGuid(), Make = "Saab" }; this.testHarness.DataStore.Create(car).Wait(); } this.testHarness.DataStore.CommitChanges().Wait(); //HACK: runtime manual override docDbCollectionSettings.EnableCrossParitionQueries = false; }
public WhenDocumentsAreCreatedWithIdAsThePartitionKey() { //Given var collectionName = nameof(WhenDocumentsAreCreatedWithIdAsThePartitionKey); this.docDbCollectionSettings = DocDbCollectionSettings.Create(collectionName, DocDbCollectionSettings.PartitionKeyTypeEnum.Id); this.testHarness = TestHarnessFunctions.GetDocumentDbTestHarness(collectionName, this.docDbCollectionSettings); //When for (var i = 0; i < 3; i++) //only three because they are expensive { var car = new Car { id = Guid.NewGuid(), Make = "Volvo" }; this.testHarness.DataStore.Create(car).Wait(); } this.testHarness.DataStore.CommitChanges().Wait(); }
internal static ITestHarness GetDocumentDbTestHarness(string testName, DocDbCollectionSettings collectionSettings = null) { var options = TestHarnessOptions.Create(collectionSettings ?? DocDbCollectionSettings.Create(testName)); var documentdbsettingsJson = "DocumentDbSettings.json"; /* * Create this file in your DataStore.Tests project root and set it's build output to "copy always" * This file should always be .gitignore(d), don't want to expose this in your repo. * { * "AuthorizationKey": "<azurekey>", * "DatabaseName": "<dbname>", * "EndpointUrl": "<endpointurl>" * } */ var location = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, documentdbsettingsJson); var documentDbSettings = JsonConvert.DeserializeObject <DocumentDbSettings>(File.ReadAllText(location)); documentDbSettings.CollectionSettings = options.CollectionSettings; return(DocumentDbTestHarness.Create(documentDbSettings)); }