private void DoCloudTableDeleteWhenNotExistSync(TablePayloadFormat format)
        {
            CloudTableClient tableClient = GenerateCloudTableClient();

            tableClient.DefaultRequestOptions.PayloadFormat = format;
            string           tableName = GenerateRandomTableName();
            CloudTable       tableRef  = tableClient.GetTableReference(tableName);
            OperationContext ctx       = new OperationContext();

            try
            {
                Assert.IsFalse(tableRef.Exists());

                // This should throw with no retries
                tableRef.Delete(null, ctx);
                Assert.Fail();
            }
            catch (StorageException ex)
            {
                Assert.AreEqual(ex.RequestInformation.HttpStatusCode, 404);
                Assert.AreEqual(ex.RequestInformation.ExtendedErrorInformation.ErrorCode, "ResourceNotFound");
                TestHelper.AssertNAttempts(ctx, 1);
            }
            finally
            {
                tableRef.DeleteIfExists();
            }
        }
Exemple #2
0
        public void TableSasInvalidOperations()
        {
            CloudTableClient tableClient = GenerateCloudTableClient();
            CloudTable       table       = tableClient.GetTableReference("T" + Guid.NewGuid().ToString("N"));

            try
            {
                table.Create();
                // Prepare SAS authentication with full permissions
                string sasString = table.GetSharedAccessSignature(
                    new SharedAccessTablePolicy
                {
                    Permissions            = SharedAccessTablePermissions.Delete,
                    SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30)
                },
                    null,
                    null,
                    null,
                    null,
                    null);

                CloudTableClient sasClient = new CloudTableClient(tableClient.BaseUri, new StorageCredentials(sasString));

                // Construct a valid set of service properties to upload.
                ServiceProperties properties = new ServiceProperties();
                properties.Logging.Version       = "1.0";
                properties.Metrics.Version       = "1.0";
                properties.Logging.RetentionDays = 9;
                sasClient.GetServiceProperties();
                sasClient.SetServiceProperties(properties);

                // Test invalid client operations
                // BUGBUG: ListTables hides the exception. We should fix this
                // TestHelpers.ExpectedException(() => sasClient.ListTablesSegmented(), "List tables with SAS", HttpStatusCode.NotFound);
                TestHelper.ExpectedException((ctx) => sasClient.GetServiceProperties(), "Get service properties with SAS", (int)HttpStatusCode.NotFound);
                TestHelper.ExpectedException((ctx) => sasClient.SetServiceProperties(properties), "Set service properties with SAS", (int)HttpStatusCode.NotFound);

                CloudTable sasTable = sasClient.GetTableReference(table.Name);

                // Verify that creation fails with SAS
                TestHelper.ExpectedException((ctx) => sasTable.Create(null, ctx), "Create a table with SAS", (int)HttpStatusCode.NotFound);

                // Create the table.
                table.Create();

                // Test invalid table operations
                TestHelper.ExpectedException((ctx) => sasTable.Delete(null, ctx), "Delete a table with SAS", (int)HttpStatusCode.NotFound);
                TestHelper.ExpectedException((ctx) => sasTable.GetPermissions(null, ctx), "Get ACL with SAS", (int)HttpStatusCode.NotFound);
                TestHelper.ExpectedException((ctx) => sasTable.SetPermissions(new TablePermissions(), null, ctx), "Set ACL with SAS", (int)HttpStatusCode.NotFound);
            }
            finally
            {
                table.DeleteIfExists();
            }
        }
Exemple #3
0
        public void CloudTableDeleteSync()
        {
            CloudTableClient tableClient = GenerateCloudTableClient();
            string           tableName   = GenerateRandomTableName();
            CloudTable       tableRef    = tableClient.GetTableReference(tableName);

            try
            {
                Assert.IsFalse(tableRef.Exists());
                tableRef.Create();
                Assert.IsTrue(tableRef.Exists());
                tableRef.Delete();
                Assert.IsFalse(tableRef.Exists());
            }
            finally
            {
                tableRef.DeleteIfExists();
            }
        }
        private void DoCloudTableDeleteSync(TablePayloadFormat format)
        {
            CloudTableClient tableClient = GenerateCloudTableClient();

            tableClient.DefaultRequestOptions.PayloadFormat = format;
            string     tableName = GenerateRandomTableName();
            CloudTable tableRef  = tableClient.GetTableReference(tableName);

            try
            {
                Assert.IsFalse(tableRef.Exists());
                tableRef.Create();
                Assert.IsTrue(tableRef.Exists());
                tableRef.Delete();
                Assert.IsFalse(tableRef.Exists());
            }
            finally
            {
                tableRef.DeleteIfExists();
            }
        }
        public void CloudTableExistsAPM()
        {
            CloudTableClient tableClient = GenerateCloudTableClient();
            string           tableName   = GenerateRandomTableName();
            CloudTable       tableRef    = tableClient.GetTableReference(tableName);

            try
            {
                using (ManualResetEvent evt = new ManualResetEvent(false))
                {
                    IAsyncResult result = null;
                    tableRef.BeginExists((res) =>
                    {
                        result = res;
                        evt.Set();
                    }, null);

                    evt.WaitOne();

                    // Table should not have been deleted as it doesnt exist
                    Assert.IsFalse(tableRef.EndExists(result));
                }

                tableRef.Create();

                using (ManualResetEvent evt = new ManualResetEvent(false))
                {
                    IAsyncResult result = null;
                    tableRef.BeginExists((res) =>
                    {
                        result = res;
                        evt.Set();
                    }, null);

                    evt.WaitOne();

                    // Table should not have been deleted as it doesnt exist
                    Assert.IsTrue(tableRef.EndExists(result));
                }

                tableRef.Delete();
                using (ManualResetEvent evt = new ManualResetEvent(false))
                {
                    IAsyncResult result = null;
                    tableRef.BeginExists((res) =>
                    {
                        result = res;
                        evt.Set();
                    }, null);

                    evt.WaitOne();

                    // Table should not have been deleted as it doesnt exist
                    Assert.IsFalse(tableRef.EndExists(result));
                }
            }
            finally
            {
                tableRef.DeleteIfExists();
            }
        }
 /// <summary>
 /// Delete the specified azure storage table
 /// </summary>
 /// <param name="table">Cloud table object</param>
 /// <param name="requestOptions">Table request options</param>
 /// <param name="operationContext">Operation context</param>
 public void Delete(CloudTable table, TableRequestOptions requestOptions, OperationContext operationContext)
 {
     table.Delete(requestOptions, operationContext);
 }
 private void EraseTable(CloudTable table)
 {
     ConsoleWrite.Verbose("  Erasing {0}", table.Name);
     if (_args.IsReal)
         table.Delete();
 }