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()); }
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() ); }
public void Delete_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 ); } _tableStorageProvider.Save( Execute.InBatches ); for ( int i = 0; i < expectedCount; i++ ) { _tableStorageProvider.Delete( _tableName, partitionKey, i.ToString( CultureInfo.InvariantCulture ) ); } _tableStorageProvider.Save( Execute.InBatches ); IEnumerable<DecoratedItem> items = _tableStorageProvider.GetCollection<DecoratedItem>( _tableName, partitionKey ); Assert.IsFalse( items.Any() ); }
public async Task Update_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); for (int i = 0; i < expectedCount; i++) { var item = await _tableStorageProvider.GetAsync <DecoratedItem>(_tableName, partitionKey, i.ToString(CultureInfo.InvariantCulture)); item.Age = 101; _tableStorageProvider.Update(_tableName, item); } await _tableStorageProvider.SaveAsync(Execute.InBatches); IEnumerable <DecoratedItem> items = (await _tableStorageProvider.CreateQuery <DecoratedItem>(_tableName).PartitionKeyEquals(partitionKey).Async()).ToList(); Assert.AreEqual(expectedCount, items.Count()); Assert.IsFalse(items.Any(i => i.Age != 101)); }
public async Task GetAsync_RetrievingObjectViaDynamic_ShouldHydrateEntityWithAllProperties() { var simpleEntity = new DecoratedItem { Id = string.Format("Dynamic{0}", DateTime.Now.Ticks), Name = "Test", Age = 1 }; _tableStorageProvider.Add(_tableName, simpleEntity); await _tableStorageProvider.SaveAsync(); var retrievedObject = await _tableStorageProvider.GetAsync(_tableName, simpleEntity.Id, simpleEntity.Name); Assert.AreEqual(simpleEntity.Age, (int)retrievedObject.Age); Assert.AreEqual(simpleEntity.Id, retrievedObject.PartitionKey); Assert.AreEqual(simpleEntity.Name, retrievedObject.RowKey); }
public void GetRange_RetrievingObjectViaDynamic_ShouldHydrateEntitiesWithAllProperties() { Enumerable.Range( 0, 10 ).ToList().ForEach( i => { var simpleEntity = new DecoratedItem { Id = string.Format( "Dynamic_{0}", i ), Name = "Test", Age = 1 }; _tableStorageProvider.Add( _tableName, simpleEntity ); _tableStorageProvider.Save(); } ); var result = _tableStorageProvider.GetRangeByPartitionKey( _tableName, "Dynamic_2", "Dynamic_6" ); Assert.AreEqual( 5, result.Count() ); Assert.AreEqual( 1, (int) result.First().Age ); }
public async Task GetRange_RetrievingObjectViaDynamic_ShouldHydrateEntitiesWithAllProperties() { foreach (int i in Enumerable.Range(0, 10)) { var simpleEntity = new DecoratedItem { Id = string.Format("Dynamic_{0}", i), Name = "Test", Age = 1 }; _tableStorageProvider.Add(_tableName, simpleEntity); await _tableStorageProvider.SaveAsync(); } var result = await _tableStorageProvider.CreateQuery(_tableName).PartitionKeyFrom("Dynamic_2").Inclusive().PartitionKeyTo("Dynamic_6").Inclusive().Async(); Assert.AreEqual(5, result.Count()); Assert.AreEqual(1, (int)result.First().Age); }
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() ); }
public void Get_RetrievingObjectViaDynamic_ShouldHydrateEntityWithAllProperties() { var simpleEntity = new DecoratedItem { Id = string.Format( "Dynamic{0}", DateTime.Now.Ticks ), Name = "Test", Age = 1 }; _tableStorageProvider.Add( _tableName, simpleEntity ); _tableStorageProvider.Save(); var retrievedObject = _tableStorageProvider.Get( _tableName, simpleEntity.Id, simpleEntity.Name ); Assert.AreEqual( simpleEntity.Age, (int) retrievedObject.Age ); Assert.AreEqual( simpleEntity.Id, retrievedObject.PartitionKey ); Assert.AreEqual( simpleEntity.Name, retrievedObject.RowKey ); }
public void Upsert_ItemExistsAndHasPartitionAndRowKeys_ItemIsUpdated() { var item = new DecoratedItem { Id = "foo2", Name = "bar2", Age = 42 }; _tableStorageProvider.Add( _tableName, item ); _tableStorageProvider.Save(); var upsertedItem = new DecoratedItem { Id = "foo2", Name = "bar2", Age = 34 }; _tableStorageProvider.Upsert( _tableName, upsertedItem ); _tableStorageProvider.Save(); upsertedItem = _tableStorageProvider.Get<DecoratedItem>( _tableName, "foo2", "bar2" ); Assert.AreEqual( 34, upsertedItem.Age ); }
public void Update_ThreeSeparateUpdatesOfSameElement_ShouldSucceed() { var item = new DecoratedItem { Id = "foo", Name = "bar", Age = 42 }; _tableStorageProvider.Add( _tableName, item ); _tableStorageProvider.Save(); var updatedItem = new DecoratedItem { Id = "foo", Name = "bar", Age = 34 }; _tableStorageProvider.Update( _tableName, updatedItem ); updatedItem.Age = 11; _tableStorageProvider.Update( _tableName, updatedItem ); updatedItem.Age = 22; _tableStorageProvider.Update( _tableName, updatedItem ); _tableStorageProvider.Save(); updatedItem = _tableStorageProvider.Get<DecoratedItem>( _tableName, "foo", "bar" ); Assert.AreEqual( 22, updatedItem.Age ); }
public void Upsert_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.Upsert( _tableName, item ); } _tableStorageProvider.Save( Execute.InBatches ); IEnumerable<DecoratedItem> items = _tableStorageProvider.GetCollection<DecoratedItem>( _tableName, partitionKey ).ToList(); Assert.AreEqual( expectedCount, items.Count() ); }
public void Delete_ItemWithoutETagHasBeenChanged_RespectsTheDelete() { var item = new DecoratedItem { Id = "foo", Name = "bar", Age = 12 }; _tableStorageProvider.Add( _tableName, item ); _tableStorageProvider.Save(); var storedItem = _tableStorageProvider.Get<DecoratedItem>( _tableName, "foo", "bar" ); storedItem.Age = 33; _tableStorageProvider.Update( _tableName, storedItem ); _tableStorageProvider.Save(); _tableStorageProvider.Delete( _tableName, storedItem ); _tableStorageProvider.Save(); var items = _tableStorageProvider.GetCollection<TypeWithStringProperty>( _tableName, _partitionKey ); Assert.IsFalse( items.Any() ); }
public async Task Delete_ItemWithoutETagHasBeenChanged_RespectsTheDelete() { var item = new DecoratedItem { Id = "foo", Name = "bar", Age = 12 }; _tableStorageProvider.Add( _tableName, item ); await _tableStorageProvider.SaveAsync(); var storedItem = await _tableStorageProvider.GetAsync<DecoratedItem>( _tableName, "foo", "bar" ); storedItem.Age = 33; _tableStorageProvider.Update( _tableName, storedItem ); await _tableStorageProvider.SaveAsync(); _tableStorageProvider.Delete( _tableName, storedItem ); await _tableStorageProvider.SaveAsync(); var items = ( await _tableStorageProvider.CreateQuery<TypeWithStringProperty>( _tableName ).PartitionKeyEquals( _partitionKey ).Async() ); Assert.IsFalse( items.Any() ); }
public async Task Update_ItemExistsAndHasPartitionAndRowKeyProperties_ItemIsUpdated() { var item = new DecoratedItem { Id = "foo", Name = "bar", Age = 42 }; _tableStorageProvider.Add( _tableName, item ); await _tableStorageProvider.SaveAsync(); var updatedItem = new DecoratedItem { Id = "foo", Name = "bar", Age = 34 }; _tableStorageProvider.Update( _tableName, updatedItem ); await _tableStorageProvider.SaveAsync(); updatedItem = await _tableStorageProvider.GetAsync<DecoratedItem>( _tableName, "foo", "bar" ); Assert.AreEqual( 34, updatedItem.Age ); }
public async Task GetRange_RetrievingObjectViaDynamic_ShouldHydrateEntitiesWithAllProperties() { foreach ( int i in Enumerable.Range( 0, 10 ) ) { var simpleEntity = new DecoratedItem { Id = string.Format( "Dynamic_{0}", i ), Name = "Test", Age = 1 }; _tableStorageProvider.Add( _tableName, simpleEntity ); await _tableStorageProvider.SaveAsync(); } var result = await _tableStorageProvider.CreateQuery( _tableName ).PartitionKeyFrom( "Dynamic_2" ).Inclusive().PartitionKeyTo( "Dynamic_6" ).Inclusive().Async(); Assert.AreEqual( 5, result.Count() ); Assert.AreEqual( 1, (int) result.First().Age ); }