public void GetBlobProperties_ExistingBlob_HasAnETag()
        {
            var containerName = _util.GenerateSampleContainerName(_runId);
            var blobName = _util.GenerateSampleBlobName(_runId);
            _util.CreateContainer(containerName);
            _util.CreateBlockBlob(containerName, blobName);
            IBlobServiceClient client = new BlobServiceClient(AccountSettings);

            var properties = client.GetBlobProperties(containerName, blobName);

            Assert.IsNotNullOrEmpty(properties.ETag);
        }
        public void GetBlobProperties_ExistingBlob_GetsCorrectContentLength()
        {
            const string blobContents = "foo";
            var expectedContentLength = Encoding.UTF8.GetByteCount(blobContents);
            var containerName = _util.GenerateSampleContainerName(_runId);
            var blobName = _util.GenerateSampleBlobName(_runId);
            _util.CreateContainer(containerName);
            _util.CreateBlockBlob(containerName, blobName, content: blobContents);
            IBlobServiceClient client = new BlobServiceClient(AccountSettings);

            var properties = client.GetBlobProperties(containerName, blobName);

            Assert.AreEqual(expectedContentLength, properties.ContentLength);
        }
        public void GetBlobProperties_ExistingBlob_GetsCorrectContentType()
        {
            const string expectedContentType = "pigeon/feathers";
            var containerName = _util.GenerateSampleContainerName(_runId);
            var blobName = _util.GenerateSampleBlobName(_runId);
            _util.CreateContainer(containerName);
            _util.CreateBlockBlob(containerName, blobName, contentType: expectedContentType);
            IBlobServiceClient client = new BlobServiceClient(AccountSettings);

            var properties = client.GetBlobProperties(containerName, blobName);

            Assert.AreEqual(expectedContentType, properties.ContentType);
        }
        public void GetBlobProperties_EmptyBlobName_ThrowsArgumentNullException()
        {
            var containerName = GenerateSampleContainerName();
            var blobName = string.Empty;
            IBlobServiceClient client = new BlobServiceClient(AccountSettings);

            var properties = client.GetBlobProperties(containerName, blobName);

            // exception thrown
        }
        public void GetBlobProperties_UnleasedBlob_GetsLeaseStatusUnlocked()
        {
            var containerName = _util.GenerateSampleContainerName(_runId);
            var blobName = _util.GenerateSampleBlobName(_runId);
            _util.CreateContainer(containerName);
            _util.CreateBlockBlob(containerName, blobName);
            IBlobServiceClient client = new BlobServiceClient(AccountSettings);

            var properties = client.GetBlobProperties(containerName, blobName);

            Assert.AreEqual(LeaseStatus.Unlocked, properties.LeaseStatus);
        }
        public void GetBlobProperties_ExistingBlobWithSpecifiedContentEncoding_GetsCorrectContentEncoding()
        {
            const string expectedEncoding = "with minimal distraction";
            var containerName = _util.GenerateSampleContainerName(_runId);
            var blobName = _util.GenerateSampleBlobName(_runId);
            _util.CreateContainer(containerName);
            _util.CreateBlockBlob(containerName, blobName, contentEncoding: expectedEncoding);
            IBlobServiceClient client = new BlobServiceClient(AccountSettings);

            var properties = client.GetBlobProperties(containerName, blobName);

            Assert.AreEqual(expectedEncoding, properties.ContentEncoding);
        }
        public void GetBlobProperties_ExistingBlob_GetsCorrectDate()
        {
            var containerName = _util.GenerateSampleContainerName(_runId);
            var blobName = _util.GenerateSampleBlobName(_runId);
            _util.CreateContainer(containerName);
            var createdDate = DateTime.Now;
            _util.CreateBlockBlob(containerName, blobName);
            IBlobServiceClient client = new BlobServiceClient(AccountSettings);

            var properties = client.GetBlobProperties(containerName, blobName);

            _util.AssertDatesEqualWithTolerance(createdDate, properties.Date);
        }
        public void GetBlobProperties_ExistingBlobWithMetadata_GetsCorrectMetadata()
        {
            var metadata = new Dictionary<string, string>{
                { "HeyHey", "We're the" },
                { "GroundControl", "CallingMajor" }
            };
            var containerName = _util.GenerateSampleContainerName(_runId);
            var blobName = _util.GenerateSampleBlobName(_runId);
            _util.CreateContainer(containerName);
            _util.CreateBlockBlob(containerName, blobName, metadata);
            IBlobServiceClient client = new BlobServiceClient(AccountSettings);

            var properties = client.GetBlobProperties(containerName, blobName);

            Assert.AreEqual(metadata, properties.Metadata);
        }
        public void GetBlobProperties_ExistingPageBlob_GetsPageBlobType()
        {
            var containerName = _util.GenerateSampleContainerName(_runId);
            var blobName = _util.GenerateSampleBlobName(_runId);
            _util.CreateContainer(containerName);
            _util.CreatePageBlob(containerName, blobName);
            IBlobServiceClient client = new BlobServiceClient(AccountSettings);

            var properties = client.GetBlobProperties(containerName, blobName);

            Assert.AreEqual(Communications.Common.BlobType.Page, properties.BlobType);
        }
        public void GetBlobProperties_LeasedBlobLeaseBreaking_GetsLeaseStateBreaking()
        {
            var containerName = GenerateSampleContainerName();
            var blobName = GenerateSampleBlobName();
            CreateContainer(containerName);
            CreateBlockBlob(containerName, blobName);
            var lease = LeaseBlob(containerName, blobName, TimeSpan.FromSeconds(60));
            BreakBlobLease(containerName, blobName, lease, 30);
            IBlobServiceClient client = new BlobServiceClient(AccountSettings);
            Thread.Sleep(TimeSpan.FromSeconds(16));

            var properties = client.GetBlobProperties(containerName, blobName);

            Assert.AreEqual(LeaseState.Breaking, properties.LeaseState);
        }
        public void GetBlobProperties_NullBlobName_ThrowsArgumentNullException()
        {
            var containerName = _util.GenerateSampleContainerName(_runId);
            string blobName = null;
            IBlobServiceClient client = new BlobServiceClient(AccountSettings);

            var properties = client.GetBlobProperties(containerName, blobName);

            // exception thrown
        }
        public void GetBlobProperties_LeasedBlob_GetsLeaseStateLeased()
        {
            var containerName = GenerateSampleContainerName();
            var blobName = GenerateSampleBlobName();
            CreateContainer(containerName);
            CreateBlockBlob(containerName, blobName);
            LeaseBlob(containerName, blobName);
            IBlobServiceClient client = new BlobServiceClient(AccountSettings);

            var properties = client.GetBlobProperties(containerName, blobName);

            Assert.AreEqual(LeaseState.Leased, properties.LeaseState);
        }
        public void GetBlobProperties_ExistingBlockBlob_GetsBlockBlobType()
        {
            var containerName = GenerateSampleContainerName();
            var blobName = GenerateSampleBlobName();
            CreateContainer(containerName);
            CreateBlockBlob(containerName, blobName);
            IBlobServiceClient client = new BlobServiceClient(AccountSettings);

            var properties = client.GetBlobProperties(containerName, blobName);

            Assert.AreEqual(Communications.BlobService.BlobType.Block, properties.BlobType);
        }
        public void GetBlobProperties_ExistingBlobJustModified_GetsCorrectLastModified()
        {
            var containerName = GenerateSampleContainerName();
            var blobName = GenerateSampleBlobName();
            var createdAt = DateTime.Now;
            CreateContainer(containerName);
            CreateBlockBlob(containerName, blobName);
            IBlobServiceClient client = new BlobServiceClient(AccountSettings);

            var properties = client.GetBlobProperties(containerName, blobName);

            AssertDatesEqualWithTolerance(createdAt, properties.LastModified);
        }
        public void GetBlobProperties_ExistingBlobModified_ETagPropertyChanges()
        {
            var containerName = _util.GenerateSampleContainerName(_runId);
            var blobName = _util.GenerateSampleBlobName(_runId);
            _util.CreateContainer(containerName);
            _util.CreateBlockBlob(containerName, blobName);
            var initialProperties = _util.GetBlobProperties(containerName, blobName);
            _util.UpdateBlockBlob(containerName, blobName);
            IBlobServiceClient client = new BlobServiceClient(AccountSettings);

            var postChangeProperties = client.GetBlobProperties(containerName, blobName);

            Assert.AreNotEqual(initialProperties.ETag, postChangeProperties.ETag);
        }
        public void GetBlobProperties_LeasedBlobWithFixedLeaseTime_GetsLeaseDurationFixed()
        {
            var containerName = _util.GenerateSampleContainerName(_runId);
            var blobName = _util.GenerateSampleBlobName(_runId);
            _util.CreateContainer(containerName);
            _util.CreateBlockBlob(containerName, blobName);
            _util.LeaseBlob(containerName, blobName, TimeSpan.FromSeconds(20));
            IBlobServiceClient client = new BlobServiceClient(AccountSettings);

            var properties = client.GetBlobProperties(containerName, blobName);

            Assert.AreEqual(LeaseDuration.Fixed, properties.LeaseDuration);
        }
        public void GetBlobProperties_ExistingBlobWithSpecifiedContentMD5_GetsCorrectContentMD5()
        {
            var containerName = _util.GenerateSampleContainerName(_runId);
            var blobName = _util.GenerateSampleBlobName(_runId);
            _util.CreateContainer(containerName);
            var blobMD5 = _util.CreateBlockBlob(containerName, blobName)
                .Properties.ContentMD5;
            IBlobServiceClient client = new BlobServiceClient(AccountSettings);

            var properties = client.GetBlobProperties(containerName, blobName);

            Assert.AreEqual(blobMD5, properties.ContentMD5);
        }
        public void GetBlobProperties_LeasedBlobWithInfiniteLeaseTime_GetsLeaseDurationInfinite()
        {
            var containerName = _util.GenerateSampleContainerName(_runId);
            var blobName = _util.GenerateSampleBlobName(_runId);
            _util.CreateContainer(containerName);
            _util.CreateBlockBlob(containerName, blobName);
            _util.LeaseBlob(containerName, blobName, null);
            IBlobServiceClient client = new BlobServiceClient(AccountSettings);

            var properties = client.GetBlobProperties(containerName, blobName);

            Assert.AreEqual(LeaseDuration.Infinite, properties.LeaseDuration);
        }
        public void GetBlobProperties_ExistingBlobWithSpecifiedContentLanguage_GetsCorrectContentLanguage()
        {
            const string expectedLanguage = "dour";
            var containerName = _util.GenerateSampleContainerName(_runId);
            var blobName = _util.GenerateSampleBlobName(_runId);
            _util.CreateContainer(containerName);
            _util.CreateBlockBlob(containerName, blobName, contentLanguage: expectedLanguage);
            IBlobServiceClient client = new BlobServiceClient(AccountSettings);

            var properties = client.GetBlobProperties(containerName, blobName);

            Assert.AreEqual(expectedLanguage, properties.ContentLanguage);
        }
        public void GetBlobProperties_LeasedBlobLeaseBroken_GetsLeaseStateBroken()
        {
            var containerName = _util.GenerateSampleContainerName(_runId);
            var blobName = _util.GenerateSampleBlobName(_runId);
            _util.CreateContainer(containerName);
            _util.CreateBlockBlob(containerName, blobName);
            var lease = _util.LeaseBlob(containerName, blobName, TimeSpan.FromSeconds(15));
            _util.BreakBlobLease(containerName, blobName, lease);
            IBlobServiceClient client = new BlobServiceClient(AccountSettings);
            Thread.Sleep(TimeSpan.FromSeconds(2));

            var properties = client.GetBlobProperties(containerName, blobName);

            Assert.AreEqual(LeaseState.Broken, properties.LeaseState);
        }
        public void GetBlobProperties_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.GetBlobProperties(containerName, initialBlobName);

            _util.AssertBlobCopyPropertiesMatch(containerName, initialBlobName, response);
        }
        public void GetBlobProperties_ExistingBlob_GetsProperties()
        {
            var containerName = GenerateSampleContainerName();
            var blobName = GenerateSampleBlobName();
            CreateContainer(containerName);
            CreateBlockBlob(containerName, blobName);
            IBlobServiceClient client = new BlobServiceClient(AccountSettings);

            var properties = client.GetBlobProperties(containerName, blobName);

            Assert.NotNull(properties);
        }