public async Task Upsert_ExistingItemIsUpsertedInOneInstanceAndNotSaved_ShouldBeUnaffectedInOtherInstances()
      {
         var secondStorageProvider = new InMemoryTableStorageProvider();
         var item = new SimpleDataItem
                          {
                             FirstType = "first"
                          };

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

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

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

         Assert.AreEqual( "first", result.FirstType );
      }
      public async Task AddItem_TwoMemoryContexts_ThePrimaryContextsUncommitedStoreShouldBeUnchangedWhenAnotherIsCreated()
      {
         InMemoryTableStorageProvider.ResetAllTables();
         var firstContext = new InMemoryTableStorageProvider();

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

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

         new InMemoryTableStorageProvider();

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

         Assert.AreEqual( expectedItem.FirstType, item.FirstType );
         Assert.AreEqual( expectedItem.SecondType, item.SecondType );
      }
      public async Task Upsert_UpsertAndCallingSaveAfterTryingToReadFromTheTable_ShouldActuallyInsert()
      {
         var simpleItem = new SimpleDataItem
         {
            FirstType = "first"
         };

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


         _tableStorageProvider.Upsert( _tableName, simpleItem, _partitionKey, _rowKey );
         await _tableStorageProvider.SaveAsync();

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

         Assert.AreEqual( simpleItem.FirstType, actualDataItem.FirstType );
      }
      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 );
      }
      public async Task 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 );
         await firstTableStorageProvider.SaveAsync();

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

         Assert.AreEqual( expectedItem.FirstType, item.FirstType );
         Assert.AreEqual( expectedItem.SecondType, item.SecondType );
      }
      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 ) );
      }
      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 );
      }
      public async Task Delete_ItemExistsAndTwoInstancesTryToDelete_ItemIsNotFoundInEitherCase()
      {
         var dataItem = new SimpleDataItem();
         _tableStorageProvider.Add( _tableName, dataItem, _partitionKey, _rowKey );
         await _tableStorageProvider.SaveAsync();

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

         firstTableStorageProvider.Delete( _tableName, _partitionKey, _rowKey );
         await firstTableStorageProvider.SaveAsync();
         secondTableStorageProvider.Delete( _tableName, _partitionKey, _rowKey );
         await secondTableStorageProvider.SaveAsync();


         bool instanceOneExisted = false;
         bool instanceTwoExisted = false;

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

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

         Assert.IsFalse( instanceOneExisted );
         Assert.IsFalse( instanceTwoExisted );
      }