コード例 #1
0
        public void GetBlob_PageBlob_GetsBlockBlobType()
        {
            var containerName = _util.GenerateSampleContainerName(_runId);
            var initialBlobName = _util.GenerateSampleBlobName(_runId);
            _util.CreateContainer(containerName);
            _util.CreatePageBlob(containerName, initialBlobName);
            IBlobServiceClient client = new BlobServiceClient(AccountSettings);

            var response = client.GetBlob(containerName, initialBlobName);

            Assert.AreEqual(Communications.Common.BlobType.Page, response.BlobType);
        }
コード例 #2
0
        public void GetBlob_ExistingBlobByValidStartAndEndRange_DownloadBlobRangeOnly()
        {
            var expectedContent = "Expected blob content";
            var containerName = _util.GenerateSampleContainerName(_runId);
            var blobName = _util.GenerateSampleBlobName(_runId);
            _util.CreateContainer(containerName);
            _util.CreateBlockBlob(containerName, blobName, content: expectedContent);
            IBlobServiceClient client = new BlobServiceClient(AccountSettings);

            var response = client.GetBlob(containerName, blobName, range: new BlobRange(2, 6));
            var data = response.GetDataBytes();

            Assert.AreEqual(expectedContent.Substring(2, 5), Encoding.UTF8.GetString(data));
        }
コード例 #3
0
        public void GetBlob_NonCopiedBlob_GetsCorrectCopyProperties()
        {
            var containerName = _util.GenerateSampleContainerName(_runId);
            var initialBlobName = _util.GenerateSampleBlobName(_runId);
            _util.CreateContainer(containerName);
            _util.CreateBlockBlob(containerName, initialBlobName);
            IBlobServiceClient client = new BlobServiceClient(AccountSettings);

            var response = client.GetBlob(containerName, initialBlobName);

            _util.AssertBlobCopyPropertiesMatch(containerName, initialBlobName, response);
        }
コード例 #4
0
        public void GetBlob_ExistingBlob_DownloadsBlobStream()
        {
            const string expectedContent = "Expected blob content";
            var containerName = _util.GenerateSampleContainerName(_runId);
            var blobName = _util.GenerateSampleBlobName(_runId);
            _util.CreateContainer(containerName);
            _util.CreateBlockBlob(containerName, blobName, content: expectedContent);
            IBlobServiceClient client = new BlobServiceClient(AccountSettings);

            var response = client.GetBlob(containerName, blobName);
            byte[] data;
            using (var stream = response.GetDataStream())
            {
                using (var ms = new MemoryStream())
                {
                    stream.CopyTo(ms);
                    data = ms.ToArray();
                }
            }

            Assert.AreEqual(expectedContent, Encoding.UTF8.GetString(data));
        }
コード例 #5
0
        public void GetBlob_NonExistentBlob_ThrowsBlobDoesNotExistException()
        {
            var containerName = _util.GenerateSampleContainerName(_runId);
            var blobName = _util.GenerateSampleBlobName(_runId);
            _util.CreateContainer(containerName);
            IBlobServiceClient client = new BlobServiceClient(AccountSettings);

            client.GetBlob(containerName, blobName);

            // expects exception
        }
コード例 #6
0
        public void GetBlob_LeasedBlobGivenInvalidLease_ThrowsArgumentException()
        {
            var containerName = _util.GenerateSampleContainerName(_runId);
            var blobName = _util.GenerateSampleBlobName(_runId);
            _util.CreateContainer(containerName);
            _util.CreateBlockBlob(containerName, blobName);
            _util.LeaseBlob(containerName, blobName);
            IBlobServiceClient client = new BlobServiceClient(AccountSettings);

            client.GetBlob(containerName, blobName, null, leaseId: InvalidLeaseId);

            // Throws exception
        }
コード例 #7
0
        public void GetBlob_LeasedBlobGivenIncorrectLease_ThrowsLeaseIdMismatchWithBlobOperationAzureException()
        {
            var containerName = _util.GenerateSampleContainerName(_runId);
            var blobName = _util.GenerateSampleBlobName(_runId);
            _util.CreateContainer(containerName);
            _util.CreateBlockBlob(containerName, blobName);
            _util.LeaseBlob(containerName, blobName);
            IBlobServiceClient client = new BlobServiceClient(AccountSettings);

            client.GetBlob(containerName, blobName, null, leaseId: GetGuidString());

            // Throws exception
        }
コード例 #8
0
        public void GetBlob_LeasedBlobWithoutLeaseSpecified_GetsBlobWithoutException()
        {
            var containerName = _util.GenerateSampleContainerName(_runId);
            var blobName = _util.GenerateSampleBlobName(_runId);
            _util.CreateContainer(containerName);
            _util.CreateBlockBlob(containerName, blobName);
            _util.LeaseBlob(containerName, blobName);
            IBlobServiceClient client = new BlobServiceClient(AccountSettings);

            var blob = client.GetBlob(containerName, blobName);

            blob = null;
            client = null;

            // no exception thrown
        }
コード例 #9
0
        public void GetBlob_ExistingBlob_DownloadsBlobBytes()
        {
            const string expectedContent = "Expected blob content";
            var containerName = _util.GenerateSampleContainerName(_runId);
            var blobName = _util.GenerateSampleBlobName(_runId);
            _util.CreateContainer(containerName);
            _util.CreateBlockBlob(containerName, blobName, content: expectedContent);
            IBlobServiceClient client = new BlobServiceClient(AccountSettings);

            var response = client.GetBlob(containerName, blobName);
            var data = response.GetDataBytes();

            Assert.AreEqual(expectedContent, Encoding.UTF8.GetString(data));
        }
コード例 #10
0
        public void GetBlob_LeasedBlobWithCorrectLeaseSpecified_GetsBlobWithoutException()
        {
            var containerName = GenerateSampleContainerName();
            var blobName = GenerateSampleBlobName();
            CreateContainer(containerName);
            CreateBlockBlob(containerName, blobName);
            var leaseId = LeaseBlob(containerName, blobName);
            IBlobServiceClient client = new BlobServiceClient(AccountSettings);

            client.GetBlob(containerName, blobName, null, leaseId);

            // no exception thrown
        }