public void Can_use_PropertyAccessorsFactory_on_indexed_property() { IMutableModel model = new Model(); var entityType = model.AddEntityType(typeof(IndexedClass)); entityType.AddProperty("Id", typeof(int)); var propertyA = entityType.AddIndexedProperty("PropertyA", typeof(string)); model.FinalizeModel(); var contextServices = InMemoryTestHelpers.Instance.CreateContextServices(model); var stateManager = contextServices.GetRequiredService <IStateManager>(); var factory = contextServices.GetRequiredService <IInternalEntityEntryFactory>(); var entity = new IndexedClass(); var entry = factory.Create(stateManager, entityType, entity); var propertyAccessors = new PropertyAccessorsFactory().Create(propertyA); Assert.Equal("ValueA", ((Func <InternalEntityEntry, string>)propertyAccessors.CurrentValueGetter)(entry)); Assert.Equal("ValueA", ((Func <InternalEntityEntry, string>)propertyAccessors.OriginalValueGetter)(entry)); Assert.Equal("ValueA", ((Func <InternalEntityEntry, string>)propertyAccessors.PreStoreGeneratedCurrentValueGetter)(entry)); Assert.Equal("ValueA", ((Func <InternalEntityEntry, string>)propertyAccessors.RelationshipSnapshotGetter)(entry)); var valueBuffer = new ValueBuffer(new object[] { 1, "ValueA" }); Assert.Equal("ValueA", propertyAccessors.ValueBufferGetter(valueBuffer)); }
public void Can_use_PropertyAccessorsFactory_on_indexed_property() { var modelBuilder = InMemoryTestHelpers.Instance.CreateConventionBuilder(); var entityTypeBuilder = modelBuilder.Entity <IndexedClass>(); entityTypeBuilder.Property <int>("Id"); var propertyA = entityTypeBuilder.IndexerProperty <string>("PropertyA").Metadata; var model = modelBuilder.FinalizeModel(); var contextServices = InMemoryTestHelpers.Instance.CreateContextServices(model); var stateManager = contextServices.GetRequiredService <IStateManager>(); var entity = new IndexedClass(); var entry = new InternalEntityEntry(stateManager, (IEntityType)entityTypeBuilder.Metadata, entity); var propertyAccessors = new PropertyAccessorsFactory().Create((IProperty)propertyA); Assert.Equal("ValueA", ((Func <InternalEntityEntry, string>)propertyAccessors.CurrentValueGetter)(entry)); Assert.Equal("ValueA", ((Func <InternalEntityEntry, string>)propertyAccessors.OriginalValueGetter)(entry)); Assert.Equal("ValueA", ((Func <InternalEntityEntry, string>)propertyAccessors.PreStoreGeneratedCurrentValueGetter)(entry)); Assert.Equal("ValueA", ((Func <InternalEntityEntry, string>)propertyAccessors.RelationshipSnapshotGetter)(entry)); var valueBuffer = new ValueBuffer(new object[] { 1, "ValueA" }); Assert.Equal("ValueA", propertyAccessors.ValueBufferGetter(valueBuffer)); }
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 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 Delegate_getter_is_returned_for_indexed_property() { var modelBuilder = new ModelBuilder(InMemoryConventionSetBuilder.Build()); modelBuilder.Entity <IndexedClass>().Property(e => e.Id); var entityType = modelBuilder.Model.FindEntityType(typeof(IndexedClass)); var propertyA = entityType.AddIndexedProperty("PropertyA", typeof(string)); var propertyB = entityType.AddIndexedProperty("PropertyB", typeof(int)); modelBuilder.FinalizeModel(); var indexedClass = new IndexedClass(); Assert.Equal( "ValueA", new IndexedPropertyGetterFactory().Create(propertyA).GetClrValue(indexedClass)); Assert.Equal( 123, new IndexedPropertyGetterFactory().Create(propertyB).GetClrValue(indexedClass)); }
public void Delegate_setter_can_set_index_properties() { var entityType = CreateModel().AddEntityType(typeof(IndexedClass)); var propertyA = entityType.AddIndexerProperty("PropertyA", typeof(string)); var propertyB = entityType.AddIndexerProperty("PropertyB", typeof(int)); var indexedClass = new IndexedClass { Id = 7 }; Assert.Equal("ValueA", indexedClass["PropertyA"]); Assert.Equal(123, indexedClass["PropertyB"]); new ClrPropertySetterFactory().Create(propertyA).SetClrValue(indexedClass, "UpdatedValue"); new ClrPropertySetterFactory().Create(propertyB).SetClrValue(indexedClass, 42); Assert.Equal("UpdatedValue", indexedClass["PropertyA"]); Assert.Equal(42, indexedClass["PropertyB"]); }