Example #1
0
        public static HttpRequestMessage 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);
            HttpRequestMessage request   = null;
            OperationContext   opContext = new OperationContext();

            try
            {
                request = FileHttpRequestMessageFactory.Create(uri, context.Timeout, properties, null, fileSize, 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.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);
        }