示例#1
0
        public async Task AddItem_TypeWithSingleStringProperty_ItemAddedToStore()
        {
            var dataItem = new TypeWithStringProperty
            {
                FirstType = "b"
            };

            _tableStorageProvider.Add(_tableName, dataItem, _partitionKey, _rowKey);
            await _tableStorageProvider.SaveAsync();

            var result = await _tableStorageProvider.GetAsync <TypeWithStringProperty>(_tableName, _partitionKey, _rowKey);

            Assert.AreEqual("b", result.FirstType);
        }
        public void Update_ItemDoesNotExist_ShouldThrowEntityDoesNotExistException()
        {
            var itemToUpdate = new TypeWithStringProperty
             {
            FirstType = "first"
             };

             itemToUpdate.FirstType = "Updated";

             _tableStorageProvider.Update( _tableName, itemToUpdate, _partitionKey, _rowKey );
             _tableStorageProvider.Save();

             Assert.Fail( "Should have thrown EntityDoesNotExistException" );
        }
        public void Get_ItemInStore_ItemReturned()
        {
            var dataItem = new TypeWithStringProperty
             {
            FirstType = "a"
             };
             _tableStorageProvider.Add( _tableName, dataItem, _partitionKey, _rowKey );
             _tableStorageProvider.Save();

             var result = _tableStorageProvider.Get<TypeWithStringProperty>( _tableName, _partitionKey, _rowKey );

             Assert.AreEqual( dataItem.FirstType, result.FirstType );
        }
        public void GetRangeByRowKey_OneItemInStore_EnumerableWithNoItemsReturned()
        {
            var item = new TypeWithStringProperty { FirstType = "a" };
             _tableStorageProvider.Add( _tableName, item, _partitionKey, "hithere" );
             _tableStorageProvider.Save();

             var result = _tableStorageProvider.GetRangeByRowKey<TypeWithStringProperty>( _tableName, _partitionKey, "hi", "hj" );

             Assert.AreEqual( 1, result.Count() );
        }
        public void GetRangeByRowKey_ManyItemsInStore_EnumerableWithAppropriateItemsReturned()
        {
            var item1 = new TypeWithStringProperty { FirstType = "a" };
             var item2 = new TypeWithStringProperty { FirstType = "b" };
             var item3 = new TypeWithStringProperty { FirstType = "c" };
             var item4 = new TypeWithStringProperty { FirstType = "d" };

             _tableStorageProvider.Add( _tableName, item1, _partitionKey, "asdf" );
             _tableStorageProvider.Add( _tableName, item2, _partitionKey, "hithere" );
             _tableStorageProvider.Add( _tableName, item3, _partitionKey, "jklh" );
             _tableStorageProvider.Add( _tableName, item4, _partitionKey, "hi" );
             _tableStorageProvider.Save();

             var result = _tableStorageProvider.GetRangeByRowKey<TypeWithStringProperty>( _tableName, _partitionKey, "hi", "hj" );

             Assert.AreEqual( 2, result.Count() );
        }
        public void Delete_ManyItemsInStore_ItemsDeleted()
        {
            for ( var i = 0; i < 1001; i++ )
             {
            var dataItem = new TypeWithStringProperty
            {
               FirstType = "a" + i
            };

            _tableStorageProvider.Add( _tableName, dataItem, _partitionKey, _rowKey + dataItem.FirstType );
            _tableStorageProvider.Save();
             }

             _tableStorageProvider.DeleteCollection( _tableName, _partitionKey );
             _tableStorageProvider.Save();

             var items = _tableStorageProvider.GetCollection<TypeWithStringProperty>( _tableName, _partitionKey );

             Assert.IsFalse( items.Any() );
        }
        public void Delete_ItemInStore_ItemDeleted()
        {
            var dataItem = new TypeWithStringProperty
             {
            FirstType = "a"
             };

             _tableStorageProvider.Add( _tableName, dataItem, _partitionKey, _rowKey );
             _tableStorageProvider.Save();

             _tableStorageProvider.Delete( _tableName, _partitionKey, _rowKey );
             _tableStorageProvider.Save();

             var items = _tableStorageProvider.GetCollection<TypeWithStringProperty>( _tableName, _partitionKey );

             Assert.IsFalse( items.Any() );
        }
      public async Task Update_ItemDoesNotExist_ShouldThrowEntityDoesNotExistException()
      {
         var itemToUpdate = new TypeWithStringProperty
         {
            FirstType = "first"
         };

         itemToUpdate.FirstType = "Updated";

         _tableStorageProvider.Update( _tableName, itemToUpdate, _partitionKey, _rowKey );

         await AsyncAssert.ThrowsAsync<EntityDoesNotExistException>( () => _tableStorageProvider.SaveAsync() );
      }
        public void AddingItemWithDuplicatePartitionAndRowKey_ExceptionThrown()
        {
            var validType = new TypeWithStringProperty
             {
            FirstType = "DoNotCare"
             };

             _tableStorageProvider.Add( _tableName, validType, _partitionKey, _rowKey );
             _tableStorageProvider.Save();

             _tableStorageProvider.Add( _tableName, validType, _partitionKey, _rowKey );

             _tableStorageProvider.Save();
        }
示例#10
0
      public async Task Delete_ItemInStore_ItemDeleted()
      {
         var dataItem = new TypeWithStringProperty
         {
            FirstType = "a"
         };

         _tableStorageProvider.Add( _tableName, dataItem, _partitionKey, _rowKey );
         await _tableStorageProvider.SaveAsync();

         _tableStorageProvider.Delete( _tableName, _partitionKey, _rowKey );
         await _tableStorageProvider.SaveAsync();

         var items = ( await _tableStorageProvider.CreateQuery<TypeWithStringProperty>( _tableName ).PartitionKeyEquals( _partitionKey ).Async() );

         Assert.IsFalse( items.Any() );
      }
示例#11
0
      public async Task Delete_ManyItemsInStore_ItemsDeleted()
      {
         for ( var i = 0; i < 1001; i++ )
         {
            var dataItem = new TypeWithStringProperty
            {
               FirstType = "a" + i
            };

            _tableStorageProvider.Add( _tableName, dataItem, _partitionKey, _rowKey + dataItem.FirstType );
         }
         await _tableStorageProvider.SaveAsync( Execute.InBatches );


         var itemsToDelete = await _tableStorageProvider.CreateQuery( _tableName ).PartitionKeyEquals( _partitionKey ).Async();
         foreach ( var item in itemsToDelete )
         {
            _tableStorageProvider.Delete( _tableName, item.PartitionKey, item.RowKey );
         }
         await _tableStorageProvider.SaveAsync( Execute.InBatches );

         var items = ( await _tableStorageProvider.CreateQuery<TypeWithStringProperty>( _tableName ).PartitionKeyEquals( _partitionKey ).Async() );

         Assert.IsFalse( items.Any() );
      }
示例#12
0
      public async Task GetAsync_ItemInStore_ItemReturnedByTask()
      {
         var dataItem = new TypeWithStringProperty
         {
            FirstType = "a"
         };
         _tableStorageProvider.Add( _tableName, dataItem, _partitionKey, _rowKey );
         await _tableStorageProvider.SaveAsync();

         var result = _tableStorageProvider.GetAsync<TypeWithStringProperty>( _tableName, _partitionKey, _rowKey );

         Assert.AreEqual( dataItem.FirstType, result.Result.FirstType );
      }
示例#13
0
      public async Task GetRangeByRowKey_ManyItemsInStore_EnumerableWithAppropriateItemsReturned()
      {
         var item1 = new TypeWithStringProperty
         {
            FirstType = "a"
         };
         var item2 = new TypeWithStringProperty
         {
            FirstType = "b"
         };
         var item3 = new TypeWithStringProperty
         {
            FirstType = "c"
         };
         var item4 = new TypeWithStringProperty
         {
            FirstType = "d"
         };

         _tableStorageProvider.Add( _tableName, item1, _partitionKey, "asdf" );
         _tableStorageProvider.Add( _tableName, item2, _partitionKey, "hithere" );
         _tableStorageProvider.Add( _tableName, item3, _partitionKey, "jklh" );
         _tableStorageProvider.Add( _tableName, item4, _partitionKey, "hi" );
         await _tableStorageProvider.SaveAsync();

         var result = await _tableStorageProvider.CreateQuery<TypeWithStringProperty>( _tableName ).PartitionKeyEquals( _partitionKey ).RowKeyFrom( "hi" ).Inclusive().RowKeyTo( "hj" ).Inclusive().Async();

         Assert.AreEqual( 2, result.Count() );
      }
示例#14
0
      public async Task GetRangeByRowKey_OneItemInStore_EnumerableWithNoItemsReturned()
      {
         var item = new TypeWithStringProperty
         {
            FirstType = "a"
         };
         _tableStorageProvider.Add( _tableName, item, _partitionKey, "hithere" );
         await _tableStorageProvider.SaveAsync();

         var result =
            await _tableStorageProvider.CreateQuery<TypeWithStringProperty>( _tableName )
               .PartitionKeyEquals( _partitionKey )
               .RowKeyFrom( "hi" )
               .Inclusive()
               .RowKeyTo( "hj" )
               .Inclusive()
               .Async();

         Assert.AreEqual( 1, result.Count() );
      }
示例#15
0
        public void Upsert_ItemExistsAndIsThenUpdated_ItemIsProperlyUpdated()
        {
            var itemToUpsert = new TypeWithStringProperty
             {
            FirstType = "first"
             };

             _tableStorageProvider.Upsert( _tableName, itemToUpsert, _partitionKey, _rowKey );
             _tableStorageProvider.Save();

             _tableStorageProvider = new AzureTableStorageProvider( _storageAccount );
             itemToUpsert = new TypeWithStringProperty { FirstType = "second" };

             _tableStorageProvider.Upsert( _tableName, itemToUpsert, _partitionKey, _rowKey );
             _tableStorageProvider.Save();

             var itemInTable = _tableStorageProvider.Get<TypeWithStringProperty>( _tableName, _partitionKey, _rowKey );

             Assert.AreEqual( itemToUpsert.FirstType, itemInTable.FirstType );
        }
示例#16
0
        public void AddItem_TypeWithSingleStringProperty_ItemAddedToStore()
        {
            var dataItem = new TypeWithStringProperty
             {
            FirstType = "b"
             };
             _tableStorageProvider.Add( _tableName, dataItem, _partitionKey, _rowKey );
             _tableStorageProvider.Save();

             var result = _tableStorageProvider.Get<TypeWithStringProperty>( _tableName, _partitionKey, _rowKey );
             Assert.AreEqual( "b", result.FirstType );
        }
示例#17
0
        private void EnsureOneItemInTableStorage()
        {
            var item = new TypeWithStringProperty
             {
            FirstType = "first"
             };

             _tableStorageProvider.Add( _tableName, item, _partitionKey, _rowKey );
             _tableStorageProvider.Save();
        }
示例#18
0
      public async Task AddingItemWithDuplicatePartitionAndRowKey_ExceptionThrown()
      {
         var validType = new TypeWithStringProperty
         {
            FirstType = "DoNotCare"
         };

         _tableStorageProvider.Add( _tableName, validType, _partitionKey, _rowKey );
         await _tableStorageProvider.SaveAsync();

         _tableStorageProvider.Add( _tableName, validType, _partitionKey, _rowKey );

         await AsyncAssert.ThrowsAsync<EntityAlreadyExistsException>( () => _tableStorageProvider.SaveAsync() );
      }