static ManyToManyCollectionMetadata BuildCollectionMetadata(EntityType parentEntityType, string name) { PropertyInfo propInfo = parentEntityType.ClrType.GetRuntimeProperty(name); if (propInfo == null) { throw new Exception($"Navigation property '{name}' couldn't be found."); } Type[] genericArgs; if (!propInfo.PropertyType.GetTypeInfo().IsGenericType || (genericArgs = propInfo.PropertyType.GetTypeInfo().GenericTypeArguments).Length != 1) { throw new Exception($"Type '{propInfo.PropertyType.FullName}' is not a valid collection type."); } Type itemType = genericArgs[0]; EntityType collectionEntityType = parentEntityType.Model.FindEntityType(itemType); ClrPropertyGetterFactory getterFactory = new ClrPropertyGetterFactory(); ClrPropertySetterFactory setterFactory = new ClrPropertySetterFactory(); return(new ManyToManyCollectionMetadata { Getter = getterFactory.Create(propInfo), Setter = setterFactory.Create(propInfo), ItemType = itemType }); }
public void Property_is_returned_if_it_implements_IClrPropertyGetter() { var getterMock = new Mock<IClrPropertyGetter>(); var propertyMock = getterMock.As<IProperty>(); var source = new ClrPropertyGetterFactory(); Assert.Same(getterMock.Object, source.Create(propertyMock.Object)); }
public void Property_is_returned_if_it_implements_IClrPropertyGetter() { var getterMock = new Mock <IClrPropertyGetter>(); var propertyMock = getterMock.As <IProperty>(); var source = new ClrPropertyGetterFactory(); Assert.Same(getterMock.Object, source.Create(propertyMock.Object)); }