Ejemplo n.º 1
0
        public void Create_DecoratedItemWithoutETag_TableItemDoesNotIncludeETag()
        {
            var decoratedItem = new DecoratedItem
            {
                Id   = "foo",
                Name = "bar",
                Age  = 42
            };

            var item = TableItem.Create(decoratedItem);

            Assert.IsNull(item.ETag);
        }
Ejemplo n.º 2
0
        public void Hydrate_ItemDecoratedWithRowAndPartitionKeyAttributes_ReturnedGenericEntityHasCorrectProperties()
        {
            var itemToSave = new DecoratedItem
                          {
                             Id = "id",
                             Name = "name",
                             Age = 42,
                          };
             var genericEntity = GenericEntity.HydrateFrom( itemToSave );

             Assert.AreEqual( "id", genericEntity.PartitionKey, "incorrect partition key" );
             Assert.AreEqual( "name", genericEntity.RowKey, "incorrect row key" );
             Assert.IsFalse( genericEntity.GetProperties().ContainsKey( "Id" ), "partition key property should not be serialized as separate property" );
             Assert.IsFalse( genericEntity.GetProperties().ContainsKey( "Name" ), "row key property should not be serialized as separate property" );
        }
Ejemplo n.º 3
0
        public void Hydrate_ItemDecoratedWithRowAndPartitionKeyAttributes_ReturnedGenericTableEntityHasCorrectProperties()
        {
            var itemToSave = new DecoratedItem
            {
                Id   = "id",
                Name = "name",
                Age  = 42,
            };
            TableItem tableItem     = TableItem.Create(itemToSave);
            var       genericEntity = GenericTableEntity.HydrateFrom(tableItem);

            Assert.AreEqual("id", genericEntity.PartitionKey, "incorrect partition key");
            Assert.AreEqual("name", genericEntity.RowKey, "incorrect row key");
            Assert.IsFalse(genericEntity.WriteEntity(null).ContainsKey("Id"), "partition key property should not be serialized as separate property");
            Assert.IsFalse(genericEntity.WriteEntity(null).ContainsKey("Name"), "row key property should not be serialized as separate property");
        }
Ejemplo n.º 4
0
      public async Task SaveAsync_ItemAdded_QueryReturnsTheItem()
      {
         var item = new DecoratedItem
         {
            Id = "abc",
            Name = "123",
            Age = 50
         };
         var entity = TableItem.Create( item );
         _context.AddNewItem( "table", entity );
         await _context.SaveAsync( Execute.Individually );

         var returnedItem = (await _context.CreateQuery<DecoratedItem>( "table" ).PartitionKeyEquals( "abc" ).RowKeyEquals( "123" ).Async() ).Single();
         Assert.AreEqual( item.Id, returnedItem.Id );
         Assert.AreEqual( item.Name, returnedItem.Name );
         Assert.AreEqual( item.Age, returnedItem.Age );
      }
Ejemplo n.º 5
0
        public void CreateQuery_ItemAddedAndSavedWithDifferentContext_ReturnsItem()
        {
            var addedItem = new DecoratedItem
             {
            Id = "abc",
            Name = "123",
            Age = 50
             };
             var entity = TableItem.Create( addedItem );
             _context.AddNewItem( "table", entity );
             _context.Save( Execute.Individually );

             var returnedItem = _context.CreateQuery<DecoratedItem>( "table" ).PartitionKeyEquals( "abc" ).RowKeyEquals( "123" ).Single();
             Assert.AreEqual( addedItem.Id, returnedItem.Id );
             Assert.AreEqual( addedItem.Name, returnedItem.Name );
             Assert.AreEqual( addedItem.Age, returnedItem.Age );
        }
Ejemplo n.º 6
0
        public async Task GetAsync_ObjectInsertedWithClassAndRetrievedViaDynamic_ShouldReturnFullyHydratedObject()
        {
            var simpleEntity = new DecoratedItem
            {
                Id   = string.Format("Dynamic{0}", DateTime.Now.Ticks),
                Name = "Test",
                Age  = 1
            };

            _tableStorageProvider.Add(_tableName, simpleEntity);

            await _tableStorageProvider.SaveAsync();

            var result = await _tableStorageProvider.GetAsync(_tableName, simpleEntity.Id, simpleEntity.Name);

            Assert.AreEqual(simpleEntity.Age, result.Age);
            Assert.AreEqual(simpleEntity.Id, result.PartitionKey);
            Assert.AreEqual(simpleEntity.Name, result.RowKey);
        }
Ejemplo n.º 7
0
        public void Get_ObjectInsertedWithClassAndRetrievedViaDynamic_ShouldReturnFullyHydratedObject()
        {
            var simpleEntity = new DecoratedItem
             {
            Id = string.Format( "Dynamic{0}", DateTime.Now.Ticks ),
            Name = "Test",
            Age = 1
             };

             _tableStorageProvider.Add( _tableName, simpleEntity );

             _tableStorageProvider.Save();

             var result = _tableStorageProvider.Get( _tableName, simpleEntity.Id, simpleEntity.Name );

             Assert.AreEqual( simpleEntity.Age, result.Age );
             Assert.AreEqual( simpleEntity.Id, result.PartitionKey );
             Assert.AreEqual( simpleEntity.Name, result.RowKey );
        }
Ejemplo n.º 8
0
      public async Task ResetAllTables_ContextCreatedBeforeCallingReset_ExistingContextStillWorks()
      {
         var localContext = new MemoryTableContext();
         MemoryTableContext.ResetAllTables();
         _context = new MemoryTableContext();

         var item = new DecoratedItem
         {
            Id = "abc",
            Name = "123",
            Age = 50
         };
         var entity = TableItem.Create( item );
         _context.AddNewItem( "table", entity );
         await _context.SaveAsync( Execute.Individually );


         var returnedItem = (await localContext.CreateQuery<DecoratedItem>( "table" ).PartitionKeyEquals( "abc" ).RowKeyEquals( "123" ).Async() ).Single();
         Assert.AreEqual( item.Id, returnedItem.Id );
         Assert.AreEqual( item.Name, returnedItem.Name );
         Assert.AreEqual( item.Age, returnedItem.Age );
      }
Ejemplo n.º 9
0
        public void GetCollection_ObjectInsertedWithClassAndRetrievedViaDynamic_ShouldReturnFullyHydratedObjects()
        {
            string partitionKey = "Test";
             Enumerable.Range( 0, 10 ).ToList().ForEach( i =>
             {
            var simpleEntity = new DecoratedItem
            {
               Id = partitionKey,
               Name = string.Format( "Dynamic{0}_{1}", DateTime.Now.Ticks, i ),
               Age = 1
            };

            _tableStorageProvider.Add( _tableName, simpleEntity );

            _tableStorageProvider.Save();
             } );

             var result = _tableStorageProvider.GetCollection( _tableName, partitionKey );

             Assert.AreEqual( 10, result.Count() );
             Assert.AreEqual( 1, result.First().Age );
        }
Ejemplo n.º 10
0
      public async Task GetCollection_ObjectInsertedWithClassAndRetrievedViaDynamic_ShouldReturnFullyHydratedObjects()
      {
         string partitionKey = "Test";
         foreach ( var i in Enumerable.Range( 0, 10 ) )
         {
            var simpleEntity = new DecoratedItem
            {
               Id = partitionKey,
               Name = string.Format( "Dynamic{0}_{1}", DateTime.Now.Ticks, i ),
               Age = 1
            };

            _tableStorageProvider.Add( _tableName, simpleEntity );

            await _tableStorageProvider.SaveAsync();
         }

         var result = await _tableStorageProvider.CreateQuery( _tableName ).PartitionKeyEquals( partitionKey ).Async();

         Assert.AreEqual( 10, result.Count() );
         Assert.AreEqual( 1, result.First().Age );
      }
Ejemplo n.º 11
0
        public async Task GetCollection_ObjectInsertedWithClassAndRetrievedViaDynamic_ShouldReturnFullyHydratedObjects()
        {
            string partitionKey = "Test";

            foreach (var i in Enumerable.Range(0, 10))
            {
                var simpleEntity = new DecoratedItem
                {
                    Id   = partitionKey,
                    Name = string.Format("Dynamic{0}_{1}", DateTime.Now.Ticks, i),
                    Age  = 1
                };

                _tableStorageProvider.Add(_tableName, simpleEntity);

                await _tableStorageProvider.SaveAsync();
            }

            var result = await _tableStorageProvider.CreateQuery(_tableName).PartitionKeyEquals(partitionKey).Async();

            Assert.AreEqual(10, result.Count());
            Assert.AreEqual(1, result.First().Age);
        }
Ejemplo n.º 12
0
        public void Save_ItemAdded_GetItemReturnsTheItem()
        {
            var item = new DecoratedItem { Id = "abc", Name = "123", Age = 50 };
             var entity = TableItem.Create( item );
             _context.AddNewItem( "table", entity );
             _context.Save( Execute.Individually );

             var returnedItem = _context.GetItem<DecoratedItem>( "table", "abc", "123" );
             Assert.AreEqual( item.Id, returnedItem.Id );
             Assert.AreEqual( item.Name, returnedItem.Name );
             Assert.AreEqual( item.Age, returnedItem.Age );
        }
Ejemplo n.º 13
0
        public void GetItem_ItemAddedToDifferentTable_ThrowsEntityDoesNotExistException()
        {
            var addedItem = new DecoratedItem { Id = "abc", Name = "123", Age = 50 };
             var entity = TableItem.Create( addedItem );
             _context.AddNewItem( "table", entity );
             _context.Save( Execute.Individually );

             try
             {
            _context.GetItem<DecoratedItem>( "diffTable", "abc", "123" );
            Assert.Fail( "Should have thrown exception" );
             }
             catch ( EntityDoesNotExistException )
             {
             }
        }
Ejemplo n.º 14
0
        public void GetItem_ItemAddedAndSavedWithDifferentContext_ReturnsItem()
        {
            var addedItem = new DecoratedItem { Id = "abc", Name = "123", Age = 50 };
             var entity = TableItem.Create( addedItem );
             _context.AddNewItem( "table", entity );
             _context.Save( Execute.Individually );

             var returnedItem = new MemoryTableContext().GetItem<DecoratedItem>( "table", "abc", "123" );
             Assert.AreEqual( addedItem.Id, returnedItem.Id );
             Assert.AreEqual( addedItem.Name, returnedItem.Name );
             Assert.AreEqual( addedItem.Age, returnedItem.Age );
        }
Ejemplo n.º 15
0
        public void CreateQuery_ItemAddedToDifferentTable_QueryDoesNotReturnEntity()
        {
            var addedItem = new DecoratedItem
             {
            Id = "abc",
            Name = "123",
            Age = 50
             };
             var entity = TableItem.Create( addedItem );
             _context.AddNewItem( "table", entity );
             _context.Save( Execute.Individually );

             var returnedItem = _context.CreateQuery<DecoratedItem>( "table" ).PartitionKeyEquals( "abc" ).RowKeyEquals( "123" ).SingleOrDefault();
             Assert.IsNotNull( returnedItem );
        }
Ejemplo n.º 16
0
      public async Task GetAsync_RetreiveAsDynamic_DynamicItemHasETagProperty()
      {
         var decoratedItem = new DecoratedItem
         {
            Id = "id",
            Name = "name",
            Age = 33
         };

         _tableStorageProvider.Add( _tableName, decoratedItem );
         await _tableStorageProvider.SaveAsync();

         _tableStorageProvider.ShouldIncludeETagWithDynamics = true;

         var actualItem = await _tableStorageProvider.GetAsync( _tableName, "id", "name" );
         var itemAsDict = actualItem as IDictionary<string, object>;
         Assert.IsTrue( itemAsDict.ContainsKey( "ETag" ) );
      }
Ejemplo n.º 17
0
        public void QueryForDynamic_ShouldIncludeETag_ResultingDynamicHasETag()
        {
            var item = new DecoratedItem
             {
            Id = "foo",
            Name = "bar"
             };
             _context.AddNewItem( "table", TableItem.Create( item ) );
             _context.Save( Execute.Individually );

             var result = _context.CreateQuery( "table", true ).PartitionKeyEquals( "foo" ).RowKeyEquals( "bar" );
             var asDict = (IDictionary<string, object>) result.First();

             Assert.IsTrue( asDict.ContainsKey( "PartitionKey" ) );
             Assert.IsTrue( asDict.ContainsKey( "RowKey" ) );
             Assert.IsTrue( asDict.ContainsKey( "ETag" ) );
        }
Ejemplo n.º 18
0
      public async Task GetAsync_RetreiveAsDynamic_DynamicItemHasTimestampProperty()
      {
         var decoratedItem = new DecoratedItem
         {
            Id = "id",
            Name = "name",
            Age = 33
         };

         _tableStorageProvider.Add( _tableName, decoratedItem );
         await _tableStorageProvider.SaveAsync();

         var actualItem = await _tableStorageProvider.GetAsync( _tableName, "id", "name" );
         var itemAsDict = actualItem as IDictionary<string, object>;
         Assert.IsTrue( itemAsDict.ContainsKey( "Timestamp" ) );
         Assert.IsTrue( actualItem.Timestamp > DateTimeOffset.MinValue );
      }
Ejemplo n.º 19
0
        public void Create_DecoratedItemWithoutETag_TableItemDoesNotIncludeETag()
        {
            var decoratedItem = new DecoratedItem
             {
            Id = "foo",
            Name = "bar",
            Age = 42
             };

             var item = TableItem.Create( decoratedItem );

             Assert.IsNull( item.ETag );
        }
Ejemplo n.º 20
0
        public void Add_EntityHasPartitionAndRowKeyAttributes_PartitionAndRowKeysSetCorrectly()
        {
            var expected = new DecoratedItem { Id = "foo", Name = "bar", Age = 1 };
             _tableStorageProvider.Add( _tableName, expected );
             _tableStorageProvider.Save();

             var actual = _tableStorageProvider.Get<DecoratedItem>( _tableName, "foo", "bar" );
             Assert.AreEqual( expected.Name, actual.Name );
             Assert.AreEqual( expected.Id, actual.Id );
        }
Ejemplo n.º 21
0
      public async Task Update_MultipleUpdatesFromSingleDynamicEntity_SucceedsRegardlessIfEntityHasBeenChanged()
      {
         var item = new DecoratedItem
         {
            Id = "foo",
            Name = "bar",
            Age = 33
         };
         _tableStorageProvider.Add( _tableName, item );
         await _tableStorageProvider.SaveAsync();

         _tableStorageProvider.ShouldThrowForReservedPropertyNames = false;

         var storedItem = await _tableStorageProvider.GetAsync( _tableName, "foo", "bar" );

         storedItem.Age = 44;
         _tableStorageProvider.Update( _tableName, storedItem );
         await _tableStorageProvider.SaveAsync();

         storedItem.Age = 39;
         _tableStorageProvider.Update( _tableName, storedItem );
         await _tableStorageProvider.SaveAsync();
      }