public void Delegate_getter_is_cached_by_type_and_property_name()
        {
            var entityType = new EntityType(typeof(Customer));
            var idProperty = entityType.AddProperty("Id", typeof(int));

            var source = new ClrPropertyGetterSource();

            var accessor = source.GetAccessor(typeof(Customer), "Id");

            Assert.Same(accessor, source.GetAccessor(typeof(Customer), "Id"));
            Assert.Same(accessor, source.GetAccessor(idProperty));
        }
        public void Property_is_returned_if_it_implements_IClrPropertyGetter()
        {
            var getterMock   = new Mock <IClrPropertyGetter>();
            var propertyMock = getterMock.As <IProperty>();

            var source = new ClrPropertyGetterSource();

            Assert.Same(getterMock.Object, source.GetAccessor(propertyMock.Object));
        }
        private NavigationAccessor Create(INavigation navigation)
        {
            var elementType = navigation.EntityType.Type.GetAnyProperty(navigation.Name).PropertyType.TryGetElementType(typeof(IEnumerable <>));

            var targetType = navigation.PointsToPrincipal
                ? navigation.ForeignKey.ReferencedEntityType
                : navigation.ForeignKey.EntityType;

            // TODO: Consider allowing an annotation to force treating a reference to an Entity which is an IEnumerable of
            // itself as a reference instead of a collection. Currently it will be considered a collection nav prop, which it isn't.

            return(elementType != null && elementType == targetType.Type
                ? new CollectionNavigationAccessor(
                       () => _getterSource.GetAccessor(navigation),
                       () => _setterSource.GetAccessor(navigation),
                       () => _collectionAccessorSource.GetAccessor(navigation))
                : new NavigationAccessor(
                       () => _getterSource.GetAccessor(navigation),
                       () => _setterSource.GetAccessor(navigation)));
        }