public void Exception_is_returned_for_indexed_property_without_indexer() { var entityType = new Model().AddEntityType(typeof(NonIndexedClass)); var idProperty = entityType.AddProperty("Id", typeof(int)); Assert.Throws <InvalidOperationException>( () => entityType.AddIndexedProperty("PropA", typeof(string))); Assert.Throws <InvalidOperationException>( () => entityType.AddIndexedProperty("PropB", typeof(int))); }
public void Delegate_getter_is_returned_for_indexed_property() { var entityType = new Model().AddEntityType(typeof(IndexedClass)); var idProperty = entityType.AddProperty("Id", typeof(int)); var propertyA = entityType.AddIndexedProperty("PropertyA", typeof(string)); var propertyB = entityType.AddIndexedProperty("PropertyB", typeof(int)); var indexedClass = new IndexedClass(); Assert.Equal( "ValueA", new IndexedPropertyGetterFactory().Create(propertyA).GetClrValue(indexedClass)); Assert.Equal( 123, new IndexedPropertyGetterFactory().Create(propertyB).GetClrValue(indexedClass)); }
public void Exception_is_returned_for_indexed_property_without_indexer() { var entityType = new Model().AddEntityType(typeof(NonIndexedClass)); var idProperty = entityType.AddProperty("Id", typeof(int)); var propertyA = entityType.AddIndexedProperty("PropertyA", typeof(string)); var propertyB = entityType.AddIndexedProperty("PropertyB", typeof(int)); var nonIndexedClass = new NonIndexedClass(); Assert.Throws <InvalidOperationException>( () => new IndexedPropertyGetterFactory().Create(propertyA).GetClrValue(nonIndexedClass)); Assert.Throws <InvalidOperationException>( () => new IndexedPropertyGetterFactory().Create(propertyB).GetClrValue(nonIndexedClass)); }
public void Delegate_setter_is_returned_for_indexed_property() { var entityType = new Model().AddEntityType(typeof(IndexedClass)); var idProperty = entityType.AddProperty("Id", typeof(int)); var propertyA = entityType.AddIndexedProperty("PropertyA", typeof(string)); var propertyB = entityType.AddIndexedProperty("PropertyB", typeof(int)); var indexedClass = new IndexedClass { Id = 1 }; new IndexedPropertySetterFactory().Create(propertyA).SetClrValue(indexedClass, "UpdatedValueA"); new IndexedPropertySetterFactory().Create(propertyB).SetClrValue(indexedClass, 456); Assert.Equal("UpdatedValueA", indexedClass["PropertyA"]); Assert.Equal(456, indexedClass["PropertyB"]); }
public void Exception_is_returned_when_setting_indexed_property_without_indexer() { var entityType = new Model().AddEntityType(typeof(NonIndexedClass)); var idProperty = entityType.AddProperty("Id", typeof(int)); var propertyA = entityType.AddIndexedProperty("PropertyA", typeof(string)); var propertyB = entityType.AddIndexedProperty("PropertyB", typeof(int)); var indexedClass = new NonIndexedClass { Id = 1, PropA = "PropAValue", PropB = 123 }; Assert.Throws <InvalidOperationException>( () => new IndexedPropertySetterFactory().Create(propertyA).SetClrValue(indexedClass, "UpdatedValueA")); Assert.Throws <InvalidOperationException>( () => new IndexedPropertySetterFactory().Create(propertyB).SetClrValue(indexedClass, 456)); }