File: PropertyMapperTests.cs

package info (click to toggle)
mono 3.2.8%2Bdfsg-10
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 527,964 kB
  • ctags: 623,327
  • sloc: cs: 3,938,236; xml: 1,891,753; ansic: 418,737; java: 59,920; sh: 15,754; makefile: 11,067; sql: 7,956; perl: 2,279; cpp: 1,380; yacc: 1,203; python: 594; asm: 422; sed: 16; php: 1
file content (114 lines) | stat: -rw-r--r-- 5,320 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.

namespace System.Data.Entity.ModelConfiguration.Edm.UnitTests
{
    using System.Data.Entity.Core.Metadata.Edm;
    using System.Data.Entity.ModelConfiguration.Configuration;
    using System.Data.Entity.ModelConfiguration.Configuration.Types;
    using System.Data.Entity.ModelConfiguration.Mappers;
    using System.Linq;
    using Moq;
    using Xunit;

    public sealed class PropertyMapperTests
    {
        [Fact]
        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);
        }

        [Fact]
        public void Map_should_map_entity_navigation_properties()
        {
            var model = new EdmModel(DataSpace.CSpace);
            var entityType = new EntityType();
            model.AddEntitySet("Source", entityType);
            var mappingContext
                = new MappingContext(new ModelConfiguration(), new ConventionsConfiguration(), model);

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

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

        [Fact]
        public void Map_should_map_complex_properties()
        {
            var mockComplexType = new MockType();
            var mockModelConfiguration = new Mock<ModelConfiguration>();
            mockModelConfiguration
                .Setup(m => m.IsComplexType(mockComplexType)).Returns(true);
            mockModelConfiguration
                .Setup(m => m.GetStructuralTypeConfiguration(mockComplexType))
                .Returns(new Mock<StructuralTypeConfiguration>().Object);
            var entityType = new EntityType();
            var mappingContext
                = new MappingContext(mockModelConfiguration.Object, new ConventionsConfiguration(), new EdmModel(DataSpace.CSpace));

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

            Assert.Equal(0, entityType.DeclaredNavigationProperties.Count);
            Assert.Equal(1, entityType.DeclaredProperties.Count);
            Assert.NotNull(entityType.DeclaredProperties.Single().ComplexType);
        }

        [Fact]
        public void Map_should_set_correct_name_and_type()
        {
            var entityType = new EntityType();
            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);
        }

        [Fact]
        public void Map_should_set_correct_nullability()
        {
            var entityType = new EntityType();
            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)));

            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);
        }
    }
}