public void Can_add_and_get_property_mapping()
        {
            var p1 = EdmProperty.CreatePrimitive("p1", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32));
            var p2 = EdmProperty.CreatePrimitive("p2", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32));

            var mappingContext = new SimpleMappingContext(new EdmModel(DataSpace.SSpace), true);

            mappingContext.AddMapping(p1, p2);
            Assert.Same(p2, mappingContext[p1]);
        }
        public void Cannot_create_value_condition_mapping_with_null_value()
        {
            var primitiveType = PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String);
            var property      = EdmProperty.CreatePrimitive("P", primitiveType);

            Assert.Equal(
                "value",
                Assert.Throws <ArgumentNullException>(
                    () => new ValueConditionMapping(property, null)).ParamName);
        }
Ejemplo n.º 3
0
        public void HasConventionalKeyName_returns_true_when_type_and_id()
        {
            var property = EdmProperty.CreatePrimitive(
                "PersonId",
                PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32));

            EntityType.Create("Person", "MyModel", DataSpace.CSpace, null, new[] { property }, null);

            Assert.True(property.HasConventionalKeyName());
        }
Ejemplo n.º 4
0
        public TestModelBuilder Property(string propertyName)
        {
            var property1 = EdmProperty.CreatePrimitive(propertyName, PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            _entityType.AddMember(property1);
            var property = property1;

            property.SetClrPropertyInfo(new MockPropertyInfo(typeof(string), propertyName));
            return(this);
        }
        private void Assert_Timestamp(BinaryPropertyConfiguration binaryPropertyConfiguration)
        {
            binaryPropertyConfiguration.Configure(EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)));

            Assert.Equal("rowversion", binaryPropertyConfiguration.ColumnType);
            Assert.Equal(false, binaryPropertyConfiguration.IsNullable);
            Assert.Equal(ConcurrencyMode.Fixed, binaryPropertyConfiguration.ConcurrencyMode);
            Assert.Equal(DatabaseGeneratedOption.Computed, binaryPropertyConfiguration.DatabaseGeneratedOption);
            Assert.Equal(8, binaryPropertyConfiguration.MaxLength.Value);
        }
Ejemplo n.º 6
0
        public void Generate_can_map_foreign_key_association_type()
        {
            var model = new EdmModel(DataSpace.CSpace);

            var principalEntityType = model.AddEntityType("P");

            principalEntityType.GetMetadataProperties().SetClrType(typeof(object));

            var dependentEntityType = model.AddEntityType("D");

            dependentEntityType.GetMetadataProperties().SetClrType(typeof(string));

            var dependentProperty1 = EdmProperty.CreatePrimitive("FK1", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32));

            dependentProperty1.Nullable = false;
            dependentEntityType.AddMember(dependentProperty1);

            var dependentProperty2 = EdmProperty.CreatePrimitive("FK2", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            dependentEntityType.AddMember(dependentProperty2);

            model.AddEntitySet("PSet", principalEntityType);
            model.AddEntitySet("DSet", dependentEntityType);

            var associationType
                = model.AddAssociationType(
                      "P_D",
                      principalEntityType, RelationshipMultiplicity.One,
                      dependentEntityType, RelationshipMultiplicity.Many);

            associationType.Constraint
                = new ReferentialConstraint(
                      associationType.SourceEnd,
                      associationType.TargetEnd,
                      principalEntityType.KeyProperties,
                      new[] { dependentProperty1, dependentProperty2 });

            associationType.SourceEnd.DeleteBehavior = OperationAction.Cascade;

            var databaseMapping
                = CreateDatabaseMappingGenerator().Generate(model);

            var dependentTable       = databaseMapping.GetEntityTypeMapping(dependentEntityType).MappingFragments.Single().Table;
            var foreignKeyConstraint = dependentTable.ForeignKeyBuilders.Single();

            Assert.Equal(2, dependentTable.Properties.Count());
            Assert.Equal(2, foreignKeyConstraint.DependentColumns.Count());
            Assert.Equal(OperationAction.Cascade, foreignKeyConstraint.DeleteAction);
            Assert.Equal(associationType.Name, foreignKeyConstraint.Name);

            var foreignKeyColumn = foreignKeyConstraint.DependentColumns.First();

            Assert.False(foreignKeyColumn.Nullable);
            Assert.Equal("FK1", foreignKeyColumn.Name);
        }
        public void Can_create_value_condition_mapping_with_column()
        {
            var primitiveType = FakeSqlProviderServices.Instance.GetProviderManifest("2008").GetStoreTypes().First();
            var column        = EdmProperty.CreatePrimitive("C", primitiveType);
            var mapping       = new ValueConditionMapping(column, 42);

            Assert.Same(column, mapping.Column);
            Assert.Null(mapping.Property);
            Assert.Equal(42, mapping.Value);
            Assert.Null(mapping.IsNull);
        }
        public void Can_create_value_condition_mapping_with_property()
        {
            var primitiveType = PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String);
            var property      = EdmProperty.CreatePrimitive("P", primitiveType);
            var mapping       = new ValueConditionMapping(property, 42);

            Assert.Same(property, mapping.Property);
            Assert.Null(mapping.Column);
            Assert.Equal(42, mapping.Value);
            Assert.Null(mapping.IsNull);
        }
        public void SetStoreGeneratedPattern_should_create_annotation_and_add_to_property_facets()
        {
            var property = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            property.SetStoreGeneratedPattern(StoreGeneratedPattern.Computed);

            var storeGeneratedPattern = property.GetStoreGeneratedPattern();

            Assert.NotNull(storeGeneratedPattern);
            Assert.Equal(StoreGeneratedPattern.Computed, storeGeneratedPattern);
        }
Ejemplo n.º 10
0
        public void Configure_should_update_model_dateTime_precision()
        {
            var configuration = CreateConfiguration();

            configuration.Precision = 255;
            var property = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.DateTime));

            configuration.Configure(property);

            Assert.Equal((byte)255, property.Precision);
        }
        public void ComplexType_apply_should_set_given_value_for_unicode_fixed_length_strings()
        {
            var complexType = new ComplexType("C");
            var property = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
            property.IsFixedLength = true;
            complexType.AddMember(property);

            (new SqlCePropertyMaxLengthConvention(2000)).Apply(complexType, CreateDbModel());

            Assert.Equal(2000, property.MaxLength);
        }
        public void ComplexType_apply_should_set_correct_defaults_for_unconfigured_strings()
        {
            var complexType = new ComplexType("C");
            var property = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
            complexType.AddMember(property);

            (new SqlCePropertyMaxLengthConvention())
                .Apply(complexType, CreateDbModel());

            Assert.Equal(4000, property.MaxLength);
        }
Ejemplo n.º 13
0
        public void Configure_should_update_IsUnicode()
        {
            var configuration = CreateConfiguration();

            configuration.IsUnicode = true;
            var property = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            configuration.Configure(property);

            Assert.Equal(true, property.IsUnicode);
        }
        public void Apply_should_set_correct_defaults_for_unconfigured_strings()
        {
            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            var property = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
            entityType.AddMember(property);

            (new SqlCePropertyMaxLengthConvention())
                .Apply(entityType, CreateDbModel());

            Assert.Equal(4000, property.MaxLength);
        }
        public void Apply_should_set_given_value_for_unicode_fixed_length_strings()
        {
            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            var property = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
            property.IsFixedLength = true;
            entityType.AddMember(property);

            (new SqlCePropertyMaxLengthConvention(2000)).Apply(entityType, CreateDbModel());

            Assert.Equal(2000, property.MaxLength);
        }
        public void Apply_should_set_given_value_for_binary_key()
        {
            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            var property = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
            entityType.AddMember(property);
            entityType.AddKeyMember(property);

            (new SqlCePropertyMaxLengthConvention(2000)).Apply(entityType, CreateDbModel());

            Assert.Null(property.IsUnicode);
            Assert.Equal(2000, property.MaxLength);
        }
        public void Apply_should_not_match_simple_key_of_wrong_type()
        {
            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            var property   = EdmProperty.CreatePrimitive("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_model_decimal_scale_but_not_precision()
        {
            var configuration = CreateConfiguration();

            configuration.Scale = 70;
            var property = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Decimal));

            configuration.Configure(property);

            Assert.Equal((byte)70, property.Scale);
            Assert.Equal(null, property.Precision);
        }
Ejemplo n.º 19
0
        public void Configure_should_update_MaxLength()
        {
            var property = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            var configuration = CreateConfiguration();

            configuration.MaxLength = 1;

            configuration.Configure(property);

            Assert.Equal(1, property.MaxLength);
        }
        public void Apply_should_ignore_case()
        {
            var entityType = new EntityType("Foo", "N", DataSpace.CSpace);
            var property1  = EdmProperty.CreatePrimitive("foOid", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            entityType.AddMember(property1);
            var property = property1;

            (new IdKeyDiscoveryConvention()).Apply(entityType, new DbModel(new EdmModel(DataSpace.CSpace), null));

            Assert.True(entityType.KeyProperties.Contains(property));
        }
        public void Apply_should_make_key_not_nullable()
        {
            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            var property1  = EdmProperty.CreatePrimitive("Id", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            entityType.AddMember(property1);
            var property = property1;

            (new IdKeyDiscoveryConvention()).Apply(entityType, new DbModel(new EdmModel(DataSpace.CSpace), null));

            Assert.False(property.Nullable);
        }
        public void SetStoreGeneratedPattern_should_update_existing_annotation()
        {
            var property = EdmProperty.CreatePrimitive("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);
        }
Ejemplo n.º 23
0
        public void AddPrimitiveProperty_should_create_and_add_to_primitive_properties()
        {
            var complexType = new ComplexType("C");
            var property1   = EdmProperty.CreatePrimitive("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));
        }
Ejemplo n.º 24
0
        public void Apply_should_not_set_defaults_for_configured_scale()
        {
            var property = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Decimal));

            property.Scale = 4;

            (new DecimalPropertyConvention())
            .Apply(property, new DbModel(new EdmModel(DataSpace.CSpace), null));

            Assert.Equal((byte)18, property.Precision);
            Assert.Equal((byte)4, property.Scale);
        }
        public void AddPrimitiveProperty_should_create_and_add_to_declared_properties()
        {
            var entityType = new EntityType("E", "N", DataSpace.CSpace);

            var property1 = EdmProperty.CreatePrimitive("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));
        }
Ejemplo n.º 26
0
        public void GetPrimitiveProperty_should_return_correct_property()
        {
            var complexType = new ComplexType("C");
            var property1   = EdmProperty.CreatePrimitive("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 GetPrimitiveProperty_should_return_correct_property()
        {
            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            var property1  = EdmProperty.CreatePrimitive("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 GetPrimitiveProperties_should_return_only_primitive_properties()
        {
            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            var property1  = EdmProperty.CreatePrimitive("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 Apply_should_set_correct_defaults_for_fixed_length_binary()
        {
            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            var property = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
            property.IsFixedLength = true;
            entityType.AddMember(property);

            (new SqlCePropertyMaxLengthConvention())
                .Apply(entityType, CreateDbModel());

            Assert.Null(property.IsUnicode);
            Assert.Equal(4000, property.MaxLength);
        }
Ejemplo n.º 30
0
        public void Apply_should_set_correct_defaults_for_string_keys()
        {
            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            var property   = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            entityType.AddMember(property);
            entityType.AddKeyMember(property);

            (new PropertyMaxLengthConvention())
            .Apply(entityType, new DbModel(new EdmModel(DataSpace.CSpace), null));

            Assert.Equal(128, property.MaxLength);
        }