Beispiel #1
0
 public static T InsertOrReplaceEntity <T>(this CloudTablePool tablePool, T entity) where T : class, ITableEntity
 {
     return(tablePool.Execute(table =>
     {
         var insertOp = TableOperation.InsertOrReplace(entity);
         var tableResult = table.Execute(insertOp);
         return (T)tableResult.Result;
     }));
 }
Beispiel #2
0
        /// Performs a plain merge operation for a given entity where the caller must set the e-tag on the entity
        public static T UpdateEntity <T>(this CloudTablePool tablePool, T entity) where T : class, ITableEntity
        {
            return(tablePool.Execute(table =>
            {
                var updateOp = TableOperation.Merge(entity);

                var tableResult = table.Execute(updateOp);
                return (T)tableResult.Result;
            }));
        }
Beispiel #3
0
        public static async Task <T> InsertOrMergeEntityAsync <T>(this CloudTablePool tablePool, T entity)
            where T : class, ITableEntity
        {
            return(await tablePool.ExecuteAsync(async table =>
            {
                var insertOp = TableOperation.InsertOrMerge(entity);
                var tableResult = await table.ExecuteAsync(insertOp);

                return (T)tableResult.Result;
            }));
        }
Beispiel #4
0
 /// Performs a 'hard' delete operation, the e-tag will be set to * (so always delete)
 public static void Delete(this CloudTablePool tablePool, string partitionKey, string rowKey)
 {
     tablePool.Execute(table =>
     {
         table.Execute(TableOperation.Delete(new DynamicTableEntity(partitionKey
                                                                    , rowKey
                                                                    , "*"
                                                                    , EmptyProperties)));
         return(true);
     });
 }
Beispiel #5
0
 public static ReadOnlyCollection <T> GetAllEntitiesInPartition <T>(
     this CloudTablePool tablePool
     , string partitionKey) where T : ITableEntity, new()
 {
     return(tablePool.Execute(table =>
     {
         using var loader = new AzureStorageTableLoader <T, T>(
                   table
                   , DefaultMap
                   , new[] { partitionKey }
                   );
         return loader.AllEntities;
     }));
Beispiel #6
0
        public void InsertEntity_Ok()
        {
            //Arrange
            var tableEntity    = new DynamicTableEntity();
            var cloudTableMock = new Mock <CloudTable>(new Uri("https://nothing.net"), new TableClientConfiguration());

            SetupExecute(cloudTableMock, tableEntity, TableOperationType.Insert);
            var pool = new CloudTablePool("UnitTestTable", cloudTableMock.Object);

            //Act & Assert
            TableStorageHelpers.InsertEntity(pool, tableEntity).Should().Be(tableEntity);
            cloudTableMock.Verify();
        }
Beispiel #7
0
        private static (Mock <CloudTable> cloudTableMock, CloudTablePool pool) CreateTablePoolWithMockForExecuteQuery(
            DynamicTableEntity entityToReturnInTableResult,
            Action <Mock <CloudTable>, DynamicTableEntity> setupMethod)
        {
            const string tableName      = "UnitTestTable";
            var          cloudTableMock = new Mock <CloudTable>(new Uri($"https://nothing.net/{tableName}"), new TableClientConfiguration());

            setupMethod(cloudTableMock, entityToReturnInTableResult);

            var pool = new CloudTablePool(tableName, cloudTableMock.Object);

            return(cloudTableMock, pool);
        }
Beispiel #8
0
        public static T?GetEntity <T>(this CloudTablePool tablePool, string partitionKey, string rowKey)
            where T : ITableEntity, new()
        {
            return(tablePool.Execute(table =>
            {
                var filter =
                    TableQueryHelpers.CreatePointQueryFilterForPartitionAndRowKey(partitionKey
                                                                                  , rowKey);

                var entity = table.ExecuteQuery(new TableQuery <T>().Where(filter))
                             .FirstOrDefault();

                return entity;
            }));
        }
Beispiel #9
0
        public static bool TryGetEntity <T>(this CloudTablePool tablePool
                                            , string partitionKey
                                            , string rowKey
                                            , out T entity)
            where T : ITableEntity, new()
        {
            var e = GetEntity <T>(tablePool, partitionKey, rowKey);

            if (e == null)
            {
                entity = new T(); // default
                return(false);
            }

            entity = e;
            return(true);
        }