public void PutBlockBlobIntelligently_DefaultArgsOnly_CreatesBlockBlob()
        {
            var expectedData = Encoding.UTF8.GetBytes("test data");
            var containerName = GenerateSampleContainerName();
            var blobName = GenerateSampleBlobName();
            IBlobServiceClientEx client = new BlobServiceClientEx(AccountSettings);
            CreateContainer(containerName);

            // Tempt it to do it in two uploads by specifying half megabyte
            client.PutBlockBlobIntelligently(expectedData.Length - 5, containerName, blobName, expectedData);

            AssertBlobExists(containerName, blobName, BlobType.BlockBlob);
            AssertBlockBlobContainsData(containerName, blobName, expectedData);
        }
        public void PutBlockBlobIntelligently_DataSmallerThanMaxSingleUploadSize_CreatesBlockBlobWithOneUpload()
        {
            var expectedData = Encoding.UTF8.GetBytes("test data");
            var expectedDataLength = expectedData.Length;
            var containerName = GenerateSampleContainerName();
            var blobName = GenerateSampleBlobName();
            IBlobServiceClientEx client = new BlobServiceClientEx(AccountSettings);
            CreateContainer(containerName);

            // Tempt it to do it in two uploads by specifying a blocksize smaller than the data length
            var response = client.PutBlockBlobIntelligently(expectedDataLength - 5, containerName, blobName, expectedData);

            AssertBlobOfSingleUpload(expectedData, containerName, blobName);
            AssertIsPutBlockBlobResponse(response);
        }
        public void PutBlockBlobIntelligently_SingleUploadWithMetadata_CorrectMetadata()
        {
            var expectedData = new byte[1024];
            var expectedMetadata = new Dictionary<string, string>
            {
                {"haikuLine1", "I dreamed I was in"},
                {"haikuLine2", "A long-running endless loop"},
                {"haikuLine3", "And then the next day"}
            };
            var containerName = GenerateSampleContainerName();
            var blobName = GenerateSampleBlobName();
            IBlobServiceClientEx client = new BlobServiceClientEx(AccountSettings);
            CreateContainer(containerName);

            client.PutBlockBlobIntelligently(BlobServiceConstants.MaxSingleBlockUploadSize, containerName, blobName, expectedData,
                metadata: expectedMetadata);

            var metadata = GetBlobMetadata(containerName, blobName);
            AssertBlobOfSingleUpload(expectedData, containerName, blobName);
            Assert.AreEqual(expectedMetadata, metadata);
        }
        public void PutBlockBlobIntelligently_SingleUploadWithCacheControl_CorrectContentCacheControl()
        {
            var expectedData = new byte[1024];
            const string expectedCacheControl = "ponyfoo";
            var containerName = GenerateSampleContainerName();
            var blobName = GenerateSampleBlobName();
            IBlobServiceClientEx client = new BlobServiceClientEx(AccountSettings);
            CreateContainer(containerName);

            client.PutBlockBlobIntelligently(BlobServiceConstants.MaxSingleBlockUploadSize, containerName, blobName, expectedData,
                cacheControl: expectedCacheControl);

            var properties = GetBlobProperties(containerName, blobName);
            AssertBlobOfSingleUpload(expectedData, containerName, blobName);
            Assert.AreEqual(expectedCacheControl, properties.CacheControl);
        }
        public void PutBlockBlobIntelligently_SingleUploadWithContentMD5_CorrectContentMD5()
        {
            var expectedData = new byte[1024];
            var expectedContentMD5 = Convert.ToBase64String(MD5.Create().ComputeHash(expectedData));
            var containerName = GenerateSampleContainerName();
            var blobName = GenerateSampleBlobName();
            IBlobServiceClientEx client = new BlobServiceClientEx(AccountSettings);
            CreateContainer(containerName);

            client.PutBlockBlobIntelligently(BlobServiceConstants.MaxSingleBlockUploadSize, containerName, blobName, expectedData,
                contentMD5: expectedContentMD5);

            var properties = GetBlobProperties(containerName, blobName);
            AssertBlobOfSingleUpload(expectedData, containerName, blobName);
            Assert.AreEqual(expectedContentMD5, properties.ContentMD5);
        }
        public void PutBlockBlobIntelligently_SingleUploadWithContentEncoding_CorrectContentEncoding()
        {
            const string expectedContentEncoding = "UTF8";
            var expectedData = new byte[1024];
            var containerName = GenerateSampleContainerName();
            var blobName = GenerateSampleBlobName();
            IBlobServiceClientEx client = new BlobServiceClientEx(AccountSettings);
            CreateContainer(containerName);

            client.PutBlockBlobIntelligently(BlobServiceConstants.MaxSingleBlockUploadSize, containerName, blobName, expectedData,
                contentEncoding: expectedContentEncoding);

            var properties = GetBlobProperties(containerName, blobName);
            AssertBlobOfSingleUpload(expectedData, containerName, blobName);
            Assert.AreEqual(expectedContentEncoding, properties.ContentEncoding);
        }
        public void PutBlockBlobIntelligently_MultipleUploadsWithContentLanguage_CorrectContentLanguage()
        {
            const string expectedContentLanguage = "ancient/yiddish";
            var expectedData = new byte[MaxIntelligentSingleBlobUploadSizeOverride + 5];
            var containerName = GenerateSampleContainerName();
            var blobName = GenerateSampleBlobName();
            IBlobServiceClientEx client = new BlobServiceClientEx(AccountSettings, MaxIntelligentSingleBlobUploadSizeOverride);
            CreateContainer(containerName);

            client.PutBlockBlobIntelligently(BlobServiceConstants.MaxSingleBlockUploadSize, containerName, blobName, expectedData,
                contentLanguage: expectedContentLanguage);

            var properties = GetBlobProperties(containerName, blobName);
            AssertBlobOfMultipleUploads(expectedData, containerName, blobName);
            Assert.AreEqual(expectedContentLanguage, properties.ContentLanguage);
        }
        public void PutBlockBlobIntelligently_DataLargerThanMaxSingleUploadSize_CreatesBlockBlobWithMultipleUploads()
        {
            var expectedData = new byte[MaxIntelligentSingleBlobUploadSizeOverride + 5];
            var containerName = GenerateSampleContainerName();
            var blobName = GenerateSampleBlobName();
            IBlobServiceClientEx client = new BlobServiceClientEx(AccountSettings, MaxIntelligentSingleBlobUploadSizeOverride);
            CreateContainer(containerName);

            var response = client.PutBlockBlobIntelligently(BlobServiceConstants.MaxSingleBlockUploadSize, containerName, blobName, expectedData);

            AssertBlobOfMultipleUploads(expectedData, containerName, blobName);
            AssertIsBlockListResponse(response);
        }
        public void PutBlockBlobIntelligently_MultipleUploadsWithCacheControl_CorrectContentCacheControl()
        {
            var expectedData = new byte[MaxIntelligentSingleBlobUploadSizeOverride + 5];
            const string expectedCacheControl = "ponyfoo";
            var containerName = _util.GenerateSampleContainerName(_runId);
            var blobName = _util.GenerateSampleBlobName(_runId);
            IBlobServiceClientEx client = new BlobServiceClientEx(AccountSettings, MaxIntelligentSingleBlobUploadSizeOverride);
            _util.CreateContainer(containerName);

            client.PutBlockBlobIntelligently(BlobServiceConstants.MaxSingleBlockUploadSize, containerName, blobName, expectedData,
                cacheControl: expectedCacheControl);

            var properties = _util.GetBlobProperties(containerName, blobName);
            _util.AssertBlobOfMultipleUploads(expectedData, containerName, blobName, MaxIntelligentSingleBlobUploadSizeOverride);
            Assert.AreEqual(expectedCacheControl, properties.CacheControl);
        }
        public void PutBlockBlobIntelligently_MultipleUploadsWithContentMD5_CorrectContentMD5()
        {
            var expectedData = new byte[MaxIntelligentSingleBlobUploadSizeOverride + 5];
            var expectedContentMD5 = Convert.ToBase64String(MD5.Create().ComputeHash(expectedData));
            var containerName = _util.GenerateSampleContainerName(_runId);
            var blobName = _util.GenerateSampleBlobName(_runId);
            IBlobServiceClientEx client = new BlobServiceClientEx(AccountSettings, MaxIntelligentSingleBlobUploadSizeOverride);
            _util.CreateContainer(containerName);

            client.PutBlockBlobIntelligently(BlobServiceConstants.MaxSingleBlockUploadSize, containerName, blobName, expectedData,
                contentMD5: expectedContentMD5);

            var properties = _util.GetBlobProperties(containerName, blobName);
            _util.AssertBlobOfMultipleUploads(expectedData, containerName, blobName, MaxIntelligentSingleBlobUploadSizeOverride);
            Assert.AreEqual(expectedContentMD5, properties.ContentMD5);
        }
        public void PutBlockBlobIntelligently_SingleUploadWithContentType_CorrectContentTypeSet()
        {
            const string expectedContentType = "foo/bar";
            var expectedData = new byte[1024];
            var containerName = _util.GenerateSampleContainerName(_runId);
            var blobName = _util.GenerateSampleBlobName(_runId);
            IBlobServiceClientEx client = new BlobServiceClientEx(AccountSettings);
            _util.CreateContainer(containerName);

            client.PutBlockBlobIntelligently(BlobServiceConstants.MaxSingleBlockUploadSize, containerName, blobName, expectedData,
                contentType: expectedContentType);

            var properties = _util.GetBlobProperties(containerName, blobName);
            _util.AssertBlobOfSingleUpload(expectedData, containerName, blobName, MaxIntelligentSingleBlobUploadSizeOverride);
            Assert.AreEqual(expectedContentType, properties.ContentType);
        }