/// <see cref="ITableStorageProvider.Update{T}"/> public void Update <T>(string tableName, IEnumerable <CloudEntity <T> > entities, bool force) { lock (_syncRoot) { List <MockTableEntry> entries; if (!_tables.TryGetValue(tableName, out entries)) { throw new DataServiceRequestException("UPDATE: table not found."); } // verify valid data BEFORE updating them if (entities.GroupJoin(entries, u => ToId(u), ToId, (u, vs) => vs.Count(entry => force || u.ETag == null || entry.ETag == u.ETag)).Any(c => c != 1)) { throw new DataServiceRequestException("UPDATE: key not found or etag conflict."); } if (entities.GroupBy(e => ToId(e)).Any(id => id.Count() != 1)) { throw new DataServiceRequestException("UPDATE: duplicate keys."); } // ok, we can update safely now foreach (var entity in entities) { var etag = (_nextETag++).ToString(); entity.ETag = etag; var index = entries.FindIndex(entry => entry.PartitionKey == entity.PartitionKey && entry.RowKey == entity.RowKey); entries[index] = new MockTableEntry { PartitionKey = entity.PartitionKey, RowKey = entity.RowKey, ETag = etag, Value = FatEntity.Convert(entity, DataSerializer) }; } } }
static System.Tuple <string, string> ToId(MockTableEntry entry) { return(System.Tuple.Create(entry.PartitionKey, entry.RowKey)); }