Exemple #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();
            }
        }
        public void ListFilesAndDirectoriesScenarioTest(string shareName, FileListingContext listingContext, HttpStatusCode?expectedError, params string[] expectedFiles)
        {
            HttpWebRequest request = FileTests.ListFilesAndDirectoriesRequest(FileContext, shareName, listingContext);

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

            try
            {
                FileTests.ListFilesAndDirectoriesResponse(response, FileContext, expectedError);
                ListFilesAndDirectoriesResponse listFilesResponse = new ListFilesAndDirectoriesResponse(response.GetResponseStream());
                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.Close();
            }
        }