Example #1
0
        public void CreateInstanceFromProperties_TargetTypeDecoratedWithRowAndPartitionKeyAttributes_RowAndPartitionKeySetCorrectly()
        {
            var genericEntity = new GenericEntity();
             genericEntity.PartitionKey = "foo";
             genericEntity.RowKey = "bar";
             genericEntity["Age"] = new EntityPropertyInfo( 42, typeof( int ), false );

             var item = genericEntity.CreateInstanceFromProperties<DecoratedItem>();
             Assert.AreEqual<string>( "foo", item.Id, "Incorrect partition key" );
             Assert.AreEqual<string>( "bar", item.Name, "Incorrect row key" );
        }
        private static XElement GenericEntityPropertyToXElement( Type type, string key, EntityPropertyInfo entityInfo )
        {
            string elementValue;
             if ( _typeToXmlConverterFunction.ContainsKey( type ) )
             {
            elementValue = _typeToXmlConverterFunction[type]( entityInfo.Value );
             }
             else
             {
            elementValue = entityInfo.IsNull ? null : entityInfo.Value.ToString();
             }

             var element = new XElement( AzureNamespaceProvider.AstoriaDataNamespace + key, elementValue );
             if ( entityInfo.IsNull )
             {
            element.Add( new XAttribute( AzureNamespaceProvider.AstoriaMetadataNamespace + "null", "true" ) );
             }

             return element;
        }