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