public void TestInitialize() { this.client = TestCommon.CreateClient(true); this.database = TestCommon.CreateOrGetDatabase(this.client); this.collection = new CosmosContainerSettings() { Id = Guid.NewGuid().ToString() }; this.collection.IndexingPolicy.IndexingMode = IndexingMode.Lazy; try { this.collection = this.client.CreateDocumentCollectionAsync(this.database, this.collection).Result; } catch (DocumentClientException exception) { Assert.Fail(exception.InnerException.Message); } this.triggerName = "uniqueConstraint_" + Guid.NewGuid().ToString("N"); string triggerContent = File.ReadAllText("ScriptSampleTests_UniqueConstraint.js"); CosmosTriggerSettings triggerResource = new CosmosTriggerSettings { Id = this.triggerName, Body = triggerContent, TriggerOperation = TriggerOperation.All, TriggerType = TriggerType.Pre }; CosmosTriggerSettings trigger = this.client.CreateTriggerAsync(this.collection.SelfLink, triggerResource).Result; }
public void TestInitialize() { this.client = TestCommon.CreateClient(true); this.database = TestCommon.CreateOrGetDatabase(this.client); PartitionKeyDefinition defaultPartitionKeyDefinition = new PartitionKeyDefinition { Paths = new System.Collections.ObjectModel.Collection <string>(new[] { "/pk" }), Kind = PartitionKind.Hash }; this.collection = new DocumentCollection() { Id = Guid.NewGuid().ToString(), PartitionKey = defaultPartitionKeyDefinition }; this.collection.IndexingPolicy.IndexingMode = IndexingMode.Lazy; try { this.collection = this.client.CreateDocumentCollectionAsync(this.database.SelfLink, this.collection).Result; } catch (DocumentClientException exception) { Assert.Fail(exception.InnerException.Message); } this.triggerName = "uniqueConstraint_" + Guid.NewGuid().ToString("N"); string triggerContent = File.ReadAllText("ScriptSampleTests_UniqueConstraint.js"); Trigger triggerResource = new Trigger { Id = this.triggerName, Body = triggerContent, TriggerOperation = TriggerOperation.All, TriggerType = TriggerType.Pre }; Trigger trigger = this.client.CreateTriggerAsync(this.collection.SelfLink, triggerResource).Result; }
public void TestInitialize() { this.client = TestCommon.CreateClient(true); this.database = TestCommon.CreateOrGetDatabase(this.client); }
private async Task ValidateServerSideQueryEvalWithPaginationScenario() { DocumentClient client = TestCommon.CreateClient(false, defaultConsistencyLevel: ConsistencyLevel.Session); CosmosDatabaseSettings database = TestCommon.CreateOrGetDatabase(client); CosmosContainerSettings collection = new CosmosContainerSettings { Id = "ConsistentCollection" }; collection.IndexingPolicy.IndexingMode = IndexingMode.Consistent; collection = client.Create <CosmosContainerSettings>( database.ResourceId, collection); //Do script post to insert as many document as we could in a tight loop. string script = @"function() { var output = 0; var client = getContext().getCollection(); function callback(err, docCreated) { if(err) throw 'Error while creating document'; output++; getContext().getResponse().setBody(output); if(output < 50) client.createDocument(client.getSelfLink(), { id: 'testDoc' + output, title : 'My Book'}, {}, callback); }; client.createDocument(client.getSelfLink(), { id: 'testDoc' + output, title : 'My Book'}, {}, callback); }"; StoredProcedureResponse <int> scriptResponse = null; int totalNumberOfDocuments = GatewayTests.CreateExecuteAndDeleteProcedure(client, collection, script, out scriptResponse); int pageSize = 5; int totalHit = 0; IDocumentQuery <Book> documentQuery = (from book in client.CreateDocumentQuery <Book>( collection.SelfLink, new FeedOptions { MaxItemCount = pageSize }) where book.Title == "My Book" select book).AsDocumentQuery(); while (documentQuery.HasMoreResults) { FeedResponse <dynamic> pagedResult = await documentQuery.ExecuteNextAsync(); string isUnfiltered = pagedResult.ResponseHeaders[HttpConstants.HttpHeaders.IsFeedUnfiltered]; Assert.IsTrue(string.IsNullOrEmpty(isUnfiltered), "Query is evaulated in client"); Assert.IsTrue(pagedResult.Count <= pageSize, "Page size is not honored in client site eval"); if (totalHit != 0 && documentQuery.HasMoreResults) { //Except first page and last page we should have seen client continuation token. Assert.IsFalse(pagedResult.ResponseHeaders[HttpConstants.HttpHeaders.Continuation].Contains(HttpConstants.Delimiters.ClientContinuationDelimiter), "Client continuation is missing from the response continuation"); } totalHit += pagedResult.Count; } Assert.AreEqual(totalHit, totalNumberOfDocuments, "Didnt get all the documents"); //Do with default pagination. documentQuery = (from book in client.CreateDocumentQuery <Book>( collection.SelfLink) where book.Title == "My Book" select book).AsDocumentQuery(); totalHit = 0; while (documentQuery.HasMoreResults) { FeedResponse <dynamic> pagedResult = await documentQuery.ExecuteNextAsync(); string isUnfiltered = pagedResult.ResponseHeaders[HttpConstants.HttpHeaders.IsFeedUnfiltered]; Assert.IsTrue(string.IsNullOrEmpty(isUnfiltered), "Query is evaulated in client"); Assert.IsTrue(pagedResult.Count == totalNumberOfDocuments, "Page size is not honored in client site eval"); totalHit += pagedResult.Count; } Assert.AreEqual(totalHit, totalNumberOfDocuments, "Didnt get all the documents"); }