Esempio n. 1
0
        public void Can_use_PropertyAccessorsFactory_on_non_indexed_property()
        {
            IMutableModel model      = new Model();
            var           entityType = model.AddEntityType(typeof(NonIndexedClass));

            entityType.AddProperty("Id", typeof(int));
            var propA = entityType.AddProperty("PropA", typeof(string));

            model.FinalizeModel();

            var contextServices = InMemoryTestHelpers.Instance.CreateContextServices(model);
            var stateManager    = contextServices.GetRequiredService <IStateManager>();
            var factory         = contextServices.GetRequiredService <IInternalEntityEntryFactory>();

            var entity = new NonIndexedClass();
            var entry  = factory.Create(stateManager, entityType, entity);

            var propertyAccessors = new PropertyAccessorsFactory().Create(propA);

            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_non_indexed_property()
        {
            var modelBuilder      = InMemoryTestHelpers.Instance.CreateConventionBuilder();
            var entityTypeBuilder = modelBuilder.Entity <NonIndexedClass>();

            entityTypeBuilder.Property <int>("Id");
            var propA = entityTypeBuilder.Property <string>("PropA").Metadata;

            var model = modelBuilder.FinalizeModel();

            var contextServices = InMemoryTestHelpers.Instance.CreateContextServices(model);
            var stateManager    = contextServices.GetRequiredService <IStateManager>();

            var entity = new NonIndexedClass();
            var entry  = new InternalEntityEntry(stateManager, (IEntityType)entityTypeBuilder.Metadata, entity);

            var propertyAccessors = new PropertyAccessorsFactory().Create((IProperty)propA);

            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));
        }