Beispiel #1
0
        public void Equals_should_compare_references_or_dependent_key_sequences()
        {
            var propertyInfo             = new MockPropertyInfo().Object;
            var constraintConfiguration1 = new ForeignKeyConstraintConfiguration(new[] { propertyInfo });

            Assert.True(constraintConfiguration1.Equals(constraintConfiguration1));

            var constraintConfiguration2 = new ForeignKeyConstraintConfiguration(new[] { propertyInfo });

            Assert.True(constraintConfiguration1.Equals(constraintConfiguration2));
        }
    public void Apply(
        PropertyInfo propertyInfo, Func <NavigationPropertyConfiguration> configuration)
    {
        var foreignKeyProperty =
            propertyInfo.DeclaringType.GetProperty("Id" + propertyInfo.Name);

        if (foreignKeyProperty != null && configuration().Constraint == null)
        {
            var fkConstraint = new ForeignKeyConstraintConfiguration();
            fkConstraint.AddColumn(foreignKeyProperty);
            configuration().Constraint = fkConstraint;
        }
    }
        public void Cloning_a_foreign_key_constraint_clones_its_property_information()
        {
            var configuration =
                new ForeignKeyConstraintConfiguration(
                    new List <PropertyInfo>
            {
                new MockPropertyInfo(typeof(int), "P1")
            });

            var clone = (ForeignKeyConstraintConfiguration)configuration.Clone();

            Assert.True(clone.IsFullySpecified);
            Assert.True(clone.ToProperties.Any(p => p.Name == "P1"));
        }
Beispiel #4
0
        public void Configure_should_add_properties_to_dependent_properties()
        {
            var mockPropertyInfo        = new MockPropertyInfo(typeof(int), "P");
            var constraintConfiguration = new ForeignKeyConstraintConfiguration(new[] { mockPropertyInfo.Object });
            var entityType = new EntityType();
            var property1  = EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

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

            property.SetClrPropertyInfo(mockPropertyInfo);
            var associationType = new AssociationType();

            associationType.SourceEnd = new AssociationEndMember("S", entityType);
            associationType.TargetEnd = new AssociationEndMember("T", new EntityType());

            constraintConfiguration.Configure(
                associationType, associationType.SourceEnd, new EntityTypeConfiguration(typeof(object)));

            Assert.Equal(1, associationType.Constraint.ToProperties.Count);
        }
Beispiel #5
0
        public void Configure_should_throw_when_dependent_property_not_found()
        {
            var constraintConfiguration
                = new ForeignKeyConstraintConfiguration(
                      new[]
            {
                new MockPropertyInfo(typeof(int), "P").Object
            });
            var associationType = new AssociationType();

            Assert.Equal(
                Strings.ForeignKeyPropertyNotFound("P", "T"),
                Assert.Throws <InvalidOperationException>(
                    () => constraintConfiguration.Configure(
                        associationType,
                        new AssociationEndMember(
                            "E", new EntityType
            {
                Name = "T"
            })
                        , new EntityTypeConfiguration(typeof(object)))).Message);
        }
Beispiel #6
0
        public void Configure_should_propagate_end_kind_to_keys_when_required()
        {
            var mockPropertyInfo        = new MockPropertyInfo(typeof(int), "P");
            var constraintConfiguration = new ForeignKeyConstraintConfiguration(new[] { mockPropertyInfo.Object });
            var entityType = new EntityType();
            var property1  = EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

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

            property.Nullable = true;
            property.SetClrPropertyInfo(mockPropertyInfo);
            var associationType = new AssociationType();

            associationType.SourceEnd = new AssociationEndMember("S", entityType);
            associationType.TargetEnd = new AssociationEndMember("T", new EntityType());
            associationType.TargetEnd.RelationshipMultiplicity = RelationshipMultiplicity.One;

            constraintConfiguration.Configure(
                associationType, associationType.SourceEnd, new EntityTypeConfiguration(typeof(object)));

            Assert.Equal(1, associationType.Constraint.ToProperties.Count);
            Assert.Equal(false, property.Nullable);
        }