Beispiel #1
0
        public void ListContainersScenarioTest(ListingContext listingContext, HttpStatusCode?expectedError, params string[] expectedContainers)
        {
            HttpWebRequest request = BlobTests.ListContainersRequest(BlobContext, 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.ListContainersResponse(response, BlobContext, expectedError);
                ListContainersResponse listContainersResponse = new ListContainersResponse(response.GetResponseStream());
                int i = 0;
                foreach (BlobContainerEntry item in listContainersResponse.Containers)
                {
                    if (expectedContainers == null)
                    {
                        Assert.Fail("Should not have containers.");
                    }
                    Assert.IsTrue(i < expectedContainers.Length, "Unexpected container: " + item.Name);
                    Assert.AreEqual <string>(expectedContainers[i++], item.Name, "Incorrect container.");
                }
                if (expectedContainers != null && i < expectedContainers.Length)
                {
                    Assert.Fail("Missing container: " + expectedContainers[i] + "(and " + (expectedContainers.Length - i - 1) + " more).");
                }
            }
            finally
            {
                response.Close();
            }
        }
        public async Task ListContainersScenarioTest(ListingContext listingContext, HttpStatusCode?expectedError, params string[] expectedContainers)
        {
            HttpRequestMessage request = BlobTests.ListContainersRequest(BlobContext, listingContext);

            Assert.IsTrue(request != null, "Failed to create HttpRequestMessage");
            using (HttpResponseMessage response = await BlobTestUtils.GetResponse(request, BlobContext))
            {
                BlobTests.ListContainersResponse(response, BlobContext, expectedError);
                ListContainersResponse listContainersResponse = await ListContainersResponse.ParseAsync(HttpResponseParsers.GetResponseStream(response), CancellationToken.None);

                int i = 0;
                foreach (BlobContainerEntry item in listContainersResponse.Containers)
                {
                    if (expectedContainers == null)
                    {
                        Assert.Fail("Should not have containers.");
                    }
                    Assert.IsTrue(i < expectedContainers.Length, "Unexpected container: " + item.Name);
                    Assert.AreEqual <string>(expectedContainers[i++], item.Name, "Incorrect container.");
                }
                if (expectedContainers != null && i < expectedContainers.Length)
                {
                    Assert.Fail("Missing container: " + expectedContainers[i] + "(and " + (expectedContainers.Length - i - 1) + " more).");
                }
            }
        }