public void TestAllKeys(HeaderType headerType) { INameValueCollection headers = this.CreateHeaders(headerType); headers[Key] = Guid.NewGuid().ToString(); Assert.AreEqual(Key, headers.AllKeys().First()); }
private StoredProcedureResponse <string> CreateDocumentScript(DocumentClient client, INameValueCollection headers) { var headersIterator = headers.AllKeys().SelectMany(headers.GetValues, (k, v) => new { key = k, value = v }); var scriptOptions = "{"; var headerIndex = 0; foreach (var header in headersIterator) { if (headerIndex != 0) { scriptOptions += ", "; } headerIndex++; scriptOptions += header.key + ":" + header.value; } scriptOptions += "}"; var guid = Guid.NewGuid().ToString(); var script = @" function() { var client = getContext().getCollection(); client.createDocument(client.getSelfLink(), { id: ""TestDoc"" }," + scriptOptions + @", function(err, docCreated, options) { if(err) throw new Error('Error while creating document: ' + err.message); else { getContext().getResponse().setBody(JSON.stringify(docCreated)); } });}"; Database database = client.CreateDatabaseAsync(new Database { Id = Guid.NewGuid().ToString() }).Result; PartitionKeyDefinition partitionKeyDefinition = new PartitionKeyDefinition { Paths = new System.Collections.ObjectModel.Collection <string>(new[] { "/id" }), Kind = PartitionKind.Hash }; DocumentCollection collection = client.CreateDocumentCollectionAsync(database.SelfLink, new DocumentCollection { Id = Guid.NewGuid().ToString(), PartitionKey = partitionKeyDefinition }).Result; var sproc = new StoredProcedure() { Id = Guid.NewGuid().ToString(), Body = script }; var createdSproc = client.CreateStoredProcedureAsync(collection, sproc).Result.Resource; RequestOptions requestOptions = new RequestOptions(); requestOptions.PartitionKey = new PartitionKey("TestDoc"); var result = client.ExecuteStoredProcedureAsync <string>(createdSproc, requestOptions).Result; return(result); }
private StoredProcedureResponse <string> ReadFeedScript(DocumentClient client, INameValueCollection headers) { var headersIterator = headers.AllKeys().SelectMany(headers.GetValues, (k, v) => new { key = k, value = v }); var scriptOptions = "{"; var headerIndex = 0; foreach (var header in headersIterator) { if (headerIndex != 0) { scriptOptions += ", "; } headerIndex++; scriptOptions += header.key + ":" + header.value; } scriptOptions += "}"; var script = @"function() { var client = getContext().getCollection(); function callback(err, docFeed, responseOptions) { if(err) throw 'Error while reading documents'; docFeed.forEach(function(doc, i, arr) { getContext().getResponse().appendBody(JSON.stringify(doc)); }); }; client.readDocuments(client.getSelfLink()," + scriptOptions + @", callback);}"; Database database = client.CreateDatabaseAsync(new Database { Id = Guid.NewGuid().ToString() }).Result; PartitionKeyDefinition partitionKeyDefinition = new PartitionKeyDefinition { Paths = new System.Collections.ObjectModel.Collection <string>(new[] { "/id" }), Kind = PartitionKind.Hash }; DocumentCollection collection = client.CreateDocumentCollectionAsync(database.SelfLink, new DocumentCollection { Id = Guid.NewGuid().ToString(), PartitionKey = partitionKeyDefinition }).Result; var sproc = new StoredProcedure() { Id = Guid.NewGuid().ToString(), Body = script }; var createdSproc = client.CreateStoredProcedureAsync(collection, sproc).Result.Resource; RequestOptions requestOptions = new RequestOptions(); requestOptions.PartitionKey = new PartitionKey("test"); var result = client.ExecuteStoredProcedureAsync <string>(createdSproc, requestOptions).Result; return(result); }
public void TestAllKeysWithKnownProperties(HeaderType headerType) { INameValueCollection headers = this.CreateHeaders(headerType); headers[Key] = Guid.NewGuid().ToString(); headers.Add(HttpConstants.HttpHeaders.Continuation, Guid.NewGuid().ToString()); headers[HttpConstants.HttpHeaders.RetryAfterInMilliseconds] = "20"; headers.Add(WFConstants.BackendHeaders.SubStatus, "1002"); headers.Add(HttpConstants.HttpHeaders.PartitionKey, Guid.NewGuid().ToString()); string[] allKeys = headers.AllKeys(); Assert.IsTrue(allKeys.Contains(Key)); Assert.IsTrue(allKeys.Contains(HttpConstants.HttpHeaders.PartitionKey)); Assert.IsTrue(allKeys.Contains(HttpConstants.HttpHeaders.RetryAfterInMilliseconds)); Assert.IsTrue(allKeys.Contains(HttpConstants.HttpHeaders.Continuation)); Assert.IsTrue(allKeys.Contains(WFConstants.BackendHeaders.SubStatus)); }
private StoredProcedureResponse <string> CreateDocumentScript(DocumentClient client, INameValueCollection headers) { var headersIterator = headers.AllKeys().SelectMany(headers.GetValues, (k, v) => new { key = k, value = v }); var scriptOptions = "{"; var headerIndex = 0; foreach (var header in headersIterator) { if (headerIndex != 0) { scriptOptions += ", "; } headerIndex++; scriptOptions += header.key + ":" + header.value; } scriptOptions += "}"; var guid = Guid.NewGuid().ToString(); var script = @" function() { var client = getContext().getCollection(); client.createDocument(client.getSelfLink(), { id: Math.random() + """" }," + scriptOptions + @", function(err, docCreated, options) { if(err) throw new Error('Error while creating document: ' + err.message); else { getContext().getResponse().setBody(JSON.stringify(docCreated)); } });}"; var collection = TestCommon.CreateOrGetDocumentCollection(client); var sproc = new StoredProcedure() { Id = Guid.NewGuid().ToString(), Body = script }; var createdSproc = client.CreateStoredProcedureAsync(collection, sproc).Result.Resource; var result = client.ExecuteStoredProcedureAsync <string>(createdSproc).Result; return(result); }
private StoredProcedureResponse <string> ReadFeedScript(DocumentClient client, INameValueCollection headers) { var headersIterator = headers.AllKeys().SelectMany(headers.GetValues, (k, v) => new { key = k, value = v }); var scriptOptions = "{"; var headerIndex = 0; foreach (var header in headersIterator) { if (headerIndex != 0) { scriptOptions += ", "; } headerIndex++; scriptOptions += header.key + ":" + header.value; } scriptOptions += "}"; var script = @"function() { var client = getContext().getCollection(); function callback(err, docFeed, responseOptions) { if(err) throw 'Error while reading documents'; docFeed.forEach(function(doc, i, arr) { getContext().getResponse().appendBody(JSON.stringify(doc)); }); }; client.readDocuments(client.getSelfLink()," + scriptOptions + @", callback);}"; var collection = TestCommon.CreateOrGetDocumentCollection(client); var sproc = new StoredProcedure() { Id = Guid.NewGuid().ToString(), Body = script }; var createdSproc = client.CreateStoredProcedureAsync(collection, sproc).Result.Resource; var result = client.ExecuteStoredProcedureAsync <string>(createdSproc).Result; return(result); }