public static HttpWebRequest GetFileRequest(FileContext context, string shareName, string fileName, AccessCondition accessCondition) { bool valid = FileTests.ShareNameValidator(shareName) && FileTests.FileNameValidator(fileName); Uri uri = FileTests.ConstructGetUri(context.Address, shareName, fileName); HttpWebRequest request = null; OperationContext opContext = new OperationContext(); try { request = FileHttpWebRequestFactory.Get(uri, context.Timeout, accessCondition, true, opContext); } catch (InvalidOperationException) { if (valid) { Assert.Fail(); } } if (valid) { Assert.IsNotNull(request); Assert.IsNotNull(request.Method); Assert.AreEqual("GET", request.Method); FileTestUtils.RangeHeader(request, null); } return request; }
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 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 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 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 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 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, 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 FileClientTests(bool owner, bool async, int timeout) { FileContext = new FileContext(owner, async, timeout); }
/// <summary> /// Checks a get file range response for consistency with the given parameters, and closes the response. /// </summary> /// <param name="response">The HTTP web response to check.</param> /// <param name="context">The testing context.</param> /// <param name="content">The expected content returned in the response.</param> /// <param name="expectedStartRange">The expected start range returned in the response header.</param> /// <param name="expectedEndRange">The expected end range returned in the response header.</param> /// <param name="expectedTotalBytes">The expected total number of bytes in the file.</param> /// <param name="expectedError">The expected error code, or null if the operation is expected to succeed.</param> public static void CheckFileRangeResponse( HttpWebResponse response, FileContext context, byte[] content, long expectedStartRange, long expectedEndRange, long expectedTotalBytes, HttpStatusCode? expectedError) { Assert.IsNotNull(response); if (expectedError == null) { Assert.AreEqual(HttpStatusCode.PartialContent, response.StatusCode); Assert.IsNotNull(content); FileTestUtils.LastModifiedHeader(response); FileTestUtils.ContentLengthHeader(response, content.Length); FileTestUtils.ETagHeader(response); FileTestUtils.RequestIdHeader(response); FileTestUtils.Contents(response, content); FileTestUtils.ContentRangeHeader(response, expectedStartRange, expectedEndRange, expectedTotalBytes); } else { Assert.AreEqual(expectedError, response.StatusCode, response.StatusDescription); } response.Close(); }
public static HttpWebRequest WriteRangeRequest(FileContext context, string shareName, string fileName, FileRange range, int length, AccessCondition accessCondition) { bool valid = FileTests.ShareNameValidator(shareName) && FileTests.FileNameValidator(fileName); Uri uri = FileTests.ConstructPutUri(context.Address, shareName, fileName); HttpWebRequest request = null; OperationContext opContext = new OperationContext(); try { request = FileHttpWebRequestFactory.PutRange(uri, context.Timeout, range, FileRangeWrite.Update, accessCondition, true, opContext); request.ContentLength = length; } catch (InvalidOperationException) { if (valid) { Assert.Fail(); } } if (valid) { Assert.IsNotNull(request); Assert.IsNotNull(request.Method); Assert.AreEqual("PUT", request.Method); FileTestUtils.RangeHeader(request, range.StartOffset, range.EndOffset); } return request; }
public static HttpWebResponse GetResponse(HttpWebRequest request, FileContext context) { Assert.IsNotNull(request); HttpWebResponse response = null; try { response = (HttpWebResponse)request.GetResponse(); } catch (WebException ex) { response = (HttpWebResponse)ex.Response; } Assert.IsNotNull(response); return response; }
static void SetRequestSync(HttpWebRequest request, FileContext context, byte[] content) { Stream stream = request.GetRequestStream(); Assert.IsNotNull(stream); stream.Write(content, 0, content.Length); stream.Close(); }
static void SetRequestAsync(HttpWebRequest request, FileContext context, byte[] content) { request.BeginGetRequestStream(new AsyncCallback(FileTestUtils.ReadCallback), request); setRequestAsyncSem.WaitOne(); }
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 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); } }