예제 #1
0
        public void SimpleItemWithDontSerializeAttributeConvertsToGenericTableEntityCorrectly()
        {
            var itemToSave = new SimpleItemWithDontSerializeAttribute
            {
                SerializedString    = "foo",
                NotSerializedString = "bar"
            };
            TableItem tableItem = TableItem.Create(itemToSave, "pk", "rk");

            var genericItemToTest = GenericTableEntity.HydrateFrom(tableItem);


            var wereCool = true;


            wereCool &= itemToSave.SerializedString == genericItemToTest.WriteEntity(null)["SerializedString"].StringValue;

            try
            {
                wereCool &= null == genericItemToTest.WriteEntity(null)["NotSerializedString"].StringValue;
            }
            catch (KeyNotFoundException)
            {
                wereCool &= true;
            }

            wereCool &= genericItemToTest.WriteEntity(null).Count == 1;

            Assert.IsTrue(wereCool);
        }
예제 #2
0
        public void Upsert(string tableName, TableItem tableItem)
        {
            var genericTableEntity = GenericTableEntity.HydrateFrom(tableItem);
            Action <MemoryStorageAccount> action = tables => tables.GetTable(tableName).GetPartition(tableItem.PartitionKey).Upsert(genericTableEntity);

            _pendingActions.Enqueue(new TableAction(action, tableItem.PartitionKey, tableItem.RowKey, tableName));
        }
예제 #3
0
        public void ConvertTo_ItemHasColumnWithNonBoolType_ResultingObjectHasFalsePropertyValue()
        {
            dynamic item = new ExpandoObject();

            item.IsAwesome = "yes!";

            TableItem tableItem   = TableItem.Create(item, "pk", "rk");
            var       tableEntity = GenericTableEntity.HydrateFrom(tableItem);

            Assert.ThrowsException <InvalidOperationException>(() => tableEntity.ConvertTo <TypeWithBoolProperty>());
        }
예제 #4
0
        public void DeleteItem(string tableName, TableItem tableItem, ConflictHandling conflictHandling)
        {
            var genericTableEntity = GenericTableEntity.HydrateFrom(tableItem);

            if (ShouldForceOverwrite(conflictHandling, genericTableEntity))
            {
                genericTableEntity.ETag = "*";
            }
            Action <MemoryStorageAccount> action = tables => tables.GetTable(tableName).GetPartition(tableItem.PartitionKey).Delete(genericTableEntity);

            _pendingActions.Enqueue(new TableAction(action, tableItem.PartitionKey, tableItem.RowKey, tableName));
        }
예제 #5
0
        public void Hydrate_ItemDecoratedWithETagAttribute_ReturnedGenericTableEntityHasETag()
        {
            var itemToSave = new DecoratedItemWithETag
            {
                Id   = "id",
                Name = "name",
                ETag = "etag"
            };
            TableItem tableItem     = TableItem.Create(itemToSave);
            var       genericEntity = GenericTableEntity.HydrateFrom(tableItem);

            Assert.AreEqual("etag", genericEntity.ETag);
        }
예제 #6
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");
        }
예제 #7
0
        public void DynamicItemConvertsToGenericTableEntityCorrectly()
        {
            dynamic itemToSave = new ExpandoObject();

            itemToSave.FirstType  = "foo";
            itemToSave.SecondType = "bar";

            TableItem tableItem = TableItem.Create(itemToSave, "pk", "rk");

            var genericItemToTest = GenericTableEntity.HydrateFrom(tableItem);

            var wereCool = true;

            wereCool &= itemToSave.FirstType == genericItemToTest.WriteEntity(null)["FirstType"].StringValue;
            wereCool &= itemToSave.SecondType == genericItemToTest.WriteEntity(null)["SecondType"].StringValue;

            wereCool &= genericItemToTest.WriteEntity(null).Count == 2;

            Assert.IsTrue(wereCool);
        }
예제 #8
0
        public void SimpleItemConvertsToGenericTableEntityCorrectly()
        {
            var itemToSave = new SimpleDataItem
            {
                FirstType  = "foo",
                SecondType = 0
            };

            TableItem tableItem = TableItem.Create(itemToSave, "pk", "rk");

            var genericItemToTest = GenericTableEntity.HydrateFrom(tableItem);


            var wereCool = true;


            wereCool &= itemToSave.FirstType == genericItemToTest.WriteEntity(null)["FirstType"].StringValue;
            wereCool &= itemToSave.SecondType == genericItemToTest.WriteEntity(null)["SecondType"].Int32Value;
            wereCool &= null == genericItemToTest.WriteEntity(null)["UriTypeProperty"].StringValue;;

            wereCool &= genericItemToTest.WriteEntity(null).Count == 3;

            Assert.IsTrue(wereCool);
        }