public void EntityKeyConvention_FiguresOutTheEnumKeyProperty() { // Arrange MockType baseType = new MockType("BaseType") .Property <Color>("ID"); ODataConventionModelBuilder builder = ODataConventionModelBuilderFactory.Create(); builder.AddEntityType(baseType); // Act IEdmModel model = builder.GetEdmModel(); // Assert IEdmEntityType entity = model.AssertHasEntityType(baseType); IEdmStructuralProperty enumProperty = entity.AssertHasProperty <IEdmStructuralProperty>(model, "ID", typeof(Color), false); IEdmProperty enumKey = Assert.Single(entity.DeclaredKey); Assert.Same(enumProperty, enumKey); Assert.Equal(EdmTypeKind.Enum, enumKey.Type.TypeKind()); Assert.Equal("Microsoft.AspNet.OData.Test.Builder.TestModels.Color", enumKey.Type.Definition.FullTypeName()); }
public void DefaultValueAttributeEdmPropertyConvention_ConfiguresDefaultValuePropertyAsDefaultValue() { MockType type = new MockType("Entity") .Property(typeof(int), "ID") .Property(typeof(int), "Count", new DefaultValueAttribute(0)) .Property(typeof(TestEnum), "Kind", new DefaultValueAttribute(TestEnum.Member2)); ODataConventionModelBuilder builder = ODataConventionModelBuilderFactory.Create(); builder.AddEntityType(type); IEdmModel model = builder.GetEdmModel(); IEdmEntityType entity = model.AssertHasEntityType(type); IEdmStructuralProperty property = entity.AssertHasPrimitiveProperty(model, "Count", EdmPrimitiveTypeKind.Int32, isNullable: false); Assert.Equal("0", property.DefaultValueString); IEdmStructuralProperty enumProperty = entity.AssertHasProperty <IEdmStructuralProperty>(model, "Kind", typeof(TestEnum), isNullable: false); Assert.Equal("Member2", enumProperty.DefaultValueString); }