public void ListSharesScenarioTest(ListingContext listingContext, HttpStatusCode?expectedError, params string[] expectedShares)
        {
            HttpWebRequest request = FileTests.ListSharesRequest(FileContext, 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.ListSharesResponse(response, FileContext, expectedError);
                ListSharesResponse listSharesResponse = new ListSharesResponse(response.GetResponseStream());
                int i = 0;
                foreach (FileShareEntry item in listSharesResponse.Shares)
                {
                    if (expectedShares == null)
                    {
                        Assert.Fail("Should not have shares.");
                    }
                    Assert.IsTrue(i < expectedShares.Length, "Unexpected share: " + item.Name);
                    Assert.AreEqual <string>(expectedShares[i++], item.Name, "Incorrect share.");
                }
                if (expectedShares != null && i < expectedShares.Length)
                {
                    Assert.Fail("Missing share: " + expectedShares[i] + "(and " + (expectedShares.Length - i - 1) + " more).");
                }
            }
            finally
            {
                response.Close();
            }
        }
Esempio n. 2
0
        public async Task ListSharesScenarioTest(ListingContext listingContext, HttpStatusCode?expectedError, params string[] expectedShares)
        {
            HttpRequestMessage request = FileTests.ListSharesRequest(FileContext, listingContext);

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

            HttpResponseMessage response = await FileTestUtils.GetResponse(request, FileContext);

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

                int i = 0;
                foreach (FileShareEntry item in listSharesResponse.Shares)
                {
                    if (expectedShares == null)
                    {
                        Assert.Fail("Should not have shares.");
                    }
                    Assert.IsTrue(i < expectedShares.Length, "Unexpected share: " + item.Name);
                    Assert.AreEqual <string>(expectedShares[i++], item.Name, "Incorrect share.");
                }
                if (expectedShares != null && i < expectedShares.Length)
                {
                    Assert.Fail("Missing share: " + expectedShares[i] + "(and " + (expectedShares.Length - i - 1) + " more).");
                }
            }
            finally
            {
                response.Dispose();
            }
        }