public async Task ListBlobsScenarioTest(string containerName, BlobListingContext listingContext, HttpStatusCode?expectedError, params string[] expectedBlobs)
        {
            HttpRequestMessage request = BlobTests.ListBlobsRequest(BlobContext, containerName, listingContext);

            Assert.IsTrue(request != null, "Failed to create HttpRequestMessage");

            using (HttpResponseMessage response = await BlobTestUtils.GetResponse(request, BlobContext))
            {
                BlobTests.ListBlobsResponse(response, BlobContext, expectedError);
                ListBlobsResponse listBlobsResponse = await ListBlobsResponse.ParseAsync(HttpResponseParsers.GetResponseStream(response), CancellationToken.None);

                int i = 0;
                foreach (IListBlobEntry item in listBlobsResponse.Blobs)
                {
                    ListBlobEntry blob = item as ListBlobEntry;
                    if (expectedBlobs == null)
                    {
                        Assert.Fail("Should not have blobs.");
                    }
                    Assert.IsTrue(i < expectedBlobs.Length, "Unexpected blob: " + blob.Name);
                    Assert.AreEqual <string>(expectedBlobs[i++], blob.Name, "Incorrect blob.");
                }
                if (expectedBlobs != null && i < expectedBlobs.Length)
                {
                    Assert.Fail("Missing blob: " + expectedBlobs[i] + "(and " + (expectedBlobs.Length - i - 1) + " more).");
                }
            }
        }
示例#2
0
        public void ListBlobsScenarioTest(string containerName, BlobListingContext listingContext, HttpStatusCode?expectedError, params string[] expectedBlobs)
        {
            HttpWebRequest request = BlobTests.ListBlobsRequest(BlobContext, containerName, listingContext);

            Assert.IsTrue(request != null, "Failed to create HttpWebRequest");
            if (BlobContext.Credentials != null)
            {
                BlobTests.SignRequest(request, BlobContext);
            }
            HttpWebResponse response = BlobTestUtils.GetResponse(request, BlobContext);

            try
            {
                BlobTests.ListBlobsResponse(response, BlobContext, expectedError);
                ListBlobsResponse listBlobsResponse = new ListBlobsResponse(response.GetResponseStream());
                int i = 0;
                foreach (IListBlobEntry item in listBlobsResponse.Blobs)
                {
                    ListBlobEntry blob = item as ListBlobEntry;
                    if (expectedBlobs == null)
                    {
                        Assert.Fail("Should not have blobs.");
                    }
                    Assert.IsTrue(i < expectedBlobs.Length, "Unexpected blob: " + blob.Name);
                    Assert.AreEqual <string>(expectedBlobs[i++], blob.Name, "Incorrect blob.");
                }
                if (expectedBlobs != null && i < expectedBlobs.Length)
                {
                    Assert.Fail("Missing blob: " + expectedBlobs[i] + "(and " + (expectedBlobs.Length - i - 1) + " more).");
                }
            }
            finally
            {
                response.Close();
            }
        }