private async Task ItemOperations(CosmosContainer container, bool containerNotExist) { if (containerNotExist) { dynamic randomItem = new { id = "test", pk = "doesnotexist" }; Stream create = jsonSerializer.ToStream <dynamic>(randomItem); this.VerifyNotFoundResponse(await container.CreateItemStreamAsync(new PartitionKey(randomItem.pk), create)); var queryIterator = container.CreateItemQueryStream("select * from t where true", maxConcurrency: 2); this.VerifyQueryNotFoundResponse(await queryIterator.FetchNextSetAsync()); var feedIterator = container.GetItemsStreamIterator(); this.VerifyNotFoundResponse(await feedIterator.FetchNextSetAsync()); dynamic randomUpsertItem = new { id = DoesNotExist, pk = DoesNotExist, status = 42 }; Stream upsert = jsonSerializer.ToStream <dynamic>(randomUpsertItem); this.VerifyNotFoundResponse(await container.UpsertItemStreamAsync( partitionKey: new Cosmos.PartitionKey(randomUpsertItem.pk), streamPayload: upsert)); } this.VerifyNotFoundResponse(await container.ReadItemStreamAsync(partitionKey: new Cosmos.PartitionKey(DoesNotExist), id: DoesNotExist)); this.VerifyNotFoundResponse(await container.DeleteItemStreamAsync(partitionKey: new Cosmos.PartitionKey(DoesNotExist), id: DoesNotExist)); dynamic randomReplaceItem = new { id = "test", pk = "doesnotexist", status = 42 }; Stream replace = jsonSerializer.ToStream <dynamic>(randomReplaceItem); this.VerifyNotFoundResponse(await container.ReplaceItemStreamAsync( partitionKey: new Cosmos.PartitionKey(randomReplaceItem.pk), id: randomReplaceItem.id, streamPayload: replace)); }
private static async Task ItemStreamFeed(CosmosContainer container) { int totalCount = 0; // SQL FeedIterator setIterator = container.GetItemsStreamIterator(); while (setIterator.HasMoreResults) { int count = 0; using (CosmosResponseMessage response = await setIterator.FetchNextSetAsync()) { response.EnsureSuccessStatusCode(); count++; using (StreamReader sr = new StreamReader(response.Content)) using (JsonTextReader jtr = new JsonTextReader(sr)) { JsonSerializer jsonSerializer = new JsonSerializer(); dynamic array = jsonSerializer.Deserialize <dynamic>(jtr); totalCount += array.Documents.Count; } } } Assert("Expected two families", totalCount == 2); }