Exemplo n.º 1
0
        public void Configure_should_rename_columns_when_left_keys_configured()
        {
            var database = new EdmModel().Initialize();
            var associationSetMapping
                = new StorageAssociationSetMapping(
                      new AssociationSet("AS", new AssociationType()), new EntitySet())
                  .Initialize();
            var column = new EdmProperty("C");

            associationSetMapping.SourceEndMapping.AddProperty(new StorageScalarPropertyMapping(new EdmProperty("PK"), column));

            var manyToManyAssociationMappingConfiguration
                = new ManyToManyAssociationMappingConfiguration();

            manyToManyAssociationMappingConfiguration.MapLeftKey("NewName");

            var mockPropertyInfo = new MockPropertyInfo();

            associationSetMapping.SourceEndMapping.EndMember = new AssociationEndMember("S", new EntityType());
            associationSetMapping.SourceEndMapping.EndMember.SetClrPropertyInfo(mockPropertyInfo);

            manyToManyAssociationMappingConfiguration.Configure(associationSetMapping, database, mockPropertyInfo);

            Assert.Equal("NewName", column.Name);
        }
        public void Configure_should_configure_inverse()
        {
            var inverseMockPropertyInfo = new MockPropertyInfo();
            var navigationPropertyConfiguration = new NavigationPropertyConfiguration(new MockPropertyInfo())
                                                      {
                                                          InverseNavigationProperty = inverseMockPropertyInfo
                                                      };
            var associationType = new EdmAssociationType().Initialize();
            var inverseAssociationType = new EdmAssociationType().Initialize();
            var model = new EdmModel().Initialize();
            model.AddAssociationType(inverseAssociationType);
            var inverseNavigationProperty
                = model.AddEntityType("T")
                    .AddNavigationProperty("N", inverseAssociationType);
            inverseNavigationProperty.SetClrPropertyInfo(inverseMockPropertyInfo);

            navigationPropertyConfiguration.Configure(
                new EdmNavigationProperty
                    {
                        Association = associationType
                    }, model, new EntityTypeConfiguration(typeof(object)));

            Assert.Same(associationType, inverseNavigationProperty.Association);
            Assert.Same(associationType.SourceEnd, inverseNavigationProperty.ResultEnd);
            Assert.Equal(0, model.GetAssociationTypes().Count());
        }
        public void Apply_methods_delegate_to_ConventionsConfiguration()
        {
            var modelConfiguration = new ModelConfiguration();
            var mockPropertyInfo   = new MockPropertyInfo(typeof(string), "S");
            Func <PropertyConfiguration> propertyConfiguration = () =>
                                                                 new StringPropertyConfiguration();
            Func <StructuralTypeConfiguration> entityConfiguration = () => new EntityTypeConfiguration(typeof(object));

            Verify_method_delegates(
                c => c.ApplyModelConfiguration(modelConfiguration),
                c => c.ApplyModelConfiguration(modelConfiguration));
            Verify_method_delegates(
                c => c.ApplyModelConfiguration(typeof(object), modelConfiguration),
                c => c.ApplyModelConfiguration(typeof(object), modelConfiguration));
            Verify_method_delegates(
                c => c.ApplyPropertyConfiguration(mockPropertyInfo, propertyConfiguration, modelConfiguration),
                c => c.ApplyPropertyConfiguration(mockPropertyInfo, propertyConfiguration, modelConfiguration));
            Verify_method_delegates(
                c => c.ApplyPropertyConfiguration(mockPropertyInfo, modelConfiguration),
                c => c.ApplyPropertyConfiguration(mockPropertyInfo, modelConfiguration));
            Verify_method_delegates(
                c => c.ApplyPropertyTypeConfiguration(mockPropertyInfo, entityConfiguration, modelConfiguration),
                c => c.ApplyPropertyTypeConfiguration(mockPropertyInfo, entityConfiguration, modelConfiguration));
            Verify_method_delegates(
                c => c.ApplyTypeConfiguration(typeof(object), entityConfiguration, modelConfiguration),
                c => c.ApplyTypeConfiguration(typeof(object), entityConfiguration, modelConfiguration));
        }
        public void Configure_should_configure_and_order_keys_when_keys_and_order_specified()
        {
            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            var property   = EdmProperty.CreatePrimitive("P2", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            entityType.AddMember(property);
            var property1 = EdmProperty.CreatePrimitive("P1", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            entityType.AddMember(property1);

            var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object));
            var mockPropertyInfo2       = new MockPropertyInfo(typeof(int), "P2");

            entityTypeConfiguration.Key(mockPropertyInfo2);
            entityTypeConfiguration.Property(new PropertyPath(mockPropertyInfo2)).ColumnOrder = 1;
            (entityType.GetDeclaredPrimitiveProperties().SingleOrDefault(p => p.Name == "P2")).SetClrPropertyInfo(mockPropertyInfo2);
            var mockPropertyInfo1 = new MockPropertyInfo(typeof(int), "P1");

            entityTypeConfiguration.Key(mockPropertyInfo1);
            entityTypeConfiguration.Property(new PropertyPath(mockPropertyInfo1)).ColumnOrder = 0;
            (entityType.GetDeclaredPrimitiveProperties().SingleOrDefault(p => p.Name == "P1")).SetClrPropertyInfo(mockPropertyInfo1);

            entityTypeConfiguration.Configure(entityType, new EdmModel(DataSpace.CSpace));

            Assert.Equal(2, entityType.KeyProperties.Count);
            Assert.Equal("P1", entityType.KeyProperties.First().Name);
        }
        public void IsValidStructuralProperty_should_return_true_when_property_read_only_collection()
        {
            var mockProperty = new MockPropertyInfo(typeof(List<string>), "P");
            mockProperty.SetupGet(p => p.CanWrite).Returns(false);

            Assert.True(mockProperty.Object.IsValidStructuralProperty());
        }
        public void Inverse_navigation_property_should_throw_when_self_inverse()
        {
            var mockPropertyInfo = new MockPropertyInfo();
            var navigationPropertyConfiguration = new NavigationPropertyConfiguration(mockPropertyInfo);

            Assert.Equal(Strings.NavigationInverseItself("P", typeof(object)), Assert.Throws<InvalidOperationException>(() => navigationPropertyConfiguration.InverseNavigationProperty = mockPropertyInfo).Message);
        }
        public void IsValidStructuralProperty_should_return_false_when_property_read_only()
        {
            var mockProperty = new MockPropertyInfo();
            mockProperty.SetupGet(p => p.CanWrite).Returns(false);

            Assert.False(mockProperty.Object.IsValidStructuralProperty());
        }
            public void IsValidStructuralProperty_should_return_false_for_indexed_property()
            {
                var mockProperty = new MockPropertyInfo();
                mockProperty.Setup(p => p.GetIndexParameters()).Returns(new ParameterInfo[1]);

                Assert.False(mockProperty.Object.IsValidStructuralProperty());
            }
Exemplo n.º 9
0
        public void Configure_should_configure_function_mapping()
        {
            var functionsConfiguration = new ModificationFunctionsConfiguration();
            var functionConfiguration  = new ModificationFunctionConfiguration();

            functionConfiguration.HasName("Func");
            functionsConfiguration.Insert(functionConfiguration);

            var mockPropertyInfo = new MockPropertyInfo();

            var navigationPropertyConfiguration
                = new NavigationPropertyConfiguration(mockPropertyInfo)
                {
                ModificationFunctionsConfiguration = functionsConfiguration
                };

            var databaseMapping
                = new DbDatabaseMapping()
                  .Initialize(new EdmModel(DataSpace.CSpace), new EdmModel(DataSpace.SSpace));

            var associationSetMapping = databaseMapping.AddAssociationSetMapping(
                new AssociationSet("AS", new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)), new EntitySet());

            var dependentTable = databaseMapping.Database.AddTable("T");

            associationSetMapping.StoreEntitySet = databaseMapping.Database.GetEntitySet(dependentTable);
            associationSetMapping.AssociationSet.ElementType.SetConfiguration(navigationPropertyConfiguration);
            associationSetMapping.SourceEndMapping.EndMember = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace));
            associationSetMapping.SourceEndMapping.EndMember.SetClrPropertyInfo(mockPropertyInfo);

            navigationPropertyConfiguration.Configure(associationSetMapping, databaseMapping, ProviderRegistry.Sql2008_ProviderManifest);

            Assert.Equal("Func", associationSetMapping.ModificationFunctionMapping.InsertFunctionMapping.Function.Name);
        }
        public void Apply_should_transfer_constraint_and_clr_property_info_annotation()
        {
            EdmModel model
                = new TestModelBuilder()
                    .Entities("S", "T")
                    .Association("S", RelationshipMultiplicity.ZeroOrOne, "T", RelationshipMultiplicity.Many)
                    .Association("T", RelationshipMultiplicity.Many, "S", RelationshipMultiplicity.ZeroOrOne);

            var association2 = model.AssociationTypes.Last();

            var mockPropertyInfo = new MockPropertyInfo();
            association2.SourceEnd.SetClrPropertyInfo(mockPropertyInfo);

            var referentialConstraint 
                = new ReferentialConstraint(
                    association2.SourceEnd, 
                    association2.TargetEnd, 
                    new[] { new EdmProperty("P") }, 
                    new[] { new EdmProperty("D") });
            
            association2.Constraint = referentialConstraint;

            ((IEdmConvention)new AssociationInverseDiscoveryConvention()).Apply(model);

            Assert.Equal(1, model.AssociationTypes.Count());
            Assert.Equal(1, model.Containers.Single().AssociationSets.Count());

            var associationType = model.AssociationTypes.Single();

            Assert.NotSame(association2, associationType);
            Assert.Same(referentialConstraint, associationType.Constraint);
            Assert.Same(associationType.SourceEnd, referentialConstraint.FromRole);
            Assert.Same(associationType.TargetEnd, referentialConstraint.ToRole);
            Assert.Same(mockPropertyInfo.Object, associationType.TargetEnd.GetClrPropertyInfo());
        }
Exemplo n.º 11
0
        public void Configure_should_rename_columns_when_right_keys_configured()
        {
            var database = new EdmModel(DataSpace.CSpace);

            var associationSetMapping
                = new StorageAssociationSetMapping(
                    new AssociationSet("AS", new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)),
                    new EntitySet())
                    .Initialize();

            var column = new EdmProperty("C");

            associationSetMapping.TargetEndMapping.AddProperty(new StorageScalarPropertyMapping(new EdmProperty("PK"), column));

            var manyToManyAssociationMappingConfiguration
                = new ManyToManyAssociationMappingConfiguration();

            manyToManyAssociationMappingConfiguration.MapRightKey("NewName");

            var mockPropertyInfo = new MockPropertyInfo();

            associationSetMapping.SourceEndMapping.EndMember = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace));
            associationSetMapping.SourceEndMapping.EndMember.SetClrPropertyInfo(mockPropertyInfo);

            manyToManyAssociationMappingConfiguration.Configure(associationSetMapping, database, mockPropertyInfo);

            Assert.Equal("NewName", column.Name);
        }
        public void Configure_should_configure_mapping()
        {
            var manyToManyAssociationMappingConfiguration = new ManyToManyAssociationMappingConfiguration();

            manyToManyAssociationMappingConfiguration.ToTable("Foo");

            var mockPropertyInfo = new MockPropertyInfo(typeof(AType1), "N");

            var navigationPropertyConfiguration
                = new NavigationPropertyConfiguration(mockPropertyInfo)
                {
                AssociationMappingConfiguration = manyToManyAssociationMappingConfiguration
                };

            var databaseMapping
                = new DbDatabaseMapping()
                  .Initialize(new EdmModel(DataSpace.CSpace), new EdmModel(DataSpace.SSpace));

            var associationSetMapping = databaseMapping.AddAssociationSetMapping(
                new AssociationSet("AS", new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)), new EntitySet());

            var dependentTable = databaseMapping.Database.AddTable("T");

            associationSetMapping.StoreEntitySet = databaseMapping.Database.GetEntitySet(dependentTable);
            associationSetMapping.AssociationSet.ElementType.SetConfiguration(navigationPropertyConfiguration);

            associationSetMapping.SourceEndMapping.AssociationEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace));
            associationSetMapping.SourceEndMapping.AssociationEnd.SetClrPropertyInfo(mockPropertyInfo);

            navigationPropertyConfiguration.Configure(associationSetMapping, databaseMapping, ProviderRegistry.Sql2008_ProviderManifest);

            Assert.Equal("Foo", associationSetMapping.Table.GetTableName().Name);
        }
        public void Configure_should_configure_inverse()
        {
            var inverseMockPropertyInfo = new MockPropertyInfo();
            var navigationPropertyConfiguration = new NavigationPropertyConfiguration(new MockPropertyInfo())
                                                      {
                                                          InverseNavigationProperty = inverseMockPropertyInfo
                                                      };
            var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace);
            associationType.SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace));
            associationType.TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace));
            var inverseAssociationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace);
            inverseAssociationType.SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace));
            inverseAssociationType.TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace));
            var model = new EdmModel(DataSpace.CSpace);
            model.AddAssociationType(inverseAssociationType);
            var inverseNavigationProperty
                = model.AddEntityType("T")
                       .AddNavigationProperty("N", inverseAssociationType);
            inverseNavigationProperty.SetClrPropertyInfo(inverseMockPropertyInfo);

            navigationPropertyConfiguration.Configure(
                new NavigationProperty("N", TypeUsage.Create(associationType.TargetEnd.GetEntityType()))
                    {
                        RelationshipType = associationType
                    }, model, new EntityTypeConfiguration(typeof(object)));

            Assert.Same(associationType, inverseNavigationProperty.Association);
            Assert.Same(associationType.SourceEnd, inverseNavigationProperty.ResultEnd);
            Assert.Same(associationType.TargetEnd, inverseNavigationProperty.FromEndMember);
            Assert.Equal(0, model.AssociationTypes.Count());
        }
Exemplo n.º 14
0
        public void Merge_configurations_with_override()
        {
            var modificationFunctionConfigurationA = new ModificationFunctionConfiguration();

            modificationFunctionConfigurationA.HasName("Foo", "baz");

            var mockPropertyInfo = new MockPropertyInfo();

            modificationFunctionConfigurationA.Parameter(new PropertyPath(mockPropertyInfo), "baz");
            modificationFunctionConfigurationA.Result(new PropertyPath(mockPropertyInfo), "foo");
            modificationFunctionConfigurationA.RowsAffectedParameter("bar");

            var modificationFunctionConfigurationB = new ModificationFunctionConfiguration();

            modificationFunctionConfigurationB.HasName("2", "2");

            modificationFunctionConfigurationB.Parameter(new PropertyPath(mockPropertyInfo), "2");
            modificationFunctionConfigurationB.Result(new PropertyPath(mockPropertyInfo), "2");
            modificationFunctionConfigurationB.RowsAffectedParameter("2");

            modificationFunctionConfigurationA.Merge(modificationFunctionConfigurationB, allowOverride: true);

            Assert.Equal("2", modificationFunctionConfigurationA.Name);
            Assert.Equal("2", modificationFunctionConfigurationA.Schema);
            Assert.Equal(1, modificationFunctionConfigurationA.ParameterNames.Count(p => p.Item1 == "2"));
            Assert.Equal(1, modificationFunctionConfigurationA.ResultBindings.Count(p => p.Value == "2"));
            Assert.Equal("2", modificationFunctionConfigurationA.RowsAffectedParameterName);
        }
Exemplo n.º 15
0
        public void Configure_should_rename_table_when_table_configured()
        {
            var database = new EdmModel(DataSpace.SSpace);
            var table = database.AddTable("OriginalName");

            var associationSetMapping
                = new StorageAssociationSetMapping(
                    new AssociationSet("AS", new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)),
                    database.GetEntitySet(table))
                    .Initialize();

            var manyToManyAssociationMappingConfiguration
                = new ManyToManyAssociationMappingConfiguration();

            manyToManyAssociationMappingConfiguration.ToTable("NewName");

            var mockPropertyInfo = new MockPropertyInfo();

            associationSetMapping.SourceEndMapping.EndMember = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace));
            associationSetMapping.SourceEndMapping.EndMember.SetClrPropertyInfo(mockPropertyInfo);

            manyToManyAssociationMappingConfiguration.Configure(associationSetMapping, database, mockPropertyInfo);

            Assert.Equal("NewName", table.GetTableName().Name);
            Assert.Same(manyToManyAssociationMappingConfiguration, table.GetConfiguration());
        }
        public void IsCompatibleWith_should_return_true_when_name_and_parameters_compatible()
        {
            var modificationFunctionConfiguration1 = new ModificationFunctionConfiguration();
            var modificationFunctionConfiguration2 = new ModificationFunctionConfiguration();

            Assert.True(modificationFunctionConfiguration1.IsCompatibleWith(modificationFunctionConfiguration2));

            modificationFunctionConfiguration1.HasName("P", "S");

            Assert.True(modificationFunctionConfiguration1.IsCompatibleWith(modificationFunctionConfiguration2));

            modificationFunctionConfiguration2.HasName("P", "S");

            Assert.True(modificationFunctionConfiguration1.IsCompatibleWith(modificationFunctionConfiguration2));

            var mockPropertyInfo1 = new MockPropertyInfo(typeof(int), "I");
            var mockPropertyInfo2 = new MockPropertyInfo(typeof(string), "S");
            var mockPropertyInfo3 = new MockPropertyInfo(typeof(bool), "B");

            modificationFunctionConfiguration1.Parameter(new PropertyPath(mockPropertyInfo1), "baz");
            modificationFunctionConfiguration1.Parameter(new PropertyPath(mockPropertyInfo2), "baz");
            modificationFunctionConfiguration1.Parameter(new PropertyPath(mockPropertyInfo3), "baz");

            Assert.True(modificationFunctionConfiguration1.IsCompatibleWith(modificationFunctionConfiguration2));

            modificationFunctionConfiguration2.Parameter(new PropertyPath(mockPropertyInfo3), "baz");
            modificationFunctionConfiguration2.Parameter(new PropertyPath(mockPropertyInfo2), "baz");
            modificationFunctionConfiguration2.Parameter(new PropertyPath(mockPropertyInfo1), "baz");

            Assert.True(modificationFunctionConfiguration1.IsCompatibleWith(modificationFunctionConfiguration2));
        }
Exemplo n.º 17
0
        public void AddCollectionProperty_ThrowsIfTypeIsDateTime(Type propertyType)
        {
            // Arrange
            MockType         type     = new MockType("Customer", @namespace: "Contoso");
            MockPropertyInfo property = new MockPropertyInfo(propertyType, "Birthday");

            property.SetupGet(p => p.ReflectedType).Returns(type);
            property.SetupGet(p => p.DeclaringType).Returns(type);

            Mock <StructuralTypeConfiguration> mock = new Mock <StructuralTypeConfiguration> {
                CallBase = true
            };

            mock.Setup(e => e.ModelBuilder).Returns(new Mock <ODataModelBuilder>().Object);
            StructuralTypeConfiguration configuration = mock.Object;

            mock.SetupGet(c => c.ClrType).Returns(type);

            // Act & Assert
            Assert.ThrowsArgument(
                () => configuration.AddCollectionProperty(property),
                "propertyInfo",
                string.Format(
                    "The type '{0}' of property 'Birthday' in the 'Contoso.Customer' type is not a supported type.",
                    propertyType.FullName));
        }
Exemplo n.º 18
0
        public void AsEdmPrimitiveProperty_sets_is_nullable_for_nullable_type()
        {
            PropertyInfo propertyInfo = new MockPropertyInfo(typeof(string), "P");
            var          property     = propertyInfo.AsEdmPrimitiveProperty();

            Assert.Equal(true, property.Nullable);
        }
Exemplo n.º 19
0
        public void Configure_should_configure_mapping()
        {
            var manyToManyAssociationMappingConfiguration = new ManyToManyAssociationMappingConfiguration();

            manyToManyAssociationMappingConfiguration.ToTable("Foo");

            var mockPropertyInfo = new MockPropertyInfo();

            var navigationPropertyConfiguration
                = new NavigationPropertyConfiguration(mockPropertyInfo)
                {
                AssociationMappingConfiguration = manyToManyAssociationMappingConfiguration
                };

            var databaseMapping
                = new DbDatabaseMapping()
                  .Initialize(new EdmModel().Initialize(), new EdmModel().Initialize());

            var associationSetMapping = databaseMapping.AddAssociationSetMapping(
                new AssociationSet("AS", new AssociationType()), new EntitySet());

            var dependentTable = databaseMapping.Database.AddTable("T");

            associationSetMapping.StoreEntitySet = databaseMapping.Database.GetEntitySet(dependentTable);
            associationSetMapping.AssociationSet.ElementType.SetConfiguration(navigationPropertyConfiguration);

            associationSetMapping.SourceEndMapping.EndMember = new AssociationEndMember("S", new EntityType());
            associationSetMapping.SourceEndMapping.EndMember.SetClrPropertyInfo(mockPropertyInfo);

            navigationPropertyConfiguration.Configure(associationSetMapping, databaseMapping);

            Assert.Equal("Foo", associationSetMapping.Table.GetTableName().Name);
        }
Exemplo n.º 20
0
        public void Configure_should_configure_inverse()
        {
            var inverseMockPropertyInfo         = new MockPropertyInfo();
            var navigationPropertyConfiguration = new NavigationPropertyConfiguration(new MockPropertyInfo())
            {
                InverseNavigationProperty = inverseMockPropertyInfo
            };
            var associationType = new AssociationType();

            associationType.SourceEnd = new AssociationEndMember("S", new EntityType());
            associationType.TargetEnd = new AssociationEndMember("T", new EntityType());
            var inverseAssociationType = new AssociationType();

            inverseAssociationType.SourceEnd = new AssociationEndMember("S", new EntityType());
            inverseAssociationType.TargetEnd = new AssociationEndMember("T", new EntityType());
            var model = new EdmModel().Initialize();

            model.AddAssociationType(inverseAssociationType);
            var inverseNavigationProperty
                = model.AddEntityType("T")
                  .AddNavigationProperty("N", inverseAssociationType);

            inverseNavigationProperty.SetClrPropertyInfo(inverseMockPropertyInfo);

            navigationPropertyConfiguration.Configure(
                new NavigationProperty("N", TypeUsage.Create(associationType.TargetEnd.GetEntityType()))
            {
                RelationshipType = associationType
            }, model, new EntityTypeConfiguration(typeof(object)));

            Assert.Same(associationType, inverseNavigationProperty.Association);
            Assert.Same(associationType.SourceEnd, inverseNavigationProperty.ResultEnd);
            Assert.Equal(0, model.GetAssociationTypes().Count());
        }
Exemplo n.º 21
0
        public void Configure_should_configure_constraint()
        {
            var mockType         = new MockType();
            var mockPropertyInfo = new MockPropertyInfo(typeof(int), "P");
            var navigationPropertyConfiguration = new NavigationPropertyConfiguration(new MockPropertyInfo())
            {
                Constraint =
                    new ForeignKeyConstraintConfiguration(new[] { mockPropertyInfo.Object })
            };
            var associationType = new AssociationType();

            associationType.SourceEnd = new AssociationEndMember("S", new EntityType());
            associationType.TargetEnd = new AssociationEndMember("T", new EntityType());
            var tempQualifier = associationType.SourceEnd.GetEntityType();

            tempQualifier.Annotations.SetClrType(mockType);
            associationType.SourceEnd.RelationshipMultiplicity = RelationshipMultiplicity.Many;
            var property1 = EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            associationType.SourceEnd.GetEntityType().AddMember(property1);
            var property = property1;

            property.SetClrPropertyInfo(mockPropertyInfo);

            navigationPropertyConfiguration.Configure(
                new NavigationProperty("N", TypeUsage.Create(associationType.TargetEnd.GetEntityType()))
            {
                RelationshipType = associationType
            },
                new EdmModel(), new EntityTypeConfiguration(typeof(object)));

            Assert.NotNull(associationType.Constraint);
            Assert.Same(associationType.SourceEnd, associationType.Constraint.DependentEnd);
            Assert.True(associationType.Constraint.ToProperties.Any());
        }
        public void Configure_should_configure_constraint()
        {
            var mockType         = typeof(AType1);
            var mockPropertyInfo = new MockPropertyInfo(typeof(AType1), "P");
            var navigationPropertyConfiguration = new NavigationPropertyConfiguration(new MockPropertyInfo(typeof(AType1), "N"))
            {
                Constraint =
                    new ForeignKeyConstraintConfiguration(new[] { mockPropertyInfo.Object })
            };
            var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace);

            associationType.SourceEnd = new AssociationEndMember("S", new EntityType("SE", "N", DataSpace.CSpace));
            associationType.TargetEnd = new AssociationEndMember("T", new EntityType("TE", "N", DataSpace.CSpace));

            associationType.SourceEnd.GetEntityType().GetMetadataProperties().SetClrType(mockType);
            associationType.SourceEnd.RelationshipMultiplicity = RelationshipMultiplicity.Many;
            var property1 = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            associationType.SourceEnd.GetEntityType().AddMember(property1);
            var property = property1;

            property.SetClrPropertyInfo(mockPropertyInfo);

            navigationPropertyConfiguration.Configure(
                new NavigationProperty("N", TypeUsage.Create(associationType.TargetEnd.GetEntityType()))
            {
                RelationshipType = associationType
            },
                new EdmModel(DataSpace.CSpace), new EntityTypeConfiguration(mockType));

            Assert.NotNull(associationType.Constraint);
            Assert.Same(associationType.SourceEnd, associationType.Constraint.ToRole);
            Assert.Same(associationType.TargetEnd, associationType.Constraint.FromRole);
            Assert.True(associationType.Constraint.ToProperties.Any());
        }
Exemplo n.º 23
0
        public void Configure_should_throw_when_incorrect_number_of_columns_configured()
        {
            var database = new EdmModel(DataSpace.CSpace);

            var associationSetMapping
                = new StorageAssociationSetMapping(
                    new AssociationSet("AS", new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)),
                    new EntitySet())
                    .Initialize();

            var manyToManyAssociationMappingConfiguration
                = new ManyToManyAssociationMappingConfiguration();

            manyToManyAssociationMappingConfiguration.MapLeftKey("Id1", "Id2");

            var mockPropertyInfo = new MockPropertyInfo();

            associationSetMapping.SourceEndMapping.EndMember = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace));
            associationSetMapping.SourceEndMapping.EndMember.SetClrPropertyInfo(mockPropertyInfo);

            Assert.Equal(
                Strings.IncorrectColumnCount("Id1, Id2"),
                Assert.Throws<InvalidOperationException>(
                    () => manyToManyAssociationMappingConfiguration.Configure(associationSetMapping, database, mockPropertyInfo)).Message);
        }
        public void Configure_should_validate_consistency_of_inverse_end_kind_when_already_configured()
        {
            var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace);

            associationType.SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace));
            associationType.TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace));
            var mockPropertyInfo = new MockPropertyInfo(typeof(AType1), "N1");
            var navigationPropertyConfigurationA
                = new NavigationPropertyConfiguration(mockPropertyInfo)
                {
                RelationshipMultiplicity = RelationshipMultiplicity.ZeroOrOne
                };

            associationType.SetConfiguration(navigationPropertyConfigurationA);
            var navigationPropertyConfigurationB
                = new NavigationPropertyConfiguration(new MockPropertyInfo(typeof(AType1), "N2"))
                {
                InverseEndKind            = RelationshipMultiplicity.Many,
                InverseNavigationProperty = mockPropertyInfo
                };

            Assert.Equal(
                Strings.ConflictingMultiplicities("N1", typeof(object)),
                Assert.Throws <InvalidOperationException>(
                    () => navigationPropertyConfigurationB.Configure(
                        new NavigationProperty("N", TypeUsage.Create(associationType.TargetEnd.GetEntityType()))
            {
                RelationshipType = associationType
            },
                        new EdmModel(DataSpace.CSpace), new EntityTypeConfiguration(typeof(object)))).Message);
        }
        public void Cloning_a_navigation_property_configuration_clones_its_property_information()
        {
            var navProp       = new MockPropertyInfo(typeof(AType1), "P1");
            var configuration = new NavigationPropertyConfiguration(navProp);

            configuration.RelationshipMultiplicity = RelationshipMultiplicity.Many;
            var inverseNavProp = new MockPropertyInfo(typeof(int), "P2");

            configuration.InverseNavigationProperty = inverseNavProp;
            configuration.InverseEndKind            = RelationshipMultiplicity.ZeroOrOne;
            configuration.DeleteAction = OperationAction.Cascade;
            configuration.IsNavigationPropertyDeclaringTypePrincipal = true;

            var clone = configuration.Clone();

            Assert.Equal(navProp, clone.NavigationProperty);
            Assert.Equal(RelationshipMultiplicity.Many, clone.RelationshipMultiplicity);
            Assert.Equal(inverseNavProp, clone.InverseNavigationProperty);
            Assert.Equal(RelationshipMultiplicity.ZeroOrOne, clone.InverseEndKind);
            Assert.Equal(OperationAction.Cascade, clone.DeleteAction);
            Assert.True(clone.IsNavigationPropertyDeclaringTypePrincipal.Value);

            Assert.Null(clone.Constraint);
            Assert.Null(clone.AssociationMappingConfiguration);
        }
        public void Configure_should_configure_inverse()
        {
            var inverseMockPropertyInfo         = new MockPropertyInfo();
            var navigationPropertyConfiguration = new NavigationPropertyConfiguration(new MockPropertyInfo(typeof(AType1), "N"))
            {
                InverseNavigationProperty = inverseMockPropertyInfo
            };
            var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace);

            associationType.SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace));
            associationType.TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace));
            var inverseAssociationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace);

            inverseAssociationType.SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace));
            inverseAssociationType.TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace));
            var model = new EdmModel(DataSpace.CSpace);

            model.AddAssociationType(inverseAssociationType);
            var inverseNavigationProperty
                = model.AddEntityType("T")
                  .AddNavigationProperty("N", inverseAssociationType);

            inverseNavigationProperty.SetClrPropertyInfo(inverseMockPropertyInfo);

            navigationPropertyConfiguration.Configure(
                new NavigationProperty("N", TypeUsage.Create(associationType.TargetEnd.GetEntityType()))
            {
                RelationshipType = associationType
            }, model, new EntityTypeConfiguration(typeof(object)));

            Assert.Same(associationType, inverseNavigationProperty.Association);
            Assert.Same(associationType.SourceEnd, inverseNavigationProperty.ResultEnd);
            Assert.Same(associationType.TargetEnd, inverseNavigationProperty.FromEndMember);
            Assert.Equal(0, model.AssociationTypes.Count());
        }
        public void Merge_configurations_with_override()
        {
            var modificationFunctionConfigurationA = new ModificationFunctionConfiguration();

            modificationFunctionConfigurationA.HasName("Foo", "baz");

            var mockPropertyInfo = new MockPropertyInfo();

            modificationFunctionConfigurationA.Parameter(new PropertyPath(mockPropertyInfo), "baz");
            modificationFunctionConfigurationA.Result(new PropertyPath(mockPropertyInfo), "foo");
            modificationFunctionConfigurationA.RowsAffectedParameter("bar");

            var modificationFunctionConfigurationB = new ModificationFunctionConfiguration();

            modificationFunctionConfigurationB.HasName("2", "2");

            modificationFunctionConfigurationB.Parameter(new PropertyPath(mockPropertyInfo), "2");
            modificationFunctionConfigurationB.Result(new PropertyPath(mockPropertyInfo), "2");
            modificationFunctionConfigurationB.RowsAffectedParameter("2");

            modificationFunctionConfigurationA.Merge(modificationFunctionConfigurationB, allowOverride: true);

            Assert.Equal("2", modificationFunctionConfigurationA.Name);
            Assert.Equal("2", modificationFunctionConfigurationA.Schema);
            Assert.Equal(1, modificationFunctionConfigurationA.ParameterNames.Count(p => p.Item1 == "2"));
            Assert.Equal(1, modificationFunctionConfigurationA.ResultBindings.Count(p => p.Value == "2"));
            Assert.Equal("2", modificationFunctionConfigurationA.RowsAffectedParameterName);
        }
        public void Configure_should_throw_when_result_binding_not_found()
        {
            var modificationFunctionConfiguration = new ModificationFunctionConfiguration();

            var mockPropertyInfo1 = new MockPropertyInfo();

            modificationFunctionConfiguration
            .Result(new PropertyPath(mockPropertyInfo1), "Foo");

            var entitySet = new EntitySet();

            entitySet.ChangeEntityContainerWithoutCollectionFixup(new EntityContainer("C", DataSpace.CSpace));

            Assert.Equal(
                Strings.ResultBindingNotFound("P", "F"),
                Assert.Throws <InvalidOperationException>(
                    () => modificationFunctionConfiguration.Configure(
                        new StorageModificationFunctionMapping(
                            entitySet,
                            new EntityType("E", "N", DataSpace.CSpace),
                            new EdmFunction("F", "N", DataSpace.SSpace),
                            new StorageModificationFunctionParameterBinding[0],
                            null,
                            null),
                        ProviderRegistry.Sql2008_ProviderManifest)).Message);
        }
        public void Configure_should_wnsure_consistency_of_inverse_end_kind_when_already_configured()
        {
            var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace);

            associationType.SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace));
            associationType.TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace));
            var mockPropertyInfo = new MockPropertyInfo(typeof(AType1), "N1");
            var navigationPropertyConfigurationA
                = new NavigationPropertyConfiguration(mockPropertyInfo);

            associationType.SetConfiguration(navigationPropertyConfigurationA);
            var navigationPropertyConfigurationB
                = new NavigationPropertyConfiguration(new MockPropertyInfo(typeof(AType1), "N2"))
                {
                InverseEndKind            = RelationshipMultiplicity.Many,
                InverseNavigationProperty = mockPropertyInfo
                };

            navigationPropertyConfigurationB.Configure(
                new NavigationProperty("N", TypeUsage.Create(associationType.TargetEnd.GetEntityType()))
            {
                RelationshipType = associationType
            },
                new EdmModel(DataSpace.CSpace), new EntityTypeConfiguration(typeof(object)));

            Assert.Equal(RelationshipMultiplicity.Many, navigationPropertyConfigurationA.RelationshipMultiplicity);
        }
Exemplo n.º 30
0
        public void AddProperty <T> (string name, string category = null,
                                     bool canWrite = true, bool flag = false,
                                     IEnumerable <Type> converterTypes = null,
                                     string description = null, bool constrained = true, ValueSources valueSources = ValueSources.Local | ValueSources.Default | ValueSources.Binding,
                                     IReadOnlyList <InputMode> inputModes = null, PropertyVariationOption[] options = null, bool isUncommon = false, ITypeInfo realType = null, bool ignoreEnum = false)
        {
            IPropertyInfo propertyInfo;

            if (typeof(T).IsEnum && !ignoreEnum)
            {
                var underlyingType       = typeof(T).GetEnumUnderlyingType();
                var enumPropertyInfoType = typeof(MockEnumPropertyInfo <,>)
                                           .MakeGenericType(underlyingType, typeof(T));
                propertyInfo = (IPropertyInfo)Activator.CreateInstance(enumPropertyInfoType, name, description, category, canWrite, flag, converterTypes, constrained, options);
            }
            else if (inputModes != null)
            {
                propertyInfo = new MockPropertyInfoWithInputTypes <T> (name, inputModes, description, category, canWrite, converterTypes, valueSources, options);
            }
            else
            {
                propertyInfo = new MockPropertyInfo <T> (name, description, category, canWrite, converterTypes, valueSources, options, isUncommon, realType);
            }

            AddProperty <T> (propertyInfo);
        }
Exemplo n.º 31
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("SE", "N", DataSpace.CSpace);

            entityType.GetMetadataProperties().SetClrType(typeof(object));
            var property1 = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

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

            property.Nullable = true;
            property.SetClrPropertyInfo(mockPropertyInfo);
            var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace);

            associationType.SourceEnd = new AssociationEndMember("S", entityType);
            associationType.TargetEnd = new AssociationEndMember("T", new EntityType("TE", "N", DataSpace.CSpace));
            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);
        }
Exemplo n.º 32
0
        public void IsValidStructuralProperty_should_return_false_when_property_read_only()
        {
            var mockProperty = new MockPropertyInfo();

            mockProperty.SetupGet(p => p.CanWrite).Returns(false);

            Assert.False(mockProperty.Object.IsValidStructuralProperty());
        }
Exemplo n.º 33
0
        public void IsValidStructuralProperty_should_return_true_when_property_read_only_collection()
        {
            var mockProperty = new MockPropertyInfo(typeof(List <string>), "P");

            mockProperty.SetupGet(p => p.CanWrite).Returns(false);

            Assert.True(mockProperty.Object.IsValidStructuralProperty());
        }
Exemplo n.º 34
0
        public void ClrPropertyInfo_returns_propertyInfo()
        {
            var propertyInfo = new MockPropertyInfo();
            var innerConfig  = new PrimitivePropertyConfiguration();
            var config       = new LightweightPropertyConfiguration(propertyInfo, () => innerConfig);

            Assert.Same(propertyInfo.Object, config.ClrPropertyInfo);
        }
Exemplo n.º 35
0
        public void IsValidStructuralProperty_should_return_false_for_indexed_property()
        {
            var mockProperty = new MockPropertyInfo();

            mockProperty.Setup(p => p.GetIndexParameters()).Returns(new ParameterInfo[1]);

            Assert.False(mockProperty.Object.IsValidStructuralProperty());
        }
        public void Can_set_column_name_for_result_binding()
        {
            var modificationFunctionConfiguration = new ModificationFunctionConfiguration();

            var mockPropertyInfo = new MockPropertyInfo();

            modificationFunctionConfiguration.Result(new PropertyPath(mockPropertyInfo), "foo");

            Assert.Same("foo", modificationFunctionConfiguration.ResultBindings.Single().Value);
        }
        public void Apply_should_ignore_property()
        {
            var mockPropertyInfo = new MockPropertyInfo();
            var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object));

            new NotMappedPropertyAttributeConvention.NotMappedPropertyAttributeConventionImpl()
                .Apply(mockPropertyInfo, entityTypeConfiguration, new NotMappedAttribute());

            Assert.True(entityTypeConfiguration.IgnoredProperties.Contains(mockPropertyInfo));
        }
        public void ApplyPropertyConfiguration_should_run_property_configuration_conventions()
        {
            var mockConvention           = new Mock <IConfigurationConvention <PropertyInfo, Properties.Primitive.StringPropertyConfiguration> >();
            var conventionsConfiguration = new ConventionsConfiguration(new[] { mockConvention.Object });
            var mockPropertyInfo         = new MockPropertyInfo(typeof(string), "S");

            conventionsConfiguration.ApplyPropertyConfiguration(mockPropertyInfo, () => new Properties.Primitive.StringPropertyConfiguration());

            mockConvention.Verify(c => c.Apply(mockPropertyInfo, It.IsAny <Func <Properties.Primitive.StringPropertyConfiguration> >()), Times.AtMostOnce());
        }
        public void Can_set_column_name_for_result_binding()
        {
            var modificationFunctionConfiguration = new ModificationFunctionConfiguration();

            var mockPropertyInfo = new MockPropertyInfo();

            modificationFunctionConfiguration.Result(new PropertyPath(mockPropertyInfo), "foo");

            Assert.Same("foo", modificationFunctionConfiguration.ResultBindings.Single().Value);
        }
        public void Apply_should_find_single_key()
        {
            var mockPropertyInfo = new MockPropertyInfo(typeof(int), "Id");
            var mockEntityTypeConfiguration = new Mock<EntityTypeConfiguration>(typeof(object));

            new KeyAttributeConvention.KeyAttributeConventionImpl()
                .Apply(mockPropertyInfo, mockEntityTypeConfiguration.Object, new KeyAttribute());

            mockEntityTypeConfiguration.Verify(e => e.Key(mockPropertyInfo, null));
        }
        public void Inverse_navigation_property_should_throw_when_self_inverse()
        {
            var mockPropertyInfo = new MockPropertyInfo(typeof(AType1), "N");
            var navigationPropertyConfiguration = new NavigationPropertyConfiguration(mockPropertyInfo);

            Assert.Equal(
                Strings.NavigationInverseItself("N", typeof(object)),
                Assert.Throws <InvalidOperationException>(() => navigationPropertyConfiguration.InverseNavigationProperty = mockPropertyInfo)
                .Message);
        }
        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 AddDynamicPropertyDictionary_ThrowsIfTypeIsNotDictionary()
        {
            // Arrange
            MockPropertyInfo property = new MockPropertyInfo(typeof(Int32), "Test");
            Mock<StructuralTypeConfiguration> mock = new Mock<StructuralTypeConfiguration> { CallBase = true };
            StructuralTypeConfiguration configuration = mock.Object;

            // Act & Assert
            Assert.ThrowsArgument(() => configuration.AddDynamicPropertyDictionary(property),
                "propertyInfo",
                string.Format("The argument must be of type '{0}'.", "IDictionary<string, object>"));
        }
        public void HasConstraint_sets_and_configures_the_ForeignKeyConstraint()
        {
            var property = new MockPropertyInfo();
            var configuration =
                new NavigationPropertyConfiguration(
                    typeof(LightweighEntity).GetDeclaredProperty("ValidNavigationProperty"));
            var lightweightConfiguration = new ConventionNavigationPropertyConfiguration(configuration, new ModelConfiguration());

            lightweightConfiguration.HasConstraint<ForeignKeyConstraintConfiguration>(c => c.AddColumn(property));
            Assert.IsType<ForeignKeyConstraintConfiguration>(configuration.Constraint);
            Assert.Same(property.Object, ((ForeignKeyConstraintConfiguration)configuration.Constraint).ToProperties.Single());
        }
        public void Can_add_parameter_configuration()
        {
            var modificationFunctionConfiguration = new ModificationFunctionConfiguration();

            Assert.Empty(modificationFunctionConfiguration.ParameterNames);

            var mockPropertyInfo = new MockPropertyInfo();

            modificationFunctionConfiguration.Parameter(new PropertyPath(mockPropertyInfo), "baz");

            Assert.Equal("baz", modificationFunctionConfiguration.ParameterNames.Single().Value.Item1);
        }
Exemplo n.º 46
0
            public void IsValidStructuralProperty_should_return_true_when_property_read_only_collection()
            {
                var mockProperty = new MockPropertyInfo(typeof(List<string>), "Coll");
                mockProperty.SetupGet(p => p.CanWrite).Returns(false);

                var mockType = new MockType();
                mockType.Setup(m => m.GetProperties(It.IsAny<BindingFlags>())).Returns(new[] { mockProperty.Object });

                mockProperty.SetupGet(p => p.DeclaringType).Returns(mockType.Object);

                Assert.True(mockProperty.Object.IsValidStructuralProperty());
            }
        public void GetConfiguredProperties_should_return_all_configured_properties()
        {
            var modelConfiguration = new ModelConfiguration();
            var mockType = new MockType();
            var mockPropertyInfo = new MockPropertyInfo(typeof(string), "S");

            Assert.False(modelConfiguration.GetConfiguredProperties(mockType).Any());

            modelConfiguration.Entity(mockType).Property(new PropertyPath(mockPropertyInfo));

            Assert.Same(mockPropertyInfo.Object, modelConfiguration.GetConfiguredProperties(mockType).Single());
        }
        public void IsIgnoredProperty_should_return_true_if_property_is_ignored()
        {
            var modelConfiguration = new ModelConfiguration();
            var mockType = new MockType();
            var mockPropertyInfo = new MockPropertyInfo(typeof(string), "S");

            Assert.False(modelConfiguration.IsIgnoredProperty(mockType, mockPropertyInfo));

            modelConfiguration.Entity(mockType).Ignore(mockPropertyInfo);

            Assert.True(modelConfiguration.IsIgnoredProperty(mockType, mockPropertyInfo));
        }
        public void Apply_invokes_action_when_no_predicates()
        {
            var actionInvoked = false;
            var convention = new PropertyConvention(
                Enumerable.Empty<Func<PropertyInfo, bool>>(),
                c => actionInvoked = true);
            var propertyInfo = new MockPropertyInfo();
            var configuration = new PrimitivePropertyConfiguration();

            convention.Apply(propertyInfo, () => configuration, new ModelConfiguration());

            Assert.True(actionInvoked);
        }
        public void Apply_does_not_invoke_action_when_single_predicate_false()
        {
            var actionInvoked = false;
            var convention = new PropertyConvention(
                new Func<PropertyInfo, bool>[] { p => false },
                c => actionInvoked = true);
            var propertyInfo = new MockPropertyInfo();
            var configuration = new PrimitivePropertyConfiguration();

            convention.Apply(propertyInfo, () => configuration, new ModelConfiguration());

            Assert.False(actionInvoked);
        }
        public void Apply_does_not_invoke_action_when_value_null()
        {
            var actionInvoked = false;
            var convention = new PropertyConventionWithHaving<object>(
                Enumerable.Empty<Func<PropertyInfo, bool>>(),
                p => null,
                (c, v) => actionInvoked = true);
            var propertyInfo = new MockPropertyInfo();
            var configuration = new Configuration.Properties.Primitive.PrimitivePropertyConfiguration();

            convention.Apply(propertyInfo, () => configuration, new ModelConfiguration());

            Assert.False(actionInvoked);
        }
Exemplo n.º 52
0
        public void Generic_Properties_filter_on_type()
        {
            var decimalProperty = new MockPropertyInfo(typeof(decimal), "Property1");
            var nullableDecimalProperty = new MockPropertyInfo(typeof(decimal?), "Property2");
            var nonDecimalProperty = new MockPropertyInfo(typeof(string), "Property3");

            var config = new Convention().Properties<decimal>();
            Assert.NotNull(config);
            Assert.Equal(1, config.Predicates.Count());

            var predicate = config.Predicates.Single();
            Assert.True(predicate(decimalProperty));
            Assert.True(predicate(nullableDecimalProperty));
            Assert.False(predicate(nonDecimalProperty));
        }
        public void Configure_should_configure_properties()
        {
            var entityType = new EdmEntityType { Name = "E" };
            var property = entityType.AddPrimitiveProperty("P");
            property.PropertyType.EdmType = EdmPrimitiveType.Int32;
            var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object));
            var mockPropertyConfiguration = new Mock<PrimitivePropertyConfiguration>();
            var mockPropertyInfo = new MockPropertyInfo();
            property.SetClrPropertyInfo(mockPropertyInfo);
            entityTypeConfiguration.Property(new PropertyPath(mockPropertyInfo), () => mockPropertyConfiguration.Object);

            entityTypeConfiguration.Configure(entityType, new EdmModel());

            mockPropertyConfiguration.Verify(p => p.Configure(property));
        }
        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 EdmEntityType();
            var property = entityType.AddPrimitiveProperty("P");
            property.PropertyType.EdmType = EdmPrimitiveType.Int32;
            property.SetClrPropertyInfo(mockPropertyInfo);
            var associationType = new EdmAssociationType().Initialize();
            associationType.SourceEnd.EntityType = entityType;
            
            constraintConfiguration.Configure(
                associationType, associationType.SourceEnd, new EntityTypeConfiguration(typeof(object)));

            Assert.Equal(1, associationType.Constraint.DependentProperties.Count);
        }
        public void Apply_invokes_action_when_all_predicates_true()
        {
            var actionInvoked = false;
            var convention = new PropertyConvention(
                new Func<PropertyInfo, bool>[]
                    {
                        p => true,
                        p => true
                    },
                c => actionInvoked = true);
            var propertyInfo = new MockPropertyInfo();
            var configuration = new PrimitivePropertyConfiguration();

            convention.Apply(propertyInfo, () => configuration, new ModelConfiguration());

            Assert.True(actionInvoked);
        }
        public void Configure_should_configure_properties()
        {
            var complexType = new ComplexType("C");

            var property1 = EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            complexType.AddMember(property1);
            var property = property1;
            var complexTypeConfiguration = new ComplexTypeConfiguration(typeof(object));
            var mockPropertyConfiguration = new Mock<PrimitivePropertyConfiguration>();
            var mockPropertyInfo = new MockPropertyInfo();
            complexTypeConfiguration.Property(new PropertyPath(mockPropertyInfo), () => mockPropertyConfiguration.Object);
            property.SetClrPropertyInfo(mockPropertyInfo);

            complexTypeConfiguration.Configure(complexType);

            mockPropertyConfiguration.Verify(p => p.Configure(property));
        }
        public void AttributeMapper_should_map_annotation_attribute_for_properties()
        {
            var mockPropertyInfo = new MockPropertyInfo(typeof(string), "P");
            var mockAttributeProvider = new Mock<AttributeProvider>();
            mockAttributeProvider
                .Setup(a => a.GetAttributes(mockPropertyInfo.Object))
                .Returns(new Attribute[]
                    {
                        new DataContractAttribute(),
                        new TableAttribute("MyTable")
                    });

            var annotations = new List<DataModelAnnotation>();

            new AttributeMapper(mockAttributeProvider.Object).Map(mockPropertyInfo, annotations);

            Assert.Equal(1, annotations.Count);
            Assert.Equal(2, annotations.GetClrAttributes().Count);
        }
        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("E", "N", DataSpace.CSpace);
            var property1 = EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            entityType.AddMember(property1);
            var property = property1;
            property.SetClrPropertyInfo(mockPropertyInfo);
            var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace);
            associationType.SourceEnd = new AssociationEndMember("S", entityType);
            associationType.TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace));

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

            Assert.Equal(1, associationType.Constraint.ToProperties.Count);
        }
        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 EdmEntityType();
            var property = entityType.AddPrimitiveProperty("P");
            property.PropertyType.EdmType = EdmPrimitiveType.Int32;
            property.PropertyType.IsNullable = true;
            property.SetClrPropertyInfo(mockPropertyInfo);
            var associationType = new EdmAssociationType().Initialize();
            associationType.SourceEnd.EntityType = entityType;
            associationType.TargetEnd.EndKind = EdmAssociationEndKind.Required;

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

            Assert.Equal(1, associationType.Constraint.DependentProperties.Count);
            Assert.Equal(false, property.PropertyType.IsNullable);
        }