public void DatabaseGeneratedAttributeEdmPropertyConvention_DoesnotOverwriteExistingConfiguration() { // Arrange MockType type = new MockType("Entity") .Property(typeof(int), "ID") .Property(typeof(int?), "Count", new DatabaseGeneratedAttribute(DatabaseGeneratedOption.Computed)); // Act ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); builder.AddEntity(type).AddProperty(type.GetProperty("Count")).IsOptional(); IEdmModel model = builder.GetEdmModel(); // Assert IEdmEntityType entity = model.AssertHasEntityType(type); IEdmStructuralProperty property = entity.AssertHasPrimitiveProperty(model, "Count", EdmPrimitiveTypeKind.Int32, isNullable: true); var idAnnotation = model.GetAnnotationValue <EdmStringConstant>( property, StoreGeneratedPatternAnnotation.AnnotationsNamespace, "StoreGeneratedPattern"); Assert.Null(idAnnotation); }
public static IEdmStructuralProperty AssertHasKey(this IEdmEntityType entity, IEdmModel model, string keyName, EdmPrimitiveTypeKind primitiveTypeKind) { IEdmStructuralProperty key = entity.AssertHasPrimitiveProperty(model, keyName, primitiveTypeKind, isNullable: false); Assert.Contains(key, entity.Key()); return(key); }
public void EntityKeyConvention_DoesnotFigureOutKeyPropertyOnDerivedTypes() { MockType baseType = new MockType("BaseType") .Property <uint>("ID"); MockType derivedType = new MockType("DerivedType") .Property <int>("DerivedTypeID") .BaseType(baseType); ODataConventionModelBuilder builder = ODataConventionModelBuilderFactory.Create(); builder.AddEntityType(derivedType).DerivesFrom(builder.AddEntityType(baseType)); IEdmModel model = builder.GetEdmModel(); IEdmEntityType baseEntity = model.AssertHasEntityType(baseType); baseEntity.AssertHasKey(model, "ID", EdmPrimitiveTypeKind.Int64); IEdmEntityType derivedEntity = model.AssertHasEntityType(derivedType); derivedEntity.AssertHasPrimitiveProperty(model, "DerivedTypeID", EdmPrimitiveTypeKind.Int32, isNullable: false); }
public void ConcurrencyCheckAttributeEdmPropertyConvention_DoesnotOverwriteExistingConfiguration() { // Arrange MockType type = new MockType("Entity") .Property(typeof(int), "ID") .Property(typeof(int), "Count", new ConcurrencyCheckAttribute()); ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); var entityType = builder.AddEntityType(type); entityType.AddProperty(type.GetProperty("Count")).IsOptional(); builder.AddEntitySet("EntitySet", entityType); // Act IEdmModel model = builder.GetEdmModel(); // Assert IEdmEntityType entity = model.AssertHasEntityType(type); IEdmStructuralProperty property = entity.AssertHasPrimitiveProperty( model, "Count", EdmPrimitiveTypeKind.Int32, isNullable: true); IEdmEntitySet entitySet = model.EntityContainer.FindEntitySet("EntitySet"); Assert.NotNull(entitySet); IEnumerable <IEdmStructuralProperty> currencyProperties = model.GetConcurrencyProperties(entitySet); IEdmStructuralProperty currencyProperty = Assert.Single(currencyProperties); Assert.Same(property, currencyProperty); }
public void ConcurrencyCheckAttributeEdmPropertyConvention_ConfiguresETagPropertyAsETag() { // Arrange MockType type = new MockType("Entity") .Property(typeof(int), "ID") .Property(typeof(int?), "Count", new ConcurrencyCheckAttribute()); ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); builder.AddEntityType(type); // Act IEdmModel model = builder.GetEdmModel(); // Assert IEdmEntityType entity = model.AssertHasEntityType(type); IEdmStructuralProperty property = entity.AssertHasPrimitiveProperty( model, "Count", EdmPrimitiveTypeKind.Int32, isNullable: true); Assert.Equal(EdmConcurrencyMode.Fixed, property.ConcurrencyMode); }
public void GetEdmModel_PropertyWithETag_IsConcurrencyToken() { // Arrange ODataModelBuilder builder = new ODataModelBuilder(); EntityTypeConfiguration <Customer> customer = builder.EntityType <Customer>(); customer.HasKey(c => c.Id); customer.Property(c => c.Id); customer.Property(c => c.Name).IsConcurrencyToken(); builder.EntitySet <Customer>("Customers"); // Act IEdmModel model = builder.GetEdmModel(); // Assert IEdmEntityType type = model.AssertHasEntityType(typeof(Customer)); IEdmStructuralProperty property = type.AssertHasPrimitiveProperty(model, "Name", EdmPrimitiveTypeKind.String, isNullable: true); IEdmEntitySet customers = model.EntityContainer.FindEntitySet("Customers"); Assert.NotNull(customers); IEnumerable <IEdmStructuralProperty> currencyProperties = model.GetConcurrencyProperties(customers); IEdmStructuralProperty currencyProperty = Assert.Single(currencyProperties); Assert.Same(property, currencyProperty); }
public void GetEdmModel_PropertyWithConcurrency_IsConcurrencyToken() { // Arrange var builder = new ODataModelBuilder(); builder.Entity <Customer>().Property(c => c.Name).IsConcurrencyToken(); builder.Entity <Customer>().Property(c => c.Id); // Act var model = builder.GetEdmModel(); // Assert IEdmEntityType type = model.AssertHasEntityType(typeof(Customer)); IEdmStructuralProperty nameProperty = type.AssertHasPrimitiveProperty(model, "Name", EdmPrimitiveTypeKind.String, isNullable: true); Assert.Equal(EdmConcurrencyMode.Fixed, nameProperty.ConcurrencyMode); IEdmStructuralProperty idProperty = type.AssertHasPrimitiveProperty(model, "Id", EdmPrimitiveTypeKind.Int32, isNullable: false); Assert.Equal(EdmConcurrencyMode.None, idProperty.ConcurrencyMode); }
public void GetEdmModel_PropertyWithDatabaseAttribute_ConfigAnnotationOnPropertyOnEntityType() { // Arrange MockType type = new MockType("Entity") .Property(typeof(int), "ID", new DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)) .Property(typeof(int?), "Count"); ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); builder.AddEntity(type); // Act IEdmModel model = builder.GetEdmModel(); // Assert IEdmEntityType entity = model.AssertHasEntityType(type); IEdmStructuralProperty idProperty = entity.AssertHasPrimitiveProperty(model, "ID", EdmPrimitiveTypeKind.Int32, isNullable: false); var idAnnotation = model.GetAnnotationValue <EdmStringConstant>( idProperty, StoreGeneratedPatternAnnotation.AnnotationsNamespace, StoreGeneratedPatternAnnotation.AnnotationName); Assert.Equal(DatabaseGeneratedOption.Identity.ToString(), idAnnotation.Value); IEdmStructuralProperty countProperty = entity.AssertHasPrimitiveProperty(model, "Count", EdmPrimitiveTypeKind.Int32, isNullable: true); var countAnnotation = model.GetAnnotationValue <EdmStringConstant>( countProperty, StoreGeneratedPatternAnnotation.AnnotationsNamespace, StoreGeneratedPatternAnnotation.AnnotationName); Assert.Null(countAnnotation); }
public void RequiredAttributeEdmPropertyConvention_DoesnotOverwriteExistingConfiguration() { MockType type = new MockType("Entity") .Property(typeof(int), "ID") .Property(typeof(int), "Count", new RequiredAttribute()); ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); builder.AddEntity(type).AddProperty(type.GetProperty("Count")).IsOptional(); IEdmModel model = builder.GetEdmModel(); IEdmEntityType entity = model.AssertHasEntityType(type); entity.AssertHasPrimitiveProperty(model, "Count", EdmPrimitiveTypeKind.Int32, isNullable: true); }
public void RequiredAttributeEdmPropertyConvention_ConfiguresRequiredPropertyAsRequired() { MockType type = new MockType("Entity") .Property(typeof(int), "ID") .Property(typeof(int?), "Count", new RequiredAttribute()); ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); builder.AddEntity(type); IEdmModel model = builder.GetEdmModel(); IEdmEntityType entity = model.AssertHasEntityType(type); entity.AssertHasPrimitiveProperty(model, "Count", EdmPrimitiveTypeKind.Int32, isNullable: false); }
public void DefaultValueAttributeEdmPropertyConvention_DoesnotOverwriteExistingConfiguration() { MockType type = new MockType("Entity") .Property(typeof(int), "ID") .Property(typeof(int), "Count", new DefaultValueAttribute("10")); ODataConventionModelBuilder builder = ODataConventionModelBuilderFactory.Create(); builder.AddEntityType(type).AddProperty(type.GetProperty("Count")).DefaultValueString = "0"; IEdmModel model = builder.GetEdmModel(); IEdmEntityType entity = model.AssertHasEntityType(type); IEdmStructuralProperty property = entity.AssertHasPrimitiveProperty(model, "Count", EdmPrimitiveTypeKind.Int32, isNullable: false); Assert.Equal("0", property.DefaultValueString); }
public void DataMemberAttributeEdmPropertyConvention_ConfiguresNonRequiredDataMembersAsOptional() { MockType type = new MockType("Entity") .Property(typeof(int), "ID", new DataMemberAttribute()) .Property(typeof(int), "Count", new DataMemberAttribute()); type.Setup(t => t.GetCustomAttributes(It.IsAny <Type>(), It.IsAny <bool>())).Returns(new[] { new DataContractAttribute() }); ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); builder.AddEntity(type); IEdmModel model = builder.GetEdmModel(); IEdmEntityType entity = model.AssertHasEntityType(type); entity.AssertHasKey(model, "ID", EdmPrimitiveTypeKind.Int32); entity.AssertHasPrimitiveProperty(model, "Count", EdmPrimitiveTypeKind.Int32, isNullable: true); }
public void GetEdmModel_PropertyWithETag_IsConcurrencyToken() { // Arrange ODataModelBuilder builder = new ODataModelBuilder(); EntityTypeConfiguration <Customer> customer = builder.EntityType <Customer>(); customer.HasKey(c => c.Id); customer.Property(c => c.Id); customer.Property(c => c.Name).IsConcurrencyToken(); // Act IEdmModel model = builder.GetEdmModel(); // Assert IEdmEntityType type = model.AssertHasEntityType(typeof(Customer)); IEdmStructuralProperty property = type.AssertHasPrimitiveProperty(model, "Name", EdmPrimitiveTypeKind.String, isNullable: true); Assert.Equal(EdmConcurrencyMode.Fixed, property.ConcurrencyMode); }
public void GetEdmModel_PropertyWithDatabaseAttribute_SetStoreGeneratedPatternOnEntityType() { // Arrange ODataModelBuilder builder = new ODataModelBuilder(); builder.Entity <Customer>().Property(c => c.Name).HasStoreGeneratedPattern(DatabaseGeneratedOption.Computed); // Act IEdmModel model = builder.GetEdmModel(); // Assert IEdmEntityType type = model.AssertHasEntityType(typeof(Customer)); IEdmStructuralProperty property = type.AssertHasPrimitiveProperty(model, "Name", EdmPrimitiveTypeKind.String, isNullable: true); var idAnnotation = model.GetAnnotationValue <EdmStringConstant>( property, StoreGeneratedPatternAnnotation.AnnotationsNamespace, StoreGeneratedPatternAnnotation.AnnotationName); Assert.Equal(DatabaseGeneratedOption.Computed.ToString(), idAnnotation.Value); }
public void DataMemberAttributeEdmPropertyConvention_DoesnotOverwriteExistingConfiguration() { MockType type = new MockType("Entity") .Property(typeof(int), "ID", new DataMemberAttribute()) .Property(typeof(int), "Count", new DataMemberAttribute { IsRequired = true }); type.Setup(t => t.GetCustomAttributes(It.IsAny <Type>(), It.IsAny <bool>())).Returns(new[] { new DataContractAttribute() }); ODataConventionModelBuilder builder = ODataConventionModelBuilderFactory.Create(); builder.AddEntityType(type).AddProperty(type.GetProperty("Count")).IsOptional(); IEdmModel model = builder.GetEdmModel(); IEdmEntityType entity = model.AssertHasEntityType(type); entity.AssertHasPrimitiveProperty(model, "Count", EdmPrimitiveTypeKind.Int32, isNullable: true); }
public void ConcurrencyCheckAttributeEdmPropertyConvention_DoesnotOverwriteExistingConfiguration() { MockType type = new MockType("Entity") .Property(typeof(int), "ID") .Property(typeof(int), "Count", new ConcurrencyCheckAttribute()); ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); builder.AddEntityType(type).AddProperty(type.GetProperty("Count")).IsOptional(); IEdmModel model = builder.GetEdmModel(); IEdmEntityType entity = model.AssertHasEntityType(type); IEdmStructuralProperty property = entity.AssertHasPrimitiveProperty( model, "Count", EdmPrimitiveTypeKind.Int32, isNullable: true); Assert.Equal(EdmConcurrencyMode.Fixed, property.ConcurrencyMode); }
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); }
public void DataMemberAttributeEdmPropertyConvention_ConfiguresRequiredDataMembersAsRequired() { MockType type = new MockType("Entity") .Property(typeof(int), "ID", new DataMemberAttribute()) .Property(typeof(string), "Name", new DataMemberAttribute { IsRequired = true }); type.Setup(t => t.GetCustomAttributes(It.IsAny <Type>(), It.IsAny <bool>())).Returns(new[] { new DataContractAttribute() }); ODataConventionModelBuilder builder = ODataConventionModelBuilderFactory.Create(); builder.AddEntityType(type); IEdmModel model = builder.GetEdmModel(); IEdmEntityType entity = model.AssertHasEntityType(type); entity.AssertHasKey(model, "ID", EdmPrimitiveTypeKind.Int32); entity.AssertHasPrimitiveProperty(model, "Name", EdmPrimitiveTypeKind.String, isNullable: false); }