/// <summary> /// In memory implementation of <see cref="ExecuteAsync(TableOperation)"/> /// </summary> public override Task <TableResult> ExecuteAsync(TableOperation operation) { var partitionKey = operation.PartitionKey(); var rowKey = operation.RowKey(); switch (operation.OperationType) { case TableOperationType.Retrieve: if (_table.TryGetValue(partitionKey, out var retrieveInner)) { if (retrieveInner.TryGetValue(rowKey, out var retrieveResult)) { return(Task.FromResult(new TableResult() { Result = _table[partitionKey][rowKey] })); } } return(Task.FromResult(new TableResult())); case TableOperationType.Insert: case TableOperationType.InsertOrReplace: case TableOperationType.InsertOrMerge: if (_table.TryGetValue(partitionKey, out var insertInner) && insertInner != null) { if (insertInner.TryGetValue(rowKey, out var insertCurrent) && insertCurrent != null) { if (operation.OperationType == TableOperationType.Insert) { throw new InvalidOperationException("Entity exists, call InserOrReplace or InsertOrMerge instead"); } if (operation.OperationType == TableOperationType.InsertOrReplace) { _table[partitionKey][rowKey] = operation.Entity; } else { // TODO merge } } else { insertInner[rowKey] = operation.Entity; } } else { _table[partitionKey] = new Dictionary <string, object> { [rowKey] = operation.Entity }; } break; case TableOperationType.Delete: if (_table.TryGetValue(partitionKey, out var deleteInner)) { if (deleteInner.TryGetValue(rowKey, out var deleteCurrent)) { _table[partitionKey][rowKey] = null; } } break; default: break; } return(Task.FromResult(new TableResult())); }