コード例 #1
0
        public void CloudTableCreateAPM()
        {
            CloudTableClient tableClient = GenerateCloudTableClient();
            string           tableName   = GenerateRandomTableName();
            CloudTable       tableRef    = tableClient.GetTableReference(tableName);

            try
            {
                Assert.IsFalse(tableRef.Exists());
                using (ManualResetEvent evt = new ManualResetEvent(false))
                {
                    IAsyncResult result = null;
                    tableRef.BeginCreate((res) =>
                    {
                        result = res;
                        evt.Set();
                    }, null);
                    evt.WaitOne();

                    tableRef.EndCreate(result);
                }

                Assert.IsTrue(tableRef.Exists());
            }
            finally
            {
                tableRef.DeleteIfExists();
            }
        }
コード例 #2
0
        public void CloudTableCreateAlreadyExistsAPM()
        {
            CloudTableClient tableClient = GenerateCloudTableClient();
            string           tableName   = GenerateRandomTableName();
            CloudTable       tableRef    = tableClient.GetTableReference(tableName);
            OperationContext ctx         = new OperationContext();

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

                // This should throw with no retries
                using (ManualResetEvent evt = new ManualResetEvent(false))
                {
                    IAsyncResult result = null;
                    tableRef.BeginCreate(
                        null,
                        ctx,
                        (res) =>
                    {
                        result = res;
                        evt.Set();
                    },
                        null);
                    evt.WaitOne();

                    tableRef.EndCreate(result);
                }

                Assert.Fail();
            }
            catch (StorageException ex)
            {
                Assert.AreEqual(ex.RequestInformation.ExtendedErrorInformation.ErrorCode, "TableAlreadyExists");
                Assert.AreEqual(ex.RequestInformation.HttpStatusCode, (int)HttpStatusCode.Conflict);
                TestHelper.AssertNAttempts(ctx, 1);
            }
            finally
            {
                tableRef.DeleteIfExists();
            }
        }