public static HttpWebRequest ListFilesAndDirectoriesRequest(FileContext context, string shareName, FileListingContext listingContext) { Uri uri = FileClientTests.ConstructUri(context.Address, shareName); OperationContext opContext = new OperationContext(); HttpWebRequest request = DirectoryHttpWebRequestFactory.List(uri, context.Timeout, listingContext, null, true, opContext); Assert.IsNotNull(request); Assert.IsNotNull(request.Method); Assert.AreEqual("GET", request.Method); FileTestUtils.RangeHeader(request, null); return(request); }
public static HttpWebRequest ListSharesRequest(FileContext context, ListingContext listingContext) { Uri uri = FileClientTests.ConstructUri(context.Address); OperationContext opContext = new OperationContext(); HttpWebRequest request = ShareHttpWebRequestFactory.List(uri, context.Timeout, listingContext, ShareListingDetails.Metadata, true, opContext); Assert.IsNotNull(request); Assert.IsNotNull(request.Method); Assert.AreEqual("GET", request.Method); FileTestUtils.RangeHeader(request, null); return(request); }
public static HttpWebRequest DeleteFileRequest(FileContext context, string shareName, string fileName, AccessCondition accessCondition) { Uri uri = FileClientTests.ConstructUri(context.Address, shareName, fileName); OperationContext opContext = new OperationContext(); HttpWebRequest request = FileHttpWebRequestFactory.Delete(uri, context.Timeout, accessCondition, true, opContext); Assert.IsNotNull(request); Assert.IsNotNull(request.Method); Assert.AreEqual("DELETE", request.Method); FileTestUtils.RangeHeader(request, null); return(request); }
public async Task DeleteShare(string shareName) { HttpRequestMessage request = FileTests.DeleteShareRequest(FileContext, shareName, null); Assert.IsTrue(request != null, "Failed to create HttpRequestMessage"); HttpResponseMessage response = await FileTestUtils.GetResponse(request, FileContext); HttpStatusCode statusCode = response.StatusCode; string statusDescription = response.ReasonPhrase; response.Dispose(); }
public static HttpRequestMessage ListSharesRequest(FileContext context, ListingContext listingContext) { Uri uri = FileClientTests.ConstructUri(context.Address); OperationContext opContext = new OperationContext(); HttpRequestMessage request = ShareHttpRequestMessageFactory.List(uri, context.Timeout, listingContext, ShareListingDetails.Metadata, 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); }
public static HttpRequestMessage DeleteFileRequest(FileContext context, string shareName, string fileName, AccessCondition accessCondition) { Uri uri = FileClientTests.ConstructUri(context.Address, shareName, fileName); OperationContext opContext = new OperationContext(); HttpRequestMessage request = FileHttpRequestMessageFactory.Delete(uri, context.Timeout, accessCondition, null, opContext, SharedKeyCanonicalizer.Instance, context.Credentials); Assert.IsNotNull(request); Assert.IsNotNull(request.Method); Assert.AreEqual(HttpMethod.Delete, request.Method); FileTestUtils.RangeHeader(request, null); return(request); }
public static void SetRequest(HttpWebRequest request, FileContext context, byte[] content) { Assert.IsNotNull(request); if (context.Async) { FileTestUtils.SetRequestAsync(request, context, content); } else { FileTestUtils.SetRequestSync(request, context, content); } }
public static HttpWebRequest CreateShareRequest(FileContext context, string shareName) { Uri uri = FileClientTests.ConstructUri(context.Address, shareName); OperationContext opContext = new OperationContext(); HttpWebRequest request = ShareHttpWebRequestFactory.Create(uri, context.Timeout, true, opContext); Assert.IsNotNull(request); Assert.IsNotNull(request.Method); Assert.AreEqual("PUT", request.Method); FileTestUtils.RangeHeader(request, null); FileTestUtils.VersionHeader(request, false); return(request); }
public void DeleteFile(string shareName, string fileName) { HttpWebRequest request = FileTests.DeleteFileRequest(FileContext, shareName, fileName, null); Assert.IsTrue(request != null, "Failed to create HttpWebRequest"); if (FileContext.Credentials != null) { FileTests.SignRequest(request, FileContext); } HttpWebResponse response = FileTestUtils.GetResponse(request, FileContext); response.Close(); }
public static HttpRequestMessage CreateShareRequest(FileContext context, string shareName) { Uri uri = FileClientTests.ConstructUri(context.Address, shareName); OperationContext opContext = new OperationContext(); HttpRequestMessage request = ShareHttpRequestMessageFactory.Create(uri, null, context.Timeout, null, opContext, SharedKeyCanonicalizer.Instance, context.Credentials); Assert.IsNotNull(request); Assert.IsNotNull(request.Method); Assert.AreEqual(HttpMethod.Put, request.Method); FileTestUtils.RangeHeader(request, null); FileTestUtils.VersionHeader(request, false); return(request); }
public static void ListSharesResponse(HttpWebResponse response, FileContext context, HttpStatusCode?expectedError) { Assert.IsNotNull(response); if (expectedError == null) { Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, response.StatusDescription); FileTestUtils.ContentTypeHeader(response, "application/xml"); FileTestUtils.RequestIdHeader(response); } else { Assert.AreEqual(expectedError, response.StatusCode, response.StatusDescription); } }
public static void ListFilesAndDirectoriesResponse(HttpResponseMessage response, FileContext context, HttpStatusCode?expectedError) { Assert.IsNotNull(response); if (expectedError == null) { Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, response.ReasonPhrase); FileTestUtils.ContentTypeHeader(response, "application/xml"); FileTestUtils.RequestIdHeader(response); } else { Assert.AreEqual(expectedError, response.StatusCode, response.ReasonPhrase); } }
public void DeleteShare(string shareName) { HttpWebRequest request = FileTests.DeleteShareRequest(FileContext, shareName, null); Assert.IsTrue(request != null, "Failed to create HttpWebRequest"); if (FileContext.Credentials != null) { FileTests.SignRequest(request, FileContext); } HttpWebResponse response = FileTestUtils.GetResponse(request, FileContext); HttpStatusCode statusCode = response.StatusCode; string statusDescription = response.StatusDescription; response.Close(); }
public static void WriteRangeResponse(HttpResponseMessage response, FileContext context, HttpStatusCode?expectedError) { Assert.IsNotNull(response); if (expectedError == null) { Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); FileTestUtils.LastModifiedHeader(response); FileTestUtils.ETagHeader(response); FileTestUtils.RequestIdHeader(response); } else { Assert.AreEqual(expectedError, response.StatusCode, response.ReasonPhrase); } response.Dispose(); }
public static void PutFileResponse(HttpWebResponse response, FileContext context, HttpStatusCode?expectedError) { Assert.IsNotNull(response); if (expectedError == null) { Assert.AreEqual(HttpStatusCode.Created, response.StatusCode, response.StatusDescription); FileTestUtils.ETagHeader(response); FileTestUtils.LastModifiedHeader(response); FileTestUtils.RequestIdHeader(response); } else { Assert.AreEqual(expectedError, response.StatusCode, response.StatusDescription); } response.Close(); }
public static void SignRequest(HttpWebRequest request, FileContext context) { Assert.IsNotNull(request); Assert.IsNotNull(context); OperationContext opContext = new OperationContext(); SharedKeyAuthenticationHandler handler = new SharedKeyAuthenticationHandler( SharedKeyCanonicalizer.Instance, context.Credentials, context.Account); handler.SignRequest(request, opContext); FileTestUtils.AuthorizationHeader(request, true, context.Account); FileTestUtils.DateHeader(request, true); }
public async Task GetFileScenarioTest(string shareName, string fileName, FileProperties properties, HttpStatusCode?expectedError) { HttpRequestMessage request = FileTests.GetFileRequest(FileContext, shareName, fileName, null); Assert.IsTrue(request != null, "Failed to create HttpRequestMessage"); HttpResponseMessage response = await FileTestUtils.GetResponse(request, FileContext); try { FileTests.GetFileResponse(response, FileContext, properties, expectedError); } finally { response.Dispose(); } }
public async Task WriteRange(string fileName, string shareName, byte[] content, HttpStatusCode?expectedError) { FileRange range = new FileRange(0, content.Length - 1); HttpRequestMessage request = FileTests.WriteRangeRequest(FileContext, shareName, fileName, range, content.Length, null); Assert.IsTrue(request != null, "Failed to create HttpRequestMessage"); request.Content = new ByteArrayContent(content); HttpResponseMessage response = await FileTestUtils.GetResponse(request, FileContext); try { FileTests.WriteRangeResponse(response, FileContext, expectedError); } finally { response.Dispose(); } }
public async Task PutFileScenarioTest(string shareName, string fileName, FileProperties properties, byte[] content, HttpStatusCode?expectedError) { HttpRequestMessage request = FileTests.PutFileRequest(FileContext, shareName, fileName, properties, content, content.Length, null); request.Content = new ByteArrayContent(content); Assert.IsTrue(request != null, "Failed to create HttpRequestMessage"); //HttpRequestHandler.SetContentLength(request, content.Length); HttpResponseMessage response = await FileTestUtils.GetResponse(request, FileContext); try { FileTests.PutFileResponse(response, FileContext, expectedError); } finally { response.Dispose(); } }
public async Task CreateFile(string shareName, string fileName, bool isPublic) { Properties = new FileProperties(); HttpRequestMessage request = FileTests.PutFileRequest(FileContext, shareName, fileName, Properties, Content, 7000, null); Assert.IsTrue(request != null, "Failed to create HttpRequestMessage"); CancellationTokenSource timeout = new CancellationTokenSource(30000); HttpResponseMessage response = await FileTestUtils.GetResponse(request, FileContext, timeout); HttpStatusCode statusCode = response.StatusCode; string statusDescription = response.ReasonPhrase; response.Dispose(); if (statusCode != HttpStatusCode.Created) { Assert.Fail(string.Format("Failed to create file: {0}, Status: {1}, Status Description: {2}", shareName, statusCode, statusDescription)); } }
public void GetFileScenarioTest(string shareName, string fileName, FileProperties properties, HttpStatusCode?expectedError) { HttpWebRequest request = FileTests.GetFileRequest(FileContext, shareName, fileName, null); Assert.IsTrue(request != null, "Failed to create HttpWebRequest"); if (FileContext.Credentials != null) { FileTests.SignRequest(request, FileContext); } HttpWebResponse response = FileTestUtils.GetResponse(request, FileContext); try { FileTests.GetFileResponse(response, FileContext, properties, expectedError); } finally { response.Close(); } }
public void WriteRange(string fileName, string shareName, byte[] content, HttpStatusCode?expectedError) { FileRange range = new FileRange(0, content.Length - 1); HttpWebRequest request = FileTests.WriteRangeRequest(FileContext, shareName, fileName, range, content.Length, null); Assert.IsTrue(request != null, "Failed to create HttpWebRequest"); if (FileContext.Credentials != null) { FileTests.SignRequest(request, FileContext); } FileTestUtils.SetRequest(request, FileContext, content); HttpWebResponse response = FileTestUtils.GetResponse(request, FileContext); try { FileTests.WriteRangeResponse(response, FileContext, expectedError); } finally { response.Close(); } }
public static HttpWebRequest PutFileRequest(FileContext context, string shareName, string fileName, FileProperties properties, byte[] content, long fileSize, AccessCondition accessCondition) { bool valid = FileTests.ShareNameValidator(shareName) && FileTests.FileNameValidator(fileName) && FileTestUtils.ContentValidator(content); Uri uri = FileTests.ConstructPutUri(context.Address, shareName, fileName); HttpWebRequest request = null; OperationContext opContext = new OperationContext(); try { request = FileHttpWebRequestFactory.Create(uri, context.Timeout, properties, fileSize, accessCondition, true, opContext); } catch (InvalidOperationException) { if (valid) { Assert.Fail(); } } if (valid) { Assert.IsNotNull(request); Assert.IsNotNull(request.Method); Assert.AreEqual("PUT", request.Method); FileTestUtils.VersionHeader(request, false); FileTestUtils.ContentTypeHeader(request, null); FileTestUtils.ContentDispositionHeader(request, properties.ContentDisposition); FileTestUtils.ContentEncodingHeader(request, properties.ContentEncoding); FileTestUtils.ContentLanguageHeader(request, null); FileTestUtils.CacheControlHeader(request, null); FileTestUtils.FileTypeHeader(request, "File"); FileTestUtils.FileSizeHeader(request, properties.Length); } return(request); }
public void CreateFile(string shareName, string fileName, bool isPublic) { Properties = new FileProperties(); HttpWebRequest request = FileTests.PutFileRequest(FileContext, shareName, fileName, Properties, Content, 7000, null); Assert.IsTrue(request != null, "Failed to create HttpWebRequest"); request.Timeout = 30000; if (FileContext.Credentials != null) { FileTests.SignRequest(request, FileContext); } HttpWebResponse response = FileTestUtils.GetResponse(request, FileContext); HttpStatusCode statusCode = response.StatusCode; string statusDescription = response.StatusDescription; response.Close(); if (statusCode != HttpStatusCode.Created) { Assert.Fail(string.Format("Failed to create file: {0}, Status: {1}, Status Description: {2}", shareName, statusCode, statusDescription)); } }
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(); } }
public async Task ClearRangeScenarioTest(string shareName, string fileName, HttpStatusCode?expectedError) { // 1. Create Sparse File int fileSize = 128 * 1024; FileProperties properties = new FileProperties(); Uri uri = FileTests.ConstructPutUri(FileContext.Address, shareName, fileName); OperationContext opContext = new OperationContext(); HttpRequestMessage webRequest = FileHttpRequestMessageFactory.Create(uri, FileContext.Timeout, properties, fileSize, null, null, opContext, null, null); using (HttpResponseMessage response = await FileTestUtils.GetResponse(webRequest, FileContext)) { FileTests.PutFileResponse(response, FileContext, expectedError); } // 2. Now upload some ranges for (int m = 0; m * 512 * 4 < fileSize; m++) { int startOffset = 512 * 4 * m; int length = 512; FileRange range = new FileRange(startOffset, startOffset + length - 1); opContext = new OperationContext(); HttpRequestMessage rangeRequest = FileHttpRequestMessageFactory.PutRange(uri, FileContext.Timeout, range, FileRangeWrite.Update, null, null, opContext, null, null); HttpRequestHandler.SetContentLength(rangeRequest, 512); byte[] content = new byte[length]; random.NextBytes(content); rangeRequest.Content = new ByteArrayContent(content); using (HttpResponseMessage rangeResponse = await FileTestUtils.GetResponse(rangeRequest, FileContext)) { } } // 3. Now do a List Ranges List <FileRange> fileRanges = new List <FileRange>(); opContext = new OperationContext(); HttpRequestMessage listRangesRequest = FileHttpRequestMessageFactory.ListRanges(uri, FileContext.Timeout, null, null, null, null, null, opContext, null, null); using (HttpResponseMessage rangeResponse = await FileTestUtils.GetResponse(listRangesRequest, FileContext)) { var ranges = await ListRangesResponse.ParseAsync(await rangeResponse.Content.ReadAsStreamAsync(), CancellationToken.None); fileRanges.AddRange(ranges); } // 4. Now Clear some ranges bool skipFlag = false; foreach (FileRange pRange in fileRanges) { skipFlag = !skipFlag; if (skipFlag) { continue; } opContext = new OperationContext(); HttpRequestMessage clearRangeRequest = FileHttpRequestMessageFactory.PutRange(uri, FileContext.Timeout, pRange, FileRangeWrite.Clear, null, null, opContext, null, null); HttpRequestHandler.SetContentLength(clearRangeRequest, 0); using (HttpResponseMessage clearResponse = await FileTestUtils.GetResponse(clearRangeRequest, FileContext)) { } } // 5. Get New ranges and verify List <FileRange> newFileRanges = new List <FileRange>(); opContext = new OperationContext(); HttpRequestMessage newFileRangeRequest = FileHttpRequestMessageFactory.ListRanges(uri, FileContext.Timeout, null, null, null, null, null, opContext, null, null); using (HttpResponseMessage newFileRangeResponse = await FileTestUtils.GetResponse(newFileRangeRequest, FileContext)) { var ranges = await ListRangesResponse.ParseAsync(await newFileRangeResponse.Content.ReadAsStreamAsync(), CancellationToken.None); newFileRanges.AddRange(ranges); } Assert.AreEqual(fileRanges.Count(), newFileRanges.Count() * 2); for (int l = 0; l < newFileRanges.Count(); l++) { Assert.AreEqual(fileRanges[2 * l].StartOffset, newFileRanges[l].StartOffset); Assert.AreEqual(fileRanges[2 * l].EndOffset, newFileRanges[l].EndOffset); } }