Пример #1
0
        public void CloudBlobDirectoryFlatListingWithPrefix()
        {
            foreach (String delimiter in Delimiters)
            {
                CloudBlobClient client = GenerateCloudBlobClient();
                client.DefaultDelimiter = delimiter;
                string             name      = GetRandomContainerName();
                CloudBlobContainer container = client.GetContainerReference(name);

                try
                {
                    container.Create();
                    if (CloudBlobDirectorySetupWithDelimiter(container, delimiter))
                    {
                        BlobContinuationToken token     = null;
                        CloudBlobDirectory    directory = container.GetDirectoryReference("TopDir1");
                        List <IListBlobItem>  list1     = new List <IListBlobItem>();
                        do
                        {
                            BlobResultSegment result1 = directory.ListBlobsSegmented(token);
                            token = result1.ContinuationToken;
                            list1.AddRange(result1.Results);
                        }while (token != null);

                        Assert.IsTrue(list1.Count == 3);

                        IListBlobItem item11 = list1.ElementAt(0);
                        Assert.IsTrue(item11.Uri.Equals(container.Uri + "/TopDir1" + delimiter + "Blob1"));

                        IListBlobItem item12 = list1.ElementAt(1);
                        Assert.IsTrue(item12.Uri.Equals(container.Uri + "/TopDir1" + delimiter + "MidDir1" + delimiter));

                        IListBlobItem item13 = list1.ElementAt(2);
                        Assert.IsTrue(item13.Uri.Equals(container.Uri + "/TopDir1" + delimiter + "MidDir2" + delimiter));

                        CloudBlobDirectory midDir2 = (CloudBlobDirectory)item13;

                        List <IListBlobItem> list2 = new List <IListBlobItem>();
                        do
                        {
                            BlobResultSegment result2 = midDir2.ListBlobsSegmented(true, BlobListingDetails.None, null, token, null, null);
                            token = result2.ContinuationToken;
                            list2.AddRange(result2.Results);
                        }while (token != null);

                        Assert.IsTrue(list2.Count == 2);

                        IListBlobItem item41 = list2.ElementAt(0);
                        Assert.IsTrue(item41.Uri.Equals(container.Uri + "/TopDir1" + delimiter + "MidDir2" + delimiter + "EndDir1" + delimiter + "EndBlob1"));

                        IListBlobItem item42 = list2.ElementAt(1);
                        Assert.IsTrue(item42.Uri.Equals(container.Uri + "/TopDir1" + delimiter + "MidDir2" + delimiter + "EndDir2" + delimiter + "EndBlob2"));
                    }
                }
                finally
                {
                    container.DeleteIfExists();
                }
            }
        }
Пример #2
0
        public async Task CloudBlobContainerListBlobsWithSecondaryUriAsync()
        {
            AssertSecondaryEndpoint();

            CloudBlobContainer container = GetRandomContainerReference();

            try
            {
                await container.CreateAsync();

                List <string> blobNames = await CreateBlobsAsync(container, 3, BlobType.BlockBlob);

                blobNames.AddRange(await CreateBlobsAsync(container, 3, BlobType.PageBlob));

                BlobContinuationToken token = null;
                do
                {
                    BlobResultSegment results = await container.ListBlobsSegmentedAsync(null, true, BlobListingDetails.None, 1, token, null, null);

                    foreach (CloudBlob blob in results.Results)
                    {
                        Assert.IsTrue(blobNames.Remove(blob.Name));
                        Assert.IsTrue(container.GetBlockBlobReference(blob.Name).StorageUri.Equals(blob.StorageUri));
                    }

                    token = results.ContinuationToken;
                }while (token != null);
                Assert.AreEqual(0, blobNames.Count);
            }
            finally
            {
                container.DeleteIfExistsAsync().Wait();
            }
        }
Пример #3
0
        public async Task CloudBlobContainerListBlobsSegmentedAsync()
        {
            CloudBlobContainer container = GetRandomContainerReference();

            try
            {
                await container.CreateAsync();

                List <string> blobNames = await CreateBlobsAsync(container, 3, BlobType.PageBlob);

                BlobContinuationToken token = null;
                do
                {
                    BlobResultSegment results = await container.ListBlobsSegmentedAsync(null, true, BlobListingDetails.None, 1, token, null, null);

                    int count = 0;
                    foreach (IListBlobItem blobItem in results.Results)
                    {
                        Assert.IsInstanceOfType(blobItem, typeof(CloudPageBlob));
                        Assert.IsTrue(blobNames.Remove(((CloudPageBlob)blobItem).Name));
                        count++;
                    }
                    Assert.AreEqual(1, count);
                    token = results.ContinuationToken;
                }while (token != null);
                Assert.AreEqual(0, blobNames.Count);
            }
            finally
            {
                container.DeleteIfExistsAsync().Wait();
            }
        }
Пример #4
0
        public async Task CloudBlobDirectoryMultipleDelimitersAsync()
        {
            foreach (String delimiter in Delimiters)
            {
                CloudBlobClient client = GenerateCloudBlobClient();
                ////Set the default delimiter to \
                client.DefaultDelimiter = delimiter;
                string             name      = GetRandomContainerName();
                CloudBlobContainer container = client.GetContainerReference(name);
                await container.CreateAsync();

                try
                {
                    if (await CloudBlobDirectorySetupWithDelimiterAsync(container, delimiter))
                    {
                        BlobResultSegment segment = await container.ListBlobsSegmentedAsync("TopDir1" + delimiter, false, BlobListingDetails.UncommittedBlobs, null, null, null, null);

                        List <IListBlobItem> simpleList = new List <IListBlobItem>();
                        simpleList.AddRange(segment.Results);
                        while (segment.ContinuationToken != null)
                        {
                            segment = await container.ListBlobsSegmentedAsync("TopDir1" + delimiter, false, BlobListingDetails.UncommittedBlobs, null, segment.ContinuationToken, null, null);

                            simpleList.AddRange(segment.Results);
                        }

                        Assert.IsTrue(simpleList.Count == 3);

                        IListBlobItem item11 = simpleList.ElementAt(0);
                        Assert.IsTrue(item11.Uri.Equals(container.Uri + "/TopDir1" + delimiter + "Blob1"));

                        IListBlobItem item12 = simpleList.ElementAt(1);
                        Assert.IsTrue(item12.Uri.Equals(container.Uri + "/TopDir1" + delimiter + "MidDir1" + delimiter));

                        IListBlobItem item13 = simpleList.ElementAt(2);
                        Assert.IsTrue(item13.Uri.Equals(container.Uri + "/TopDir1" + delimiter + "MidDir2" + delimiter));

                        CloudBlobDirectory directory    = container.GetDirectoryReference("TopDir1" + delimiter);
                        CloudBlobDirectory subDirectory = directory.GetDirectoryReference("MidDir1" + delimiter);
                        CloudBlobDirectory parent       = subDirectory.Parent;
                        Assert.AreEqual(parent.Prefix, directory.Prefix);
                        Assert.AreEqual(parent.Uri, directory.Uri);
                    }
                }
                finally
                {
                    container.DeleteIfExistsAsync().Wait();
                }
            }
        }
Пример #5
0
        public async Task CloudBlobContainerListBlobsSegmentedSasAsync()
        {
            CloudBlobContainer container = GetRandomContainerReference();

            try
            {
                await container.CreateAsync();

                List <string> blobNames = await CreateBlobsAsync(container, 3, BlobType.PageBlob);

                string sas = container.GetSharedAccessSignature(new SharedAccessBlobPolicy
                {
                    SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddHours(1),
                    Permissions            = SharedAccessBlobPolicy.PermissionsFromString("racwdl")
                });

                CloudBlobContainer sasContainer = GenerateCloudBlobSasClient(sas).GetContainerReference(container.Name);

                BlobContinuationToken token = null;
                do
                {
                    BlobResultSegment results = await sasContainer.ListBlobsSegmentedAsync(null, true, BlobListingDetails.None, 1, token, null, null);

                    int count = 0;
                    foreach (IListBlobItem blobItem in results.Results)
                    {
                        Assert.IsInstanceOfType(blobItem, typeof(CloudPageBlob));
                        Assert.IsTrue(blobNames.Remove(((CloudPageBlob)blobItem).Name));
                        count++;
                    }
                    Assert.AreEqual(1, count);
                    token = results.ContinuationToken;
                }while (token != null);
                Assert.AreEqual(0, blobNames.Count);
            }
            finally
            {
                container.DeleteIfExistsAsync().Wait();
            }
        }
        public async Task CloudBlobListBlobSegmentEncryptionScopeTask()
        {
            // Arrange
            CloudBlobContainer container = GetRandomContainerReference();
            await container.CreateAsync();

            var encryptionScope = TestBase.TargetTenantConfig.EncryptionScope;
            var options         = new BlobRequestOptions
            {
                EncryptionScope = encryptionScope
            };

            var appendBlob = container.GetAppendBlobReference(GetRandomBlobName());
            await appendBlob.CreateOrReplaceAsync(null, options, null, CancellationToken.None);

            try
            {
                BlobContinuationToken token = null;
                do
                {
                    BlobResultSegment results = await container.ListBlobsSegmentedAsync(token);

                    foreach (IListBlobItem blobItem in results.Results)
                    {
                        CloudBlob blob = blobItem as CloudBlob;

                        // Assert
                        Assert.AreEqual(options.EncryptionScope, blob.Properties.EncryptionScope);
                    }
                    token = results.ContinuationToken;
                }while (token != null);
            }
            finally
            {
                await container.DeleteAsync();
            }
        }
Пример #7
0
        public async Task CloudBlobContainerListBlobsAsync()
        {
            CloudBlobContainer container = GetRandomContainerReference();

            try
            {
                await container.CreateAsync();

                List <string> blobNames = await CreateBlobsAsync(container, 3, BlobType.PageBlob);

                BlobResultSegment results = await container.ListBlobsSegmentedAsync(null);

                Assert.AreEqual(blobNames.Count, results.Results.Count());
                foreach (IListBlobItem blobItem in results.Results)
                {
                    Assert.IsInstanceOfType(blobItem, typeof(CloudPageBlob));
                    Assert.IsTrue(blobNames.Remove(((CloudPageBlob)blobItem).Name));
                }
            }
            finally
            {
                container.DeleteIfExistsAsync().Wait();
            }
        }
Пример #8
0
        public async Task CloudBlobDirectoryFlatListingAsync()
        {
            foreach (String delimiter in Delimiters)
            {
                CloudBlobClient client = GenerateCloudBlobClient();
                client.DefaultDelimiter = delimiter;
                string             name      = GetRandomContainerName();
                CloudBlobContainer container = client.GetContainerReference(name);

                try
                {
                    await container.CreateAsync();

                    if (await CloudBlobDirectorySetupWithDelimiterAsync(container, delimiter))
                    {
                        BlobResultSegment segment = await container.ListBlobsSegmentedAsync("TopDir1" + delimiter, false, BlobListingDetails.None, null, null, null, null);

                        List <IListBlobItem> simpleList1 = new List <IListBlobItem>();
                        simpleList1.AddRange(segment.Results);
                        while (segment.ContinuationToken != null)
                        {
                            segment = await container.ListBlobsSegmentedAsync("TopDir1" + delimiter, false, BlobListingDetails.None, null, segment.ContinuationToken, null, null);

                            simpleList1.AddRange(segment.Results);
                        }

                        Assert.IsTrue(simpleList1.Count == 3);
                        IListBlobItem item11 = simpleList1.ElementAt(0);
                        Assert.IsTrue(item11.Uri.Equals(container.Uri + "/TopDir1" + delimiter + "Blob1"));

                        IListBlobItem item12 = simpleList1.ElementAt(1);
                        Assert.IsTrue(item12.Uri.Equals(container.Uri + "/TopDir1" + delimiter + "MidDir1" + delimiter));

                        IListBlobItem item13 = simpleList1.ElementAt(2);
                        Assert.IsTrue(item13.Uri.Equals(container.Uri + "/TopDir1" + delimiter + "MidDir2" + delimiter));
                        CloudBlobDirectory midDir2 = (CloudBlobDirectory)item13;

                        BlobResultSegment segment2 = await container.ListBlobsSegmentedAsync("TopDir1" + delimiter + "MidDir1", true, BlobListingDetails.None, null, null, null, null);

                        List <IListBlobItem> simpleList2 = new List <IListBlobItem>();
                        simpleList2.AddRange(segment2.Results);
                        while (segment2.ContinuationToken != null)
                        {
                            segment2 = await container.ListBlobsSegmentedAsync("TopDir1" + delimiter + "MidDir1", true, BlobListingDetails.None, null, segment2.ContinuationToken, null, null);

                            simpleList2.AddRange(segment2.Results);
                        }

                        Assert.IsTrue(simpleList2.Count == 2);

                        IListBlobItem item21 = simpleList2.ElementAt(0);
                        Assert.IsTrue(item21.Uri.Equals(container.Uri + "/TopDir1" + delimiter + "MidDir1" + delimiter + "EndDir1" + delimiter + "EndBlob1"));

                        IListBlobItem item22 = simpleList2.ElementAt(1);
                        Assert.IsTrue(item22.Uri.Equals(container.Uri + "/TopDir1" + delimiter + "MidDir1" + delimiter + "EndDir2" + delimiter + "EndBlob2"));

                        BlobResultSegment segment3 = await container.ListBlobsSegmentedAsync("TopDir1" + delimiter + "MidDir1" + delimiter, false, BlobListingDetails.None, null, null, null, null);

                        List <IListBlobItem> simpleList3 = new List <IListBlobItem>();
                        simpleList3.AddRange(segment3.Results);
                        while (segment3.ContinuationToken != null)
                        {
                            segment3 = await container.ListBlobsSegmentedAsync("TopDir1" + delimiter + "MidDir1" + delimiter, false, BlobListingDetails.None, null, segment3.ContinuationToken, null, null);

                            simpleList3.AddRange(segment3.Results);
                        }
                        Assert.IsTrue(simpleList3.Count == 2);

                        IListBlobItem item31 = simpleList3.ElementAt(0);
                        Assert.IsTrue(item31.Uri.Equals(container.Uri + "/TopDir1" + delimiter + "MidDir1" + delimiter + "EndDir1" + delimiter));

                        IListBlobItem item32 = simpleList3.ElementAt(1);
                        Assert.IsTrue(item32.Uri.Equals(container.Uri + "/TopDir1" + delimiter + "MidDir1" + delimiter + "EndDir2" + delimiter));

                        BlobResultSegment segment4 = await midDir2.ListBlobsSegmentedAsync(true, BlobListingDetails.None, null, null, null, null);

                        List <IListBlobItem> simpleList4 = new List <IListBlobItem>();
                        simpleList4.AddRange(segment4.Results);
                        while (segment4.ContinuationToken != null)
                        {
                            segment4 = await midDir2.ListBlobsSegmentedAsync(true, BlobListingDetails.None, null, segment4.ContinuationToken, null, null);

                            simpleList4.AddRange(segment4.Results);
                        }

                        Assert.IsTrue(simpleList4.Count == 2);

                        IListBlobItem item41 = simpleList4.ElementAt(0);

                        Assert.IsTrue(item41.Uri.Equals(container.Uri + "/TopDir1" + delimiter + "MidDir2" + delimiter + "EndDir1" + delimiter + "EndBlob1"));

                        IListBlobItem item42 = simpleList4.ElementAt(1);
                        Assert.IsTrue(item42.Uri.Equals(container.Uri + "/TopDir1" + delimiter + "MidDir2" + delimiter + "EndDir2" + delimiter + "EndBlob2"));
                    }
                }
                finally
                {
                    container.DeleteIfExistsAsync().Wait();
                }
            }
        }
Пример #9
0
        public async Task CloudBlobSnapshotAsync()
        {
            CloudBlobContainer container = GetRandomContainerReference();

            try
            {
                await container.CreateAsync();

                MemoryStream   originalData = new MemoryStream(GetRandomBuffer(1024));
                CloudBlockBlob blockBlob    = container.GetBlockBlobReference(BlobName);
                await blockBlob.UploadFromStreamAsync(originalData);

                CloudBlob blob = container.GetBlobReference(BlobName);
                await blob.FetchAttributesAsync();

                Assert.IsFalse(blob.IsSnapshot);
                Assert.IsNull(blob.SnapshotTime, "Root blob has SnapshotTime set");
                Assert.IsFalse(blob.SnapshotQualifiedUri.Query.Contains("snapshot"));
                Assert.AreEqual(blob.Uri, blob.SnapshotQualifiedUri);

                CloudBlob snapshot1 = await blob.SnapshotAsync();

                Assert.AreEqual(blob.Properties.ETag, snapshot1.Properties.ETag);
                Assert.AreEqual(blob.Properties.LastModified, snapshot1.Properties.LastModified);
                Assert.IsTrue(snapshot1.IsSnapshot);
                Assert.IsNotNull(snapshot1.SnapshotTime, "Snapshot does not have SnapshotTime set");
                Assert.AreEqual(blob.Uri, snapshot1.Uri);
                Assert.AreNotEqual(blob.SnapshotQualifiedUri, snapshot1.SnapshotQualifiedUri);
                Assert.AreNotEqual(snapshot1.Uri, snapshot1.SnapshotQualifiedUri);
                Assert.IsTrue(snapshot1.SnapshotQualifiedUri.Query.Contains("snapshot"));

                CloudBlob snapshot2 = await blob.SnapshotAsync();

                Assert.IsTrue(snapshot2.SnapshotTime.Value > snapshot1.SnapshotTime.Value);

                await snapshot1.FetchAttributesAsync();

                await snapshot2.FetchAttributesAsync();

                await blob.FetchAttributesAsync();

                AssertAreEqual(snapshot1.Properties, blob.Properties);

                CloudBlob snapshot1Clone = new CloudBlob(new Uri(blob.Uri + "?snapshot=" + snapshot1.SnapshotTime.Value.ToString("O")), blob.ServiceClient.Credentials);
                Assert.IsNotNull(snapshot1Clone.SnapshotTime, "Snapshot clone does not have SnapshotTime set");
                Assert.AreEqual(snapshot1.SnapshotTime.Value, snapshot1Clone.SnapshotTime.Value);
                await snapshot1Clone.FetchAttributesAsync();

                AssertAreEqual(snapshot1.Properties, snapshot1Clone.Properties);

                // The query parser should not be case sensitive in detecting a snapshot in the query string
                CloudBlob snapshotParseVerifier = new CloudBlob(new Uri(blob.Uri + "?sNapshOt=" + snapshot1.SnapshotTime.Value.ToString("O")), blob.ServiceClient.Credentials);
                Assert.IsNotNull(snapshotParseVerifier.SnapshotTime, "Snapshot parse verifier did not successfully detect the snapshot time");
                Assert.AreEqual(snapshot1.SnapshotTime.Value, snapshotParseVerifier.SnapshotTime.Value);

                CloudBlob snapshotCopy = container.GetBlobReference("blob2");
                await snapshotCopy.StartCopyAsync(TestHelper.Defiddler(snapshot1.Uri));
                await WaitForCopyAsync(snapshotCopy);

                Assert.AreEqual(CopyStatus.Success, snapshotCopy.CopyState.Status);

                using (Stream snapshotStream = (await snapshot1.OpenReadAsync()))
                {
                    snapshotStream.Seek(0, SeekOrigin.End);
                    TestHelper.AssertStreamsAreEqual(originalData, snapshotStream);
                }

                await blockBlob.PutBlockListAsync(new List <string>());

                await blob.FetchAttributesAsync();

                using (Stream snapshotStream = (await snapshot1.OpenReadAsync()))
                {
                    snapshotStream.Seek(0, SeekOrigin.End);
                    TestHelper.AssertStreamsAreEqual(originalData, snapshotStream);
                }

                BlobResultSegment resultSegment = await container.ListBlobsSegmentedAsync(null, true, BlobListingDetails.All, null, null, null, null);

                List <IListBlobItem> blobs = resultSegment.Results.ToList();
                Assert.AreEqual(4, blobs.Count);
                AssertAreEqual(snapshot1, (CloudBlob)blobs[0]);
                AssertAreEqual(snapshot2, (CloudBlob)blobs[1]);
                AssertAreEqual(blob, (CloudBlob)blobs[2]);
                AssertAreEqual(snapshotCopy, (CloudBlob)blobs[3]);
            }
            finally
            {
                await container.DeleteAsync();;
            }
        }