コード例 #1
0
 public void ByteParsingToFindJsonArray()
 {
     using (MemoryStream ms = new MemoryStream(this.payloadBytes))
     {
         long length = ms.Length;
         using (MemoryStream memoryStream = CosmosFeedResponseSerializer.GetStreamWithoutServiceEnvelope(ms))
         {
             if (length == memoryStream.Length)
             {
                 throw new Exception();
             }
         }
     }
 }
コード例 #2
0
        public async Task ReadManyStreamTest()
        {
            List <(string, PartitionKey)> itemList = new List <(string, PartitionKey)>();

            for (int i = 0; i < 5; i++)
            {
                itemList.Add((i.ToString(), new PartitionKey("pk" + i.ToString())));
            }

            using (ResponseMessage responseMessage = await this.Container.ReadManyItemsStreamAsync(itemList))
            {
                Assert.IsNotNull(responseMessage);
                Assert.IsTrue(responseMessage.Headers.RequestCharge > 0);
                Assert.IsNotNull(responseMessage.Diagnostics);

                ToDoActivity[] items = this.cosmosClient.ClientContext.SerializerCore.FromFeedStream <ToDoActivity>(
                    CosmosFeedResponseSerializer.GetStreamWithoutServiceEnvelope(responseMessage.Content));
                Assert.AreEqual(items.Length, 5);
            }
        }
コード例 #3
0
        public async Task ReadManyWithIdasPk()
        {
            string PartitionKey = "/id";
            ContainerProperties containerSettings = new ContainerProperties(id: Guid.NewGuid().ToString(), partitionKeyPath: PartitionKey);
            Container           container         = await this.database.CreateContainerAsync(containerSettings);

            List <(string, PartitionKey)> itemList = new List <(string, PartitionKey)>();

            for (int i = 0; i < 5; i++)
            {
                itemList.Add((i.ToString(), new PartitionKey(i.ToString())));
            }

            // Create items with different pk values
            for (int i = 0; i < 5; i++)
            {
                ToDoActivity item = ToDoActivity.CreateRandomToDoActivity();
                item.id = i.ToString();
                ItemResponse <ToDoActivity> itemResponse = await container.CreateItemAsync(item);

                Assert.AreEqual(HttpStatusCode.Created, itemResponse.StatusCode);
            }

            using (ResponseMessage responseMessage = await container.ReadManyItemsStreamAsync(itemList))
            {
                Assert.IsNotNull(responseMessage);
                Assert.IsTrue(responseMessage.Headers.RequestCharge > 0);
                Assert.IsNotNull(responseMessage.Diagnostics);

                ToDoActivity[] items = this.cosmosClient.ClientContext.SerializerCore.FromFeedStream <ToDoActivity>(
                    CosmosFeedResponseSerializer.GetStreamWithoutServiceEnvelope(responseMessage.Content));
                Assert.AreEqual(items.Length, 5);
            }

            FeedResponse <ToDoActivity> feedResponse = await container.ReadManyItemsAsync <ToDoActivity>(itemList);

            Assert.IsNotNull(feedResponse);
            Assert.AreEqual(feedResponse.Count, 5);
            Assert.IsTrue(feedResponse.Headers.RequestCharge > 0);
            Assert.IsNotNull(feedResponse.Diagnostics);
        }