Esempio n. 1
0
        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 HttpRequestMessage 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);
            HttpRequestMessage request   = null;
            OperationContext   opContext = new OperationContext();

            try
            {
                request = FileHttpRequestMessageFactory.Get(uri, context.Timeout, null, accessCondition, null, opContext, SharedKeyCanonicalizer.Instance, context.Credentials);
            }
            catch (InvalidOperationException)
            {
                if (valid)
                {
                    Assert.Fail();
                }
            }
            if (valid)
            {
                Assert.IsNotNull(request);
                Assert.IsNotNull(request.Method);
                Assert.AreEqual(HttpMethod.Get, request.Method);
                FileTestUtils.RangeHeader(request, null);
            }
            return(request);
        }
Esempio n. 3
0
        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 HttpRequestMessage 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);
            HttpRequestMessage request   = null;
            OperationContext   opContext = new OperationContext();

            try
            {
                using (var ms = new MemoryStream())
                {
                    request = FileHttpRequestMessageFactory.PutRange(uri, context.Timeout, range, FileRangeWrite.Update, accessCondition, new StreamContent(ms), opContext, SharedKeyCanonicalizer.Instance, context.Credentials);
                }
                //HttpRequestHandler.SetContentLength(request, length);
            }
            catch (InvalidOperationException)
            {
                if (valid)
                {
                    Assert.Fail();
                }
            }
            if (valid)
            {
                Assert.IsNotNull(request);
                Assert.IsNotNull(request.Method);
                Assert.AreEqual(HttpMethod.Put, request.Method);
                FileTestUtils.RangeHeader(request, range.StartOffset, range.EndOffset);
            }
            return(request);
        }
Esempio n. 5
0
        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);
        }