// Helper to add a single TDP property to a given entity type.
        private static void AddVirtualProperty <TEntity, TProperty>(string propertyName)
        {
            Type baseType        = typeof(TEntity).BaseType;
            bool inheritFromBase = baseType != typeof(object);
            ICustomTypeDescriptor       parent   = inheritFromBase ? TypeDescriptor.GetProvider(baseType).GetTypeDescriptor(baseType) : null;
            MockTypeDescriptionProvider provider = new MockTypeDescriptionProvider(() =>
            {
                return(new MockPropertyDescriptor <TProperty>(propertyName, typeof(TEntity), getter: null, setter: null));
            }, parent);

            TypeDescriptor.AddProvider(provider, typeof(TEntity));
        }
        private void TestVirtualProperty <T>(Type entityType, bool isReadOnly, Action <Type, PropertyInfo, object> verify)
        {
            string propertyName = "TestProperty";
            MockTypeDescriptionProvider provider = new MockTypeDescriptionProvider(() =>
            {
                Dictionary <object, T> valueMap = new Dictionary <object, T>();

                Action <object, T> setter;
                if (isReadOnly)
                {
                    setter = null;
                }
                else
                {
                    setter = (obj, value) => valueMap[obj] = value;
                }

                return(new MockPropertyDescriptor <T>(
                           propertyName,
                           entityType,
                           getter: obj =>
                {
                    T value;
                    valueMap.TryGetValue(obj, out value);
                    return value;
                },
                           setter: setter));
            });

            TypeDescriptor.AddProvider(provider, entityType);
            HashSet <Type> knownEntityTypes = new HashSet <Type>()
            {
                entityType
            };
            Type   surrogateType = DataContractSurrogateGenerator.GetSurrogateType(knownEntityTypes, entityType);
            object surrogateObj  = Activator.CreateInstance(surrogateType, Activator.CreateInstance(entityType));
            var    p             = surrogateType.GetProperty(propertyName);

            Assert.IsNotNull(p, "Property doesn't exist.");
            verify(surrogateType, p, surrogateObj);
            TypeDescriptor.RemoveProvider(provider, entityType);
        }