Пример #1
0
        public async Task CloudBlobContainerWebContainerOperationsAsync()
        {
            // Test operations with shard key
            CloudBlobClient    blobClient   = GenerateCloudBlobClient();
            CloudBlobContainer webContainer = blobClient.GetContainerReference("$web");

            try
            {
                await webContainer.DeleteIfExistsAsync();

                Assert.IsFalse(await webContainer.ExistsAsync());
                await TestHelper.SpinUpToNSecondsIgnoringFailuresAsync(async() => await webContainer.CreateAsync(), 120);

                Assert.IsTrue(await webContainer.ExistsAsync());
                Assert.IsTrue(
                    (await blobClient.ListContainersSegmentedAsync("$", null))
                    .Results
                    .Any(container => container.Name == webContainer.Name)
                    );

                await ValidateWebContainerAsync(webContainer);

                // Clear out the old data, faster than deleting / re-creating the container.
                foreach (CloudBlob blob in (await webContainer.ListBlobsSegmentedAsync(string.Empty, true, BlobListingDetails.All, default(int?), default(BlobContinuationToken), default(BlobRequestOptions), default(OperationContext))).Results)
                {
                    await blob.DeleteAsync();
                }

                // Test relevant operations with a service SAS.
                string webContainerSAS = webContainer.GetSharedAccessSignature(new SharedAccessBlobPolicy()
                {
                    SharedAccessExpiryTime = DateTime.Now + TimeSpan.FromDays(30), Permissions = SharedAccessBlobPermissions.Create | SharedAccessBlobPermissions.Delete | SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.List | SharedAccessBlobPermissions.Write
                });
                await ValidateWebContainerAsync(new CloudBlobContainer(new Uri(webContainer.Uri + webContainerSAS)));

                await webContainer.DeleteAsync();

                Assert.IsFalse(
                    (await blobClient.ListContainersSegmentedAsync("$", null))
                    .Results
                    .Any(container => container.Name == webContainer.Name)
                    );
            }
            finally
            {
                webContainer.DeleteIfExistsAsync().Wait();
            }
        }
Пример #2
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();
            }
        }