public void Apply_should_set_correct_defaults_for_unconfigured_strings() { var entityType = new EntityType("E", "N", DataSpace.CSpace); var property = EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(property); (new SqlCePropertyMaxLengthConvention()) .Apply(entityType, CreateDbModel()); Assert.Equal(4000, property.MaxLength); }
public void Apply_should_make_key_not_nullable() { var entityType = new EntityType("E", "N", DataSpace.CSpace); var property1 = EdmProperty.Primitive("Id", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(property1); var property = property1; ((IEdmConvention <EntityType>) new IdKeyDiscoveryConvention()).Apply(entityType, new EdmModel(DataSpace.CSpace)); Assert.False(property.Nullable); }
public void Apply_should_not_match_simple_key_of_wrong_type() { var entityType = new EntityType("E", "N", DataSpace.CSpace); var property = EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddKeyMember(property); (new StoreGeneratedIdentityKeyConvention()) .Apply(entityType, new DbModel(new EdmModel(DataSpace.CSpace), null)); Assert.Null(entityType.KeyProperties.Single().GetStoreGeneratedPattern()); }
public void Configure_should_update_IsMaxLength() { var property = EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); var configuration = CreateConfiguration(); configuration.IsMaxLength = true; configuration.Configure(property); Assert.Equal(true, property.IsMaxLength); }
public void Apply_should_not_set_defaults_for_configured_precision() { var property = EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Decimal)); property.Precision = 22; (new DecimalPropertyConvention()) .Apply(property, new DbModel(new EdmModel(DataSpace.CSpace), null)); Assert.Equal((byte)22, property.Precision); Assert.Equal((byte)2, property.Scale); }
public void Apply_should_match_simple_id() { var entityType = new EntityType(); var property1 = EdmProperty.Primitive("Id", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(property1); var property = property1; ((IEdmConvention <EntityType>) new IdKeyDiscoveryConvention()).Apply(entityType, new EdmModel()); Assert.True(entityType.DeclaredKeyProperties.Contains(property)); }
public void AddPrimitiveProperty_should_create_and_add_to_primitive_properties() { var complexType = new ComplexType("C"); var property1 = EdmProperty.Primitive("Foo", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); complexType.AddMember(property1); var property = property1; Assert.NotNull(property); Assert.Equal("Foo", property.Name); Assert.True(complexType.Properties.Contains(property)); }
public void SetStoreGeneratedPattern_should_update_existing_annotation() { var property = EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); property.SetStoreGeneratedPattern(StoreGeneratedPattern.Computed); property.SetStoreGeneratedPattern(StoreGeneratedPattern.None); var storeGeneratedPattern = property.GetStoreGeneratedPattern(); Assert.NotNull(storeGeneratedPattern); Assert.Equal(StoreGeneratedPattern.None, storeGeneratedPattern); }
public void Configure_should_update_model_property_concurrency_mode() { var configuration = CreateConfiguration(); configuration.ConcurrencyMode = ConcurrencyMode.Fixed; var property = EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); configuration.Configure(property); Assert.Equal(ConcurrencyMode.Fixed, property.ConcurrencyMode); }
public void ComplexType_apply_should_set_correct_defaults_for_unconfigured_binary() { var entityType = new ComplexType("C"); var property = EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(property); ((IEdmConvention <ComplexType>) new SqlCePropertyMaxLengthConvention()) .Apply(entityType, CreateEdmModel()); Assert.Equal(4000, property.MaxLength); }
public void Apply_should_not_set_defaults_for_configured_scale() { var property = EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Decimal)); property.Scale = 4; ((IEdmConvention <EdmProperty>) new DecimalPropertyConvention()) .Apply(property, new EdmModel(DataSpace.CSpace)); Assert.Equal((byte)18, property.Precision); Assert.Equal((byte)4, property.Scale); }
public void Apply_should_ignore_case() { var entityType = new EntityType("Foo", "N", DataSpace.CSpace); var property1 = EdmProperty.Primitive("foOid", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(property1); var property = property1; ((IEdmConvention <EntityType>) new IdKeyDiscoveryConvention()).Apply(entityType, new EdmModel(DataSpace.CSpace)); Assert.True(entityType.KeyProperties.Contains(property)); }
public void Configure_should_update_model_property_store_generated_pattern() { var configuration = CreateConfiguration(); configuration.DatabaseGeneratedOption = DatabaseGeneratedOption.Identity; var property = EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); configuration.Configure(property); Assert.Equal(StoreGeneratedPattern.Identity, property.GetStoreGeneratedPattern()); Assert.Equal(false, property.Nullable); }
public void Apply_should_set_correct_defaults_for_string_keys() { var entityType = new EntityType(); var property = EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(property); entityType.AddKeyMember(property); ((IEdmConvention <EntityType>) new SqlCePropertyMaxLengthConvention()) .Apply(entityType, CreateEdmModel()); Assert.Equal(4000, property.MaxLength); }
public void GetPrimitiveProperties_should_return_only_primitive_properties() { var entityType = new EntityType(); var property1 = EdmProperty.Primitive("Foo", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(property1); var property = property1; entityType.AddComplexProperty("Bar", new ComplexType("C")); Assert.Equal(1, entityType.GetDeclaredPrimitiveProperties().Count()); Assert.True(entityType.GetDeclaredPrimitiveProperties().Contains(property)); }
public void GetPrimitiveProperty_should_return_correct_property() { var entityType = new EntityType(); var property1 = EdmProperty.Primitive("Foo", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(property1); var property = property1; var foundProperty = entityType.GetDeclaredPrimitiveProperties().SingleOrDefault(p => p.Name == "Foo"); Assert.NotNull(foundProperty); Assert.Same(property, foundProperty); }
public void AddPrimitiveProperty_should_create_and_add_to_declared_properties() { var entityType = new EntityType(); var property1 = EdmProperty.Primitive("Foo", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(property1); var property = property1; Assert.NotNull(property); Assert.Equal("Foo", property.Name); Assert.True(entityType.DeclaredProperties.Contains(property)); }
public void ComplexType_apply_should_set_correct_defaults_for_unicode_fixed_length_strings() { var entityType = new ComplexType("C"); var property = EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); property.IsFixedLength = true; entityType.AddMember(property); (new SqlCePropertyMaxLengthConvention()) .Apply(entityType, CreateDbModel()); Assert.Equal(4000, property.MaxLength); }
public void Apply_should_set_correct_defaults_for_string_keys() { var entityType = new EntityType("E", "N", DataSpace.CSpace); var property = EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(property); entityType.AddKeyMember(property); ((IEdmConvention <EntityType>) new PropertyMaxLengthConvention()) .Apply(entityType, new EdmModel(DataSpace.CSpace)); Assert.Equal(128, property.MaxLength); }
public void GetPrimitiveProperty_should_return_correct_property() { var complexType = new ComplexType("C"); var property1 = EdmProperty.Primitive("Foo", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); complexType.AddMember(property1); var property = property1; var foundProperty = complexType.Properties.SingleOrDefault(p => p.Name == "Foo"); Assert.NotNull(foundProperty); Assert.Same(property, foundProperty); }
public void Apply_should_set_correct_defaults_for_unicode_fixed_length_strings() { var entityType = new EntityType("E", "N", DataSpace.CSpace); var property = EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); property.IsFixedLength = true; entityType.AddMember(property); ((IEdmConvention <EntityType>) new SqlCePropertyMaxLengthConvention()) .Apply(entityType, CreateEdmModel()); Assert.Equal(4000, property.MaxLength); }
public TestModelBuilder Key(string key) { var property1 = EdmProperty.Primitive(key, PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); _entityType.AddMember(property1); var property = property1; property.SetClrPropertyInfo(new MockPropertyInfo(typeof(int), key)); _entityType.AddKeyMember(property); return(this); }
public void Generate_can_map_independent_association_type() { var model = new EdmModel(DataSpace.CSpace); var principalEntityType = model.AddEntityType("P"); var type = typeof(object); principalEntityType.Annotations.SetClrType(type); var property = EdmProperty.Primitive("Id1", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); principalEntityType.AddMember(property); var idProperty1 = property; principalEntityType.AddKeyMember(idProperty1); var property1 = EdmProperty.Primitive("Id2", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); principalEntityType.AddMember(property1); var idProperty2 = property1; principalEntityType.AddKeyMember(idProperty2); var dependentEntityType = model.AddEntityType("D"); var type1 = typeof(string); dependentEntityType.Annotations.SetClrType(type1); model.AddEntitySet("PSet", principalEntityType); model.AddEntitySet("DSet", dependentEntityType); var associationType = model.AddAssociationType( "P_D", principalEntityType, RelationshipMultiplicity.One, dependentEntityType, RelationshipMultiplicity.Many); model.AddAssociationSet("P_DSet", associationType); associationType.SourceEnd.DeleteBehavior = OperationAction.Cascade; var databaseMapping = new DatabaseMappingGenerator(ProviderRegistry.Sql2008_ProviderManifest).Generate(model); var foreignKeyConstraint = databaseMapping.GetEntityTypeMapping(dependentEntityType).MappingFragments.Single().Table.ForeignKeyBuilders.Single(); Assert.Equal(2, foreignKeyConstraint.DependentColumns.Count()); Assert.Equal(associationType.Name, foreignKeyConstraint.Name); Assert.Equal(1, databaseMapping.EntityContainerMappings.Single().AssociationSetMappings.Count()); Assert.Equal(OperationAction.Cascade, foreignKeyConstraint.DeleteAction); var foreignKeyColumn = foreignKeyConstraint.DependentColumns.First(); Assert.False(foreignKeyColumn.Nullable); Assert.Equal("P_Id1", foreignKeyColumn.Name); }
public void Apply_should_set_correct_defaults_for_unconfigured_binary() { var entityType = new EntityType("E", "N", DataSpace.CSpace); var property = EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Binary)); entityType.AddMember(property); ((IEdmConvention <EntityType>) new PropertyMaxLengthConvention()) .Apply(entityType, new EdmModel(DataSpace.CSpace)); Assert.Null(property.IsUnicode); Assert.Equal(false, property.IsFixedLength); Assert.Null(property.MaxLength); }
public void HasStoreGeneratedPattern_should_return_true_when_not_null_or_none() { var property = EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); Assert.False(property.HasStoreGeneratedPattern()); property.SetStoreGeneratedPattern(StoreGeneratedPattern.None); Assert.False(property.HasStoreGeneratedPattern()); property.SetStoreGeneratedPattern(StoreGeneratedPattern.Computed); Assert.True(property.HasStoreGeneratedPattern()); }
public void Apply_should_match_simple_short_key() { var entityType = new EntityType("E", "N", DataSpace.CSpace); var property = EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32)); entityType.AddKeyMember(property); ((IEdmConvention <EntityType>) new StoreGeneratedIdentityKeyConvention()) .Apply(entityType, new EdmModel(DataSpace.CSpace)); Assert.Equal( StoreGeneratedPattern.Identity, entityType.KeyProperties.Single().GetStoreGeneratedPattern()); }
public void Apply_should_ignore_when_type_is_derived() { var entityType = new EntityType("E", "N", DataSpace.CSpace); var property1 = EdmProperty.Primitive("Id", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(property1); var property = property1; entityType.BaseType = new EntityType("E", "N", DataSpace.CSpace); (new IdKeyDiscoveryConvention()).Apply(entityType, new DbModel(new EdmModel(DataSpace.CSpace), null)); Assert.False(entityType.KeyProperties.Contains(property)); }
public void Apply_should_match_simple_long_key() { var entityType = new EntityType(); var property = EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int64)); entityType.AddKeyMember(property); ((IEdmConvention <EntityType>) new StoreGeneratedIdentityKeyConvention()) .Apply(entityType, new EdmModel().Initialize()); Assert.Equal( StoreGeneratedPattern.Identity, entityType.DeclaredKeyProperties.Single().GetStoreGeneratedPattern()); }
public void Apply_should_set_correct_defaults_for_binary_key() { var entityType = new EntityType("E", "N", DataSpace.CSpace); var property = EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Binary)); entityType.AddMember(property); entityType.AddKeyMember(property); (new PropertyMaxLengthConvention()) .Apply(entityType, new DbModel(new EdmModel(DataSpace.CSpace), null)); Assert.Null(property.IsUnicode); Assert.Equal(128, property.MaxLength); }
public void Apply_should_ignore_when_key_already_specified() { var entityType = new EntityType("E", "N", DataSpace.CSpace); var property1 = EdmProperty.Primitive("Id", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(property1); var property = property1; entityType.AddKeyMember(EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String))); ((IEdmConvention <EntityType>) new IdKeyDiscoveryConvention()).Apply(entityType, new EdmModel(DataSpace.CSpace)); Assert.False(entityType.KeyProperties.Contains(property)); }