コード例 #1
0
 private static void DeleteByPartitions(string[] partitions, string[] entries, IActivityTracker <DynamicTableEntity> journal)
 {
     foreach (var partition in partitions)
     {
         foreach (var entry in entries)
         {
             journal.Delete(new Identifier(entry, partition));
         }
     }
 }
コード例 #2
0
        public void TestQueryGlobal()
        {
            var query   = new MetricQueryableFactory <DynamicTableEntity>().Create((string)null);
            var hasRows = (query.Get(_JournalTableName, 1)).Results.Count > 0;

            if (hasRows)
            {
                var allRows = query.Get(_JournalTableName);

                foreach (var row in allRows.Results)
                {
                    _Journal.Delete(new Identifier(row.RowKey, row.PartitionKey));
                }
            }

            //Create
            InsertByPartitions(_PartitionKeys, _RowKeys, _Journal);

            //Read
            var rows = query.Get(_JournalTableName, 1,
                                 new QueryFilterCondition[] { new QueryFilterCondition(new QueryFilter("PartitionKey", "A"), QueryComparisons.Equal),
                                                              new QueryFilterCondition(new QueryFilter("RowKey", "01"), QueryComparisons.Equal) }, TableOperators.And);

            Assert.IsTrue(rows.Results.Count == 1, $"1. Wrong number of rows returned. Row count: {rows.Results.Count}");

            //Read all but 1
            var rowsA = query.Get(_JournalTableName, null,
                                  new QueryFilterCondition[] { new QueryFilterCondition(new QueryFilter("PartitionKey", "A"), QueryComparisons.NotEqual),
                                                               new QueryFilterCondition(new QueryFilter("RowKey", "01"), QueryComparisons.NotEqual) }, TableOperators.And);

            Assert.IsTrue(rowsA.Results.Count == ((_PartitionKeys.Length - 1) * (_RowKeys.Length - 1)), $"2. Wrong number of rows returned. Row count: {rowsA.Results.Count}");

            //Read all but 1
            var rowsB = query.Get(_JournalTableName, null,
                                  new QueryFilterCondition[] { new QueryFilterCondition(new QueryFilter("PartitionKey", "A"), QueryComparisons.NotEqual),
                                                               new QueryFilterCondition(new QueryFilter("RowKey", "01"), QueryComparisons.NotEqual) }, TableOperators.Or);

            Assert.IsTrue(rowsB.Results.Count == ((_PartitionKeys.Length) * (_RowKeys.Length)) - 1, $"3. Wrong number of rows returned. Row count: {rowsB.Results.Count}");

            //Read all but 1
            var rowsC = query.Get(_JournalTableName, null,
                                  new QueryFilterCondition[] { new QueryFilterCondition(new QueryFilter("PartitionKey", "A"), QueryComparisons.NotEqual),
                                                               new QueryFilterCondition(new QueryFilter("RowKey", "01"), QueryComparisons.NotEqual),
                                                               new QueryFilterCondition(new QueryFilter("RowKey", "10"), QueryComparisons.LessThan) }, TableOperators.Or, TableOperators.And);

            Assert.IsTrue(rowsC.Results.Count == ((_PartitionKeys.Length) * (_RowKeys.Length)) - 1, $"4. Wrong number of rows returned. Row count: {rowsC.Results.Count}");

            //Read
            var rows2 = query.Get(_JournalTableName, null, new QueryFilterCondition[] { new QueryFilterCondition(new QueryFilter("RowKey", "01"), QueryComparisons.Equal) });

            Assert.IsTrue(rows2.Results.Count == _PartitionKeys.Length, $"5. Wrong number of rows returned. Row count: {rows2.Results.Count}");


            //Read
            var rows2A = query.Get(_JournalTableName, null, "RowKey eq '01'");

            Assert.IsTrue(rows2A.Results.Count == _PartitionKeys.Length, $"6. Wrong number of rows returned. Row count: {rows2A.Results.Count}");

            //Read
            var rows3 = query.Get(_JournalTableName, null, new QueryFilterCondition[] { new QueryFilterCondition(new QueryFilter("PartitionKey", "A"), QueryComparisons.Equal) });

            Assert.IsTrue(rows3.Results.Count == _RowKeys.Length, $"7. Wrong number of rows returned. Row count: {rows3.Results.Count}");

            //Delete
            DeleteByPartitions(_PartitionKeys, _RowKeys, _Journal);
        }