public async Task SaveAsync_TooManyOperationsForEGT_ThrowsInvalidOperationException() { string partitionKey = "123"; _tableStorageProvider.Add(_tableName, new DecoratedItem { Id = partitionKey, Name = "200" }); await _tableStorageProvider.SaveAsync(); int expectedCount = 100; for (int i = 0; i < expectedCount; i++) { var item = new DecoratedItem { Id = partitionKey, Name = i.ToString(CultureInfo.InvariantCulture) }; _tableStorageProvider.Add(_tableName, item); } // this next insert should fail, canceling the whole transaction _tableStorageProvider.Add(_tableName, new DecoratedItem { Id = partitionKey, Name = "200" }); try { await _tableStorageProvider.SaveAsync(Execute.Atomically); Assert.Fail("Should have thrown exception"); } catch (InvalidOperationException) { } Assert.AreEqual(1, (await _tableStorageProvider.CreateQuery <DecoratedItem>(_tableName).PartitionKeyEquals(partitionKey).Async()).Count()); }
private async Task <List <T> > GetAllEntitiesFromPartitionAsync <T>(string tableName, string partitionName) where T : Model.ITableEntity, new() { List <T> result = new List <T>(); var tableStorage = new AzureTableStorageProvider(storageAccount); string lastRowKey = string.Empty; while (true) { IEnumerable <T> entities = null; if (string.IsNullOrEmpty(lastRowKey)) { entities = await tableStorage .CreateQuery <T>(tableName) .PartitionKeyEquals(partitionName) .Top(1000).Async(); } else { entities = await tableStorage .CreateQuery <T>(tableName) .PartitionKeyEquals(partitionName) .RowKeyFrom(lastRowKey).Exclusive() .Top(1000).Async(); } result.AddRange(entities); if (entities.Count() < 1000) { break; } else { lastRowKey = entities.Last().RowKey; } } return(result); }
internal async Task <VersionRow> GetLastVersion() { var tableStorage = new AzureTableStorageProvider(storageAccount); var topVersion = await tableStorage.CreateQuery <VersionRow>(VersionsTableName).Top(1).Async(); if (topVersion.Any()) { return(topVersion.First()); } return(null); }
public async Task Insert_101EntitiesInTheSamePartition_ShouldSucceed() { string partitionKey = "123"; int expectedCount = 101; for (int i = 0; i < expectedCount; i++) { var item = new DecoratedItem { Id = partitionKey, Name = i.ToString(CultureInfo.InvariantCulture) }; _tableStorageProvider.Add(_tableName, item); } await _tableStorageProvider.SaveAsync(Execute.InBatches); IEnumerable <DecoratedItem> items = (await _tableStorageProvider.CreateQuery <DecoratedItem>(_tableName).PartitionKeyEquals(partitionKey).Async()); Assert.AreEqual(expectedCount, items.Count()); }
internal async Task <List <VersionRow> > GetLastVersions(int count) { var tableStorage = new AzureTableStorageProvider(storageAccount); return((await tableStorage.CreateQuery <VersionRow>(VersionsTableName).Top(count).Async()).ToList()); }