Example #1
0
        public async Task TableBatchRetrieveWithResolverAsync()
        {
            CloudTableClient tableClient = GenerateCloudTableClient();

            DynamicTableEntity sendEnt = new DynamicTableEntity();

            sendEnt.PartitionKey = Guid.NewGuid().ToString();
            sendEnt.RowKey       = Guid.NewGuid().ToString();

            // generate a set of properties for all supported Types
            sendEnt.Properties = new ComplexEntity().WriteEntity(null);
            sendEnt.Properties.Add("foo", new EntityProperty("bar"));

            EntityResolver <string> resolver = (pk, rk, ts, props, etag) => pk + rk + props["foo"].StringValue + props.Count;

            // not found
            TableResult result = await currentTable.ExecuteAsync(TableOperationFactory.Retrieve(sendEnt.PartitionKey, sendEnt.RowKey, resolver));

            Assert.AreEqual(result.HttpStatusCode, (int)HttpStatusCode.NotFound);
            Assert.IsNull(result.Result);
            Assert.IsNull(result.Etag);

            // insert entity
            await currentTable.ExecuteAsync(TableOperation.Insert(sendEnt));

            // Success
            result = await currentTable.ExecuteAsync(TableOperationFactory.Retrieve(sendEnt.PartitionKey, sendEnt.RowKey, resolver));

            Assert.AreEqual(result.HttpStatusCode, (int)HttpStatusCode.OK);
            Assert.AreEqual((string)result.Result, sendEnt.PartitionKey + sendEnt.RowKey + sendEnt.Properties["foo"].StringValue + sendEnt.Properties.Count);
        }
Example #2
0
        /// <summary>
        /// Test point queries entities inside and outside the given range.
        /// </summary>
        /// <param name="testClient">The table client to test.</param>
        /// <param name="tableName">The name of the table to test.</param>
        /// <param name="accessPermissions">The access permissions of the table client.</param>
        /// <param name="startPk">The start partition key range.</param>
        /// <param name="startRk">The start row key range.</param>
        /// <param name="endPk">The end partition key range.</param>
        /// <param name="endRk">The end row key range.</param>
        private async Task TestPointQuery(
            CloudTableClient testClient,
            string tableName,
            SharedAccessTablePermissions accessPermissions,
            string startPk,
            string startRk,
            string endPk,
            string endRk)
        {
            bool expectSuccess = (accessPermissions & SharedAccessTablePermissions.Query) != 0;

            Action <BaseEntity, OperationContext> queryDelegate = (tableEntity, ctx) =>
            {
                Task <TableResult> retrieveTask = testClient.GetTableReference(tableName).ExecuteAsync(TableOperationFactory.Retrieve <BaseEntity>(tableEntity.PartitionKey, tableEntity.RowKey), null, ctx).AsTask();

                retrieveTask.Wait();

                if (expectSuccess)
                {
                    Assert.IsNotNull(retrieveTask.Result.Result);
                }
                else
                {
                    Assert.AreEqual(ctx.LastResult.HttpStatusCode, (int)HttpStatusCode.OK);
                }
            };


            // Perform test
            await TestOperationWithRange(
                tableName,
                startPk,
                startRk,
                endPk,
                endRk,
                queryDelegate,
                "point query",
                expectSuccess,
                expectSuccess?HttpStatusCode.OK : HttpStatusCode.NotFound);
        }