Exemple #1
0
        public async Task FileProtocolGetShareWithEmptyHeader()
        {
            ListingContext listingContext = new ListingContext("default", null);
            await cloudOwnerAsync.CreateShare("emptyheadershare1");

            HttpRequestMessage request = FileTests.ListSharesRequest(cloudOwnerAsync.FileContext, listingContext);

            Assert.IsTrue(request != null, "Failed to create HttpRequestMessage");
            if (cloudOwnerAsync.FileContext.Credentials != null)
            {
                request.Headers.Add("x-ms-file-application-metadata", "");
            }
            using (HttpResponseMessage response = await FileTestUtils.GetResponse(request, cloudOwnerAsync.FileContext))
            {
                FileTests.ListSharesResponse(response, cloudOwnerAsync.FileContext, null);
            }

            request = FileTests.ListSharesRequest(cloudOwnerAsync.FileContext, listingContext);
            Assert.IsTrue(request != null, "Failed to create HttpRequestMessage");
            if (cloudOwnerAsync.FileContext.Credentials != null)
            {
                request.Headers.Add("x-ms-file-application-metadata", "");
            }
            using (HttpResponseMessage response = await FileTestUtils.GetResponse(request, cloudOwnerAsync.FileContext))
            {
                FileTests.ListSharesResponse(response, cloudOwnerAsync.FileContext, HttpStatusCode.OK);
            }
        }
        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();
            }
        }
Exemple #3
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();
            }
        }