Example #1
0
        public async Task ListFilesAndDirectoriesScenarioTest(string shareName, FileListingContext listingContext, HttpStatusCode?expectedError, params string[] expectedFiles)
        {
            HttpRequestMessage request = FileTests.ListFilesAndDirectoriesRequest(FileContext, shareName, listingContext);

            Assert.IsTrue(request != null, "Failed to create HttpRequestMessage");
            HttpResponseMessage response = await FileTestUtils.GetResponse(request, FileContext);

            try
            {
                FileTests.ListFilesAndDirectoriesResponse(response, FileContext, expectedError);
                ListFilesAndDirectoriesResponse listFilesResponse = await ListFilesAndDirectoriesResponse.ParseAsync(await response.Content.ReadAsStreamAsync(), CancellationToken.None);

                int i = 0;
                foreach (IListFileEntry item in listFilesResponse.Files)
                {
                    ListFileEntry file = item as ListFileEntry;
                    if (expectedFiles == null)
                    {
                        Assert.Fail("Should not have files.");
                    }
                    Assert.IsTrue(i < expectedFiles.Length, "Unexpected file: " + file.Name);
                    Assert.AreEqual <string>(expectedFiles[i++], file.Name, "Incorrect file.");
                }
                if (expectedFiles != null && i < expectedFiles.Length)
                {
                    Assert.Fail("Missing file: " + expectedFiles[i] + "(and " + (expectedFiles.Length - i - 1) + " more).");
                }
            }
            finally
            {
                response.Dispose();
            }
        }
Example #2
0
        public static HttpRequestMessage ListFilesAndDirectoriesRequest(FileContext context, string shareName, FileListingContext listingContext)
        {
            Uri uri = FileClientTests.ConstructUri(context.Address, shareName);
            OperationContext   opContext = new OperationContext();
            HttpRequestMessage request   = DirectoryHttpRequestMessageFactory.List(uri, context.Timeout, null, listingContext, null, opContext, SharedKeyCanonicalizer.Instance, context.Credentials);

            Assert.IsNotNull(request);
            Assert.IsNotNull(request.Method);
            Assert.AreEqual(HttpMethod.Get, request.Method);
            FileTestUtils.RangeHeader(request, null);
            return(request);
        }
Example #3
0
        /// <summary>
        /// Generates a web request to return a listing of all files and subdirectories in the directory.
        /// </summary>
        /// <param name="uri">The absolute URI to the share.</param>
        /// <param name="timeout">The server timeout interval.</param>
        /// <param name="shareSnapshot">A <see cref="DateTimeOffset"/> specifying the share snapshot timestamp, if the share is a snapshot.</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 List(Uri uri, int?timeout, DateTimeOffset?shareSnapshot, FileListingContext listingContext, HttpContent content, OperationContext operationContext, ICanonicalizer canonicalizer, StorageCredentials credentials)
        {
            UriQueryBuilder directoryBuilder = GetDirectoryUriQueryBuilder();

            DirectoryHttpRequestMessageFactory.AddShareSnapshot(directoryBuilder, shareSnapshot);
            directoryBuilder.Add(Constants.QueryConstants.Component, "list");

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

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

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

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

            return(request);
        }