public void Map_should_create_association_sets_for_associations()
        {
            var modelConfiguration = new ModelConfiguration();
            var model = new EdmModel().Initialize();
            var entityType = new EntityType
                                 {
                                     Name = "Source"
                                 };
            model.AddEntitySet("Source", entityType);

            var mappingContext = new MappingContext(modelConfiguration, new ConventionsConfiguration(), model);

            new NavigationPropertyMapper(new TypeMapper(mappingContext))
                .Map(
                    new MockPropertyInfo(new MockType("Target"), "Nav"), entityType,
                    () => new EntityTypeConfiguration(typeof(object)));

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

            var associationSet = model.Containers.Single().AssociationSets.Single();

            Assert.NotNull(associationSet);
            Assert.NotNull(associationSet.ElementType);
            Assert.Equal("Source_Nav", associationSet.Name);
        }
Пример #2
0
        public void Map_should_map_entity_navigation_properties()
        {
            var entityType = new EdmEntityType();
            var mappingContext
                = new MappingContext(new ModelConfiguration(), new ConventionsConfiguration(), new EdmModel().Initialize());

            new PropertyMapper(new TypeMapper(mappingContext))
                .Map(new MockPropertyInfo(new MockType(), "Foo"), entityType, () => new EntityTypeConfiguration(typeof(object)));

            Assert.Equal(1, entityType.DeclaredNavigationProperties.Count);
        }
        public void Map_should_map_entity_navigation_properties()
        {
            var model = new EdmModel(DataSpace.CSpace);
            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            model.AddEntitySet("Source", entityType);
            var mappingContext
                = new MappingContext(new ModelConfiguration(), new ConventionsConfiguration(), model);

            new PropertyMapper(new TypeMapper(mappingContext))
                .Map(new MockPropertyInfo(typeof(AType1), "Foo"), entityType, () => new EntityTypeConfiguration(typeof(object)));

            Assert.Equal(1, entityType.DeclaredNavigationProperties.Count);
        }
        public void Map_should_not_detect_arrays_as_collection_associations()
        {
            var modelConfiguration = new ModelConfiguration();
            var model = new EdmModel().Initialize();
            var entityType = new EdmEntityType();
            var mappingContext = new MappingContext(modelConfiguration, new ConventionsConfiguration(), model);

            new NavigationPropertyMapper(new TypeMapper(mappingContext))
                .Map(new MockPropertyInfo(typeof(NavigationPropertyMapperTests[]), "Nav"), entityType,
                    () => new EntityTypeConfiguration(typeof(object)));

            Assert.Equal(0, model.Namespaces.Single().AssociationTypes.Count);
        }
        public void Map_should_set_correct_name_and_type()
        {
            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            var mappingContext
                = new MappingContext(new ModelConfiguration(), new ConventionsConfiguration(), new EdmModel(DataSpace.CSpace));

            new PropertyMapper(new TypeMapper(mappingContext))
                .Map(new MockPropertyInfo(typeof(int), "Foo"), entityType, () => new EntityTypeConfiguration(typeof(object)));

            Assert.Equal(1, entityType.DeclaredProperties.Count);

            var property = entityType.GetDeclaredPrimitiveProperties().SingleOrDefault(p => p.Name == "Foo");

            Assert.Equal(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32), property.PrimitiveType);
        }
        public void Map_should_map_complex_type_properties()
        {
            var complexType = new ComplexType("C");
            var mappingContext
                = new MappingContext(new ModelConfiguration(), new ConventionsConfiguration(), new EdmModel(DataSpace.CSpace));

            new PropertyMapper(new TypeMapper(mappingContext))
                .Map(new MockPropertyInfo(typeof(int), "Foo"), complexType, () => new ComplexTypeConfiguration(typeof(object)));

            Assert.Equal(1, complexType.Properties.Count);

            var property = complexType.Properties.SingleOrDefault(p => p.Name == "Foo");

            Assert.Equal(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32), property.PrimitiveType);
        }
Пример #7
0
        public void Map_should_set_correct_name_and_type()
        {
            var entityType = new EdmEntityType();
            var mappingContext
                = new MappingContext(new ModelConfiguration(), new ConventionsConfiguration(), new EdmModel().Initialize());

            new PropertyMapper(new TypeMapper(mappingContext))
                .Map(new MockPropertyInfo(typeof(int), "Foo"), entityType, () => new EntityTypeConfiguration(typeof(object)));

            Assert.Equal(1, entityType.DeclaredProperties.Count);

            var property = entityType.GetDeclaredPrimitiveProperty("Foo");

            Assert.Equal(EdmPrimitiveType.Int32, property.PropertyType.PrimitiveType);
        }
        public void Map_should_detect_collection_associations_and_set_correct_end_kinds()
        {
            var modelConfiguration = new ModelConfiguration();
            var model = new EdmModel().Initialize();
            var entityType = new EdmEntityType();
            var mappingContext = new MappingContext(modelConfiguration, new ConventionsConfiguration(), model);

            new NavigationPropertyMapper(new TypeMapper(mappingContext))
                .Map(new MockPropertyInfo(typeof(List<NavigationPropertyMapperTests>), "Nav"), entityType,
                    () => new EntityTypeConfiguration(typeof(object)));

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

            var associationType = model.Namespaces.Single().AssociationTypes.Single();

            Assert.Equal(EdmAssociationEndKind.Optional, associationType.SourceEnd.EndKind);
            Assert.Equal(EdmAssociationEndKind.Many, associationType.TargetEnd.EndKind);
        }
        public void Map_should_map_complex_properties()
        {
            var mockModelConfiguration = new Mock<ModelConfiguration>();
            mockModelConfiguration
                .Setup(m => m.IsComplexType(typeof(AType1))).Returns(true);
            mockModelConfiguration
                .Setup(m => m.GetStructuralTypeConfiguration(typeof(AType1)))
                .Returns(new Mock<StructuralTypeConfiguration>().Object);
            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            var mappingContext
                = new MappingContext(mockModelConfiguration.Object, new ConventionsConfiguration(), new EdmModel(DataSpace.CSpace));

            new PropertyMapper(new TypeMapper(mappingContext))
                .Map(new MockPropertyInfo(typeof(AType1), "Foo"), entityType, () => new EntityTypeConfiguration(typeof(object)));

            Assert.Equal(0, entityType.DeclaredNavigationProperties.Count);
            Assert.Equal(1, entityType.DeclaredProperties.Count);
            Assert.NotNull(entityType.DeclaredProperties.Single().ComplexType);
        }
        public void Map_should_set_default_association_multiplicity_to_collection_to_optional()
        {
            var modelConfiguration = new ModelConfiguration();
            var model = new EdmModel(DataSpace.CSpace);
            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            model.AddEntitySet("Source", entityType);
            var mappingContext = new MappingContext(modelConfiguration, new ConventionsConfiguration(), model);

            new NavigationPropertyMapper(new TypeMapper(mappingContext))
                .Map(
                    new MockPropertyInfo(new MockType("Target"), "Nav"), entityType,
                    () => new EntityTypeConfiguration(typeof(object)));

            Assert.Equal(1, model.AssociationTypes.Count());

            var associationType = model.AssociationTypes.Single();

            Assert.Equal(RelationshipMultiplicity.Many, associationType.SourceEnd.RelationshipMultiplicity);
            Assert.Equal(RelationshipMultiplicity.ZeroOrOne, associationType.TargetEnd.RelationshipMultiplicity);
        }
        public void Map_should_set_namespace_when_provided_via_model_configuration()
        {
            var modelConfiguration 
                = new ModelConfiguration
                                         {
                                             ModelNamespace = "Foo"
                                         };
            var model = new EdmModel(DataSpace.CSpace);
            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            model.AddEntitySet("Source", entityType);
            var mappingContext = new MappingContext(modelConfiguration, new ConventionsConfiguration(), model);

            new NavigationPropertyMapper(new TypeMapper(mappingContext))
                .Map(
                    new MockPropertyInfo(new MockType("Target"), "Nav"), entityType,
                    () => new EntityTypeConfiguration(typeof(object)));

            Assert.Equal(1, model.AssociationTypes.Count());

            var associationType = model.AssociationTypes.Single();

            Assert.Equal("Foo", associationType.NamespaceName);
        }
        public void Map_should_set_clr_property_info_on_assocation_source_end()
        {
            var modelConfiguration = new ModelConfiguration();
            var model = new EdmModel(DataSpace.CSpace);
            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            model.AddEntitySet("Source", entityType);
            var mappingContext = new MappingContext(modelConfiguration, new ConventionsConfiguration(), model);

            var mockPropertyInfo = new MockPropertyInfo(new MockType("Target"), "Nav");

            new NavigationPropertyMapper(new TypeMapper(mappingContext))
                .Map(
                    mockPropertyInfo, entityType,
                    () => new EntityTypeConfiguration(typeof(object)));

            var associationType = model.AssociationTypes.Single();

            Assert.Same(mockPropertyInfo.Object, associationType.SourceEnd.GetClrPropertyInfo());
        }
        public void Map_should_create_navigation_property_for_association()
        {
            var modelConfiguration = new ModelConfiguration();
            var model = new EdmModel(DataSpace.CSpace);
            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            model.AddEntitySet("Source", entityType);
            var mappingContext = new MappingContext(modelConfiguration, new ConventionsConfiguration(), model);

            new NavigationPropertyMapper(new TypeMapper(mappingContext))
                .Map(
                    new MockPropertyInfo(new MockType("Target"), "Nav"), entityType,
                    () => new EntityTypeConfiguration(typeof(object)));

            Assert.Equal(1, entityType.DeclaredNavigationProperties.Count);

            var navigationProperty = entityType.NavigationProperties.Single();

            Assert.Equal("Nav", navigationProperty.Name);
            Assert.NotNull(navigationProperty.Association);
            Assert.NotSame(entityType, navigationProperty.ResultEnd.GetEntityType());
        }
Пример #14
0
        public void Map_should_set_correct_nullability()
        {
            var entityType = new EntityType();
            var mappingContext
                = new MappingContext(new ModelConfiguration(), new ConventionsConfiguration(), new EdmModel().Initialize());

            new PropertyMapper(new TypeMapper(mappingContext))
                .Map(
                    new MockPropertyInfo(typeof(int?), "Foo"),
                    entityType, () => new EntityTypeConfiguration(typeof(object)));

            var property = entityType.GetDeclaredPrimitiveProperties().SingleOrDefault(p => p.Name == "Foo");

            Assert.Equal(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32), property.PrimitiveType);
            Assert.Equal(true, property.Nullable);

            new PropertyMapper(new TypeMapper(mappingContext))
                .Map(
                    new MockPropertyInfo(typeof(int), "Bar"),
                    entityType, () => new EntityTypeConfiguration(typeof(object)));

            property = entityType.GetDeclaredPrimitiveProperties().SingleOrDefault(p => p.Name == "Bar");

            Assert.Equal(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32), property.PrimitiveType);
            Assert.Equal(false, property.Nullable);
        }