Exemplo n.º 1
0
        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).");
                }
            }
        }
Exemplo n.º 2
0
        public void BlobProtocolListingContextValidation()
        {
            BlobListingContext listingContext1 = new BlobListingContext("correct", 1, null, BlobListingDetails.All);

            try
            {
                BlobListingContext listingContext2 = new BlobListingContext("below min", 0, null, BlobListingDetails.All);
                Assert.Fail();
            }
            catch (ArgumentOutOfRangeException e)
            {
                Assert.IsTrue(e.ToString().Contains("System.ArgumentOutOfRangeException: The argument 'maxResults' is smaller than minimum of '1'"));
            }
            BlobListingContext listingContext3 = new BlobListingContext("not limited", 6000, null, BlobListingDetails.All);
        }
Exemplo n.º 3
0
        public async Task BlobProtocolListBlobsCloudOwnerSync()
        {
            BlobListingContext listingContext = new BlobListingContext("def", null, null, BlobListingDetails.All);
            await cloudOwnerSync.ListBlobsScenarioTest(cloudSetup.ContainerName, listingContext, null, cloudSetup.BlobName);

            await cloudSetup.CreateBlob(cloudSetup.ContainerName, "newblob1", false);

            await cloudSetup.CreateBlob(cloudSetup.ContainerName, "newblob2", false);

            try
            {
                await cloudOwnerSync.ListBlobsScenarioTest(cloudSetup.ContainerName, listingContext, null, cloudSetup.BlobName);

                listingContext = new BlobListingContext("n", 10, "/", BlobListingDetails.Metadata);
                await cloudOwnerSync.ListBlobsScenarioTest(cloudSetup.ContainerName, listingContext, null, "newblob1", "newblob2");
            }
            finally
            {
                await cloudSetup.DeleteBlob(cloudSetup.ContainerName, "newblob1");

                await cloudSetup.DeleteBlob(cloudSetup.ContainerName, "newblob2");
            }
        }
Exemplo n.º 4
0
        public async Task BlobProtocolListBlobsCloudAnonSync()
        {
            BlobListingContext listingContext = new BlobListingContext("p", null, null, BlobListingDetails.All);
            await cloudAnonSync.ListBlobsScenarioTest(cloudSetup.PublicContainerName, listingContext, null, cloudSetup.PublicBlobName);

            await cloudSetup.CreateBlob(cloudSetup.PublicContainerName, "newblob1", true);

            await cloudSetup.CreateBlob(cloudSetup.PublicContainerName, "newblob2", true);

            try
            {
                await cloudAnonSync.ListBlobsScenarioTest(cloudSetup.PublicContainerName, listingContext, null, cloudSetup.PublicBlobName);

                // snapshots cannot be listed along with delimiter
                listingContext = new BlobListingContext("n", 10, "/", BlobListingDetails.Metadata);
                await cloudAnonSync.ListBlobsScenarioTest(cloudSetup.PublicContainerName, listingContext, null, "newblob1", "newblob2");
            }
            finally
            {
                await cloudSetup.DeleteBlob(cloudSetup.PublicContainerName, "newblob1");

                await cloudSetup.DeleteBlob(cloudSetup.PublicContainerName, "newblob2");
            }
        }
        /// <summary>
        /// Generates a web request to return a listing of all blobs in the container.
        /// </summary>
        /// <param name="uri">The absolute URI to the container.</param>
        /// <param name="timeout">The server timeout interval.</param>
        /// <param name="listingContext">A set of parameters for the listing operation.</param>
        /// <returns>A web request to use to perform the operation.</returns>
        public static StorageRequestMessage ListBlobs(Uri uri, int?timeout, BlobListingContext listingContext, HttpContent content, OperationContext operationContext, ICanonicalizer canonicalizer, StorageCredentials credentials)
        {
            UriQueryBuilder builder = ContainerHttpRequestMessageFactory.GetContainerUriQueryBuilder();

            builder.Add(Constants.QueryConstants.Component, "list");

            if (listingContext != null)
            {
                if (listingContext.Prefix != null)
                {
                    builder.Add("prefix", listingContext.Prefix);
                }

                if (listingContext.Delimiter != null)
                {
                    builder.Add("delimiter", listingContext.Delimiter);
                }

                if (listingContext.Marker != null)
                {
                    builder.Add("marker", listingContext.Marker);
                }

                if (listingContext.MaxResults.HasValue)
                {
                    builder.Add("maxresults", listingContext.MaxResults.ToString());
                }

                if (listingContext.Details != BlobListingDetails.None)
                {
                    StringBuilder sb = new StringBuilder();

                    bool started = false;

                    if ((listingContext.Details & BlobListingDetails.Snapshots) == BlobListingDetails.Snapshots)
                    {
                        if (!started)
                        {
                            started = true;
                        }
                        else
                        {
                            sb.Append(",");
                        }

                        sb.Append("snapshots");
                    }

                    if ((listingContext.Details & BlobListingDetails.UncommittedBlobs) == BlobListingDetails.UncommittedBlobs)
                    {
                        if (!started)
                        {
                            started = true;
                        }
                        else
                        {
                            sb.Append(",");
                        }

                        sb.Append("uncommittedblobs");
                    }

                    if ((listingContext.Details & BlobListingDetails.Metadata) == BlobListingDetails.Metadata)
                    {
                        if (!started)
                        {
                            started = true;
                        }
                        else
                        {
                            sb.Append(",");
                        }

                        sb.Append("metadata");
                    }

                    if ((listingContext.Details & BlobListingDetails.Copy) == BlobListingDetails.Copy)
                    {
                        if (!started)
                        {
                            started = true;
                        }
                        else
                        {
                            sb.Append(",");
                        }

                        sb.Append("copy");
                    }

                    if ((listingContext.Details & BlobListingDetails.Deleted) == BlobListingDetails.Deleted)
                    {
                        if (!started)
                        {
                            started = true;
                        }
                        else
                        {
                            sb.Append(",");
                        }

                        sb.Append("deleted");
                    }

                    builder.Add("include", sb.ToString());
                }
            }

            StorageRequestMessage request = HttpRequestMessageFactory.CreateRequestMessage(HttpMethod.Get, uri, timeout, builder, content, operationContext, canonicalizer, credentials);

            return(request);
        }
Exemplo n.º 6
0
        public static HttpRequestMessage ListBlobsRequest(BlobContext context, string containerName, BlobListingContext listingContext)
        {
            Uri uri = BlobClientTests.ConstructUri(context.Address, containerName);
            OperationContext   opContext = new OperationContext();
            HttpRequestMessage request   = ContainerHttpRequestMessageFactory.ListBlobs(uri, context.Timeout, listingContext, null,
                                                                                        opContext,
                                                                                        SharedKeyCanonicalizer.Instance,
                                                                                        context.Credentials);

            Assert.IsNotNull(request);
            Assert.IsNotNull(request.Method);
            Assert.AreEqual(HttpMethod.Get, request.Method);
            BlobTestUtils.RangeHeader(request, null);
            BlobTestUtils.LeaseIdHeader(request, null);
            return(request);
        }