public static bool Apply <TEdmTypeConfiguration, TConventionType>() where TEdmTypeConfiguration : StructuralTypeConfiguration where TConventionType : StructuralTypeConfiguration { Func <Attribute, bool> matchAllFilter = a => true; ODataConventionModelBuilder builder = ODataModelBuilderMocks.GetConventionModelBuilder(); Attribute attribute = new Mock <Attribute>().Object; // build the type Mock <Type> type = new Mock <Type>(); type.Setup(t => t.GetCustomAttributes(It.IsAny <bool>())).Returns(new[] { attribute }); Mock <TEdmTypeConfiguration> structuralType = new Mock <TEdmTypeConfiguration>(MockBehavior.Strict); structuralType.Setup(t => t.ClrType).Returns(type.Object); // build the convention SpyAttributeEdmTypeConvention <TConventionType> spy = new SpyAttributeEdmTypeConvention <TConventionType>(matchAllFilter, allowMultiple: false); // Apply (spy as IEdmTypeConvention).Apply(structuralType.Object, builder); return(object.ReferenceEquals(builder, spy.ModelBuilder) && object.ReferenceEquals(attribute, spy.Attribute)); }
public void EntityKeyConvention_DoesnotFigureOutKeyPropertyIfIgnored() { MockType baseType = new MockType("BaseType") .Property(typeof(int), "ID", new NotMappedAttribute()); ODataConventionModelBuilder builder = ODataModelBuilderMocks.GetConventionModelBuilder(); builder.AddEntityType(baseType); IEdmModel model = builder.GetEdmModel(); IEdmEntityType baseEntity = model.AssertHasEntityType(baseType); Assert.Empty(baseEntity.Properties()); Assert.Empty(baseEntity.Key()); }