Inheritance: TableStorageProvider
Exemplo n.º 1
0
        public void AddItem_TwoMemoryContextsAndItemAddedButNotSavedInFirstContext_TheSecondContextWontSeeAddedItem()
        {
            InMemoryTableStorageProvider.ResetAllTables();

             var firstTableStorageProvider = new InMemoryTableStorageProvider();
             var secondTableStorageProvider = new InMemoryTableStorageProvider();

             firstTableStorageProvider.Add( _tableName, new SimpleDataItem
                                        {
                                           FirstType = "a",
                                           SecondType = 1
                                        }, _partitionKey, _rowKey );

             secondTableStorageProvider.Get<SimpleDataItem>( _tableName, _partitionKey, _rowKey );
        }
Exemplo n.º 2
0
        public void Upsert_UpsertAndCallingSaveAfterTryingToReadFromTheTable_ShouldActuallyInsert()
        {
            var simpleItem = new SimpleDataItem
             {
            FirstType = "first"
             };

             try
             {
            _tableStorageProvider.Get<SimpleDataItem>( _tableName, "DoNotCare", "DoNotCare" );
             }
             catch ( EntityDoesNotExistException )
             {
             }

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

             var actualDataItem = new InMemoryTableStorageProvider().Get<SimpleDataItem>( _tableName, _partitionKey, _rowKey );

             Assert.AreEqual( simpleItem.FirstType, actualDataItem.FirstType );
        }
Exemplo n.º 3
0
        public void AddItem_TwoMemoryContexts_ThePrimaryContextsUncommitedStoreShouldBeUnchangedWhenAnotherIsCreated()
        {
            InMemoryTableStorageProvider.ResetAllTables();
             var firstContext = new InMemoryTableStorageProvider();

             var expectedItem = new SimpleDataItem
                              {
                                 FirstType = "a",
                                 SecondType = 1
                              };

             firstContext.Add( _tableName, expectedItem, _partitionKey, _rowKey );
             firstContext.Save();

             new InMemoryTableStorageProvider();

             var item = firstContext.Get<SimpleDataItem>( _tableName, _partitionKey, _rowKey );

             Assert.AreEqual( expectedItem.FirstType, item.FirstType );
             Assert.AreEqual( expectedItem.SecondType, item.SecondType );
        }
Exemplo n.º 4
0
        public void Upsert_ExistingItemIsUpsertedInOneInstanceAndNotSaved_ShouldBeUnaffectedInOtherInstances()
        {
            var secondStorageProvider = new InMemoryTableStorageProvider();
             var item = new SimpleDataItem
                          {
                             FirstType = "first"
                          };

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

             item.FirstType = "second";
             _tableStorageProvider.Upsert( _tableName, item, _partitionKey, _rowKey );

             var result = secondStorageProvider.Get<SimpleDataItem>( _tableName, _partitionKey, _rowKey );

             Assert.AreEqual( "first", result.FirstType );
        }
Exemplo n.º 5
0
        public void Delete_ItemExistsAndTwoInstancesTryToDelete_ItemIsNotFoundInEitherCase()
        {
            var dataItem = new SimpleDataItem();
             _tableStorageProvider.Add( _tableName, dataItem, _partitionKey, _rowKey );
             _tableStorageProvider.Save();

             var firstTableStorageProvider = new InMemoryTableStorageProvider();
             var secondTableStorageProvider = new InMemoryTableStorageProvider();

             firstTableStorageProvider.Delete( _tableName, _partitionKey, _rowKey );
             firstTableStorageProvider.Save();
             secondTableStorageProvider.Delete( _tableName, _partitionKey, _rowKey );
             secondTableStorageProvider.Save();

             bool instanceOneExisted = false;
             bool instanceTwoExisted = false;

             try
             {
            firstTableStorageProvider.Get<SimpleDataItem>( _tableName, _partitionKey, _rowKey );
            instanceOneExisted = true;
             }
             catch ( EntityDoesNotExistException )
             {
             }

             try
             {
            secondTableStorageProvider.Get<SimpleDataItem>( _tableName, _partitionKey, _rowKey );
            instanceTwoExisted = true;
             }
             catch ( EntityDoesNotExistException )
             {
             }

             Assert.IsFalse( instanceOneExisted );
             Assert.IsFalse( instanceTwoExisted );
        }
Exemplo n.º 6
0
        public void Delete_ItemExistsInAnotherInstancesTempStore_ItemIsNotDeleted()
        {
            var dataItem = new SimpleDataItem();
             var secondTableStorageProvider = new InMemoryTableStorageProvider();
             secondTableStorageProvider.Add( _tableName, dataItem, _partitionKey, _rowKey );

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

             secondTableStorageProvider.Save();

             var instance = secondTableStorageProvider.Get<SimpleDataItem>( _tableName, _partitionKey, _rowKey );
             Assert.IsNotNull( instance );
        }
Exemplo n.º 7
0
        public void GetCollection_ItemInAnotherInstance_EnumerableWithNoItemsReturned()
        {
            _tableStorageProvider.Add( _tableName, new SimpleDataItem
             {
            FirstType = "a",
            SecondType = 1
             }, _partitionKey, _rowKey );
             var secondStorageProvider = new InMemoryTableStorageProvider();

             var result = secondStorageProvider.GetCollection<SimpleDataItem>( _tableName, _partitionKey );

             Assert.AreEqual( 0, result.Count() );
        }
Exemplo n.º 8
0
        public void AddItem_TwoMemoryContexts_TheSecondContextWillSeeAddedAndSavedItem()
        {
            InMemoryTableStorageProvider.ResetAllTables();
             var firstTableStorageProvider = new InMemoryTableStorageProvider();
             var secondTableStorageProvider = new InMemoryTableStorageProvider();

             var expectedItem = new SimpleDataItem
                              {
                                 FirstType = "a",
                                 SecondType = 1
                              };

             firstTableStorageProvider.Add( _tableName, expectedItem, _partitionKey, _rowKey );
             firstTableStorageProvider.Save();

             var item = secondTableStorageProvider.Get<SimpleDataItem>( _tableName, _partitionKey, _rowKey );

             Assert.AreEqual( expectedItem.FirstType, item.FirstType );
             Assert.AreEqual( expectedItem.SecondType, item.SecondType );
        }
Exemplo n.º 9
0
        public void QueryByPartitionKeyRange_ItemsInRange_ReturnsItems()
        {
            var items = new[]
                     {
                        new DecoratedItem { Id = "abc", Name = "123", Age = 42 },
                        new DecoratedItem { Id = "abd", Name = "456", Age = 43 },
                        new DecoratedItem { Id = "bcd", Name = "556", Age = 44 },
                     };
             foreach ( var item in items )
             {
            _context.AddNewItem( "table", TableItem.Create( item ) );
             }
             _context.Save( Execute.Individually );

             var tsp = new InMemoryTableStorageProvider();
             var result = _context.CreateQuery( "table", false )
                              .PartitionKeyFrom( tsp.MinimumKeyValue ).Inclusive()
                              .PartitionKeyTo( "bcc" ).Inclusive();

             Assert.AreEqual( 2, result.Count() );
        }
Exemplo n.º 10
0
      public async Task AddItem_TwoMemoryContexts_TheSecondContextWillNotSeeAddedAndSavedItem_WithInstanceAccount()
      {
         InMemoryTableStorageProvider.ResetAllTables();
         var firstTableStorageProvider = new InMemoryTableStorageProvider( new MemoryStorageAccount() );
         var secondTableStorageProvider = new InMemoryTableStorageProvider( new MemoryStorageAccount() );

         var expectedItem = new SimpleDataItem
         {
            FirstType = "a",
            SecondType = 1
         };

         firstTableStorageProvider.Add( _tableName, expectedItem, _partitionKey, _rowKey );
         await firstTableStorageProvider.SaveAsync();

         bool hasThrown = false;
         try
         {
            await secondTableStorageProvider.GetAsync<SimpleDataItem>( _tableName, _partitionKey, _rowKey );
         }
         catch ( EntityDoesNotExistException )
         {
            hasThrown = true;
         }

         Assert.IsTrue( hasThrown );
      }
Exemplo n.º 11
0
      public async Task AddItem_TwoMemoryContextsAndItemAddedButNotSavedInFirstContext_TheSecondContextWontSeeAddedItem()
      {
         InMemoryTableStorageProvider.ResetAllTables();

         var firstTableStorageProvider = new InMemoryTableStorageProvider();
         var secondTableStorageProvider = new InMemoryTableStorageProvider();

         firstTableStorageProvider.Add( _tableName, new SimpleDataItem
                                        {
                                           FirstType = "a",
                                           SecondType = 1
                                        }, _partitionKey, _rowKey );

         await AsyncAssert.ThrowsAsync<EntityDoesNotExistException>( () => secondTableStorageProvider.GetAsync<SimpleDataItem>( _tableName, _partitionKey, _rowKey ) );
      }
Exemplo n.º 12
0
      public async Task Delete_ItemExistsAndIsDeletedButNotSaved_ItemExistsInAnotherInstance()
      {
         var secondTableStorageProvider = new InMemoryTableStorageProvider();
         var dataItem = new SimpleDataItem();
         _tableStorageProvider.Add( _tableName, dataItem, _partitionKey, _rowKey );
         await _tableStorageProvider.SaveAsync();

         _tableStorageProvider.Delete( _tableName, _partitionKey, _rowKey );
         var instance = await secondTableStorageProvider.GetAsync<SimpleDataItem>( _tableName, _partitionKey, _rowKey );

         Assert.IsNotNull( instance );
      }
Exemplo n.º 13
0
      public async Task QueryAsyncByPartitionKeyRangeWithTop_ItemsInRange_ReturnsTopItem()
      {
         var items = new[]
                     {
                        new DecoratedItem { Id = "abc", Name = "123", Age = 42 },
                        new DecoratedItem { Id = "abd", Name = "456", Age = 43 },
                        new DecoratedItem { Id = "bcd", Name = "556", Age = 44 },
                     };
         foreach ( var item in items )
         {
            _context.AddNewItem( "table", TableItem.Create( item ) );
         }
         await _context.SaveAsync( Execute.Individually );

         var tsp = new InMemoryTableStorageProvider();
         var result = _context.CreateQuery( "table", false )
                              .PartitionKeyFrom( tsp.MinimumKeyValue ).Inclusive()
                              .PartitionKeyTo( "bcc" ).Inclusive()
                              .Top( 1 )
                              .Async().Result;

         Assert.AreEqual( 1, result.Count() );
         string actualName = result.Single().RowKey;
         Assert.AreEqual( "123", actualName );
      }