コード例 #1
0
        public void Cloning_the_model_configuration_clones_type_configurations_and_ignored_types()
        {
            var configuration = new ModelConfiguration();

            var entityType1  = new MockType("E1");
            var complexType1 = new MockType("C1");
            var ignoredType1 = new MockType("I1");

            configuration.Add(new EntityTypeConfiguration(entityType1));
            configuration.Add(new ComplexTypeConfiguration(complexType1));
            configuration.Ignore(ignoredType1);
            configuration.DefaultSchema  = "Foo";
            configuration.ModelNamespace = "Bar";

            var clone = configuration.Clone();

            Assert.True(clone.Entities.Contains(entityType1));
            Assert.True(clone.ComplexTypes.Contains(complexType1));
            Assert.True(clone.IsIgnoredType(ignoredType1));
            Assert.Equal("Foo", clone.DefaultSchema);
            Assert.Equal("Bar", clone.ModelNamespace);

            var entityType2  = new MockType("E2");
            var complexType2 = new MockType("C2");
            var ignoredType2 = new MockType("I2");

            configuration.Add(new EntityTypeConfiguration(entityType2));
            configuration.Add(new ComplexTypeConfiguration(complexType2));
            configuration.Ignore(ignoredType2);

            Assert.False(clone.Entities.Contains(entityType2));
            Assert.False(clone.ComplexTypes.Contains(complexType2));
            Assert.False(clone.IsIgnoredType(ignoredType2));
        }
コード例 #2
0
        public void Cloning_the_model_configuration_clones_type_configurations_and_ignored_types()
        {
            var configuration = new ModelConfiguration();

            var entityType1  = new MockType("E1");
            var complexType1 = new MockType("C1");
            var ignoredType1 = new MockType("I1");

            configuration.Add(new EntityTypeConfiguration(entityType1));
            configuration.Add(new ComplexTypeConfiguration(complexType1));
            configuration.Ignore(ignoredType1);

            var clone = configuration.Clone();

            Assert.True(clone.Entities.Contains(entityType1));
            Assert.True(clone.ComplexTypes.Contains(complexType1));
            Assert.True(clone.IsIgnoredType(ignoredType1));

            var entityType2  = new MockType("E2");
            var complexType2 = new MockType("C2");
            var ignoredType2 = new MockType("I2");

            configuration.Add(new EntityTypeConfiguration(entityType2));
            configuration.Add(new ComplexTypeConfiguration(complexType2));
            configuration.Ignore(ignoredType2);

            Assert.False(clone.Entities.Contains(entityType2));
            Assert.False(clone.ComplexTypes.Contains(complexType2));
            Assert.False(clone.IsIgnoredType(ignoredType2));
        }
コード例 #3
0
        public void Configure_should_configure_active_entities_and_complex_types()
        {
            var mockEntityType = new MockType();
            var mockComplexType = new MockType();

            var model = new EdmModel().Initialize();
            var entityType = model.AddEntityType("E");
            entityType.SetClrType(mockEntityType);
            var complexType = model.AddComplexType("C");
            complexType.SetClrType(mockComplexType);

            var modelConfiguration = new ModelConfiguration();
            var mockComplexTypeConfiguration = new Mock<ComplexTypeConfiguration>(mockComplexType.Object);
            var mockEntityTypeConfiguration = new Mock<EntityTypeConfiguration>(mockEntityType.Object);

            modelConfiguration.Add(mockComplexTypeConfiguration.Object);
            modelConfiguration.Add(mockEntityTypeConfiguration.Object);

            modelConfiguration.Configure(model);

            mockComplexTypeConfiguration.Verify(c => c.Configure(complexType));
            mockEntityTypeConfiguration.Verify(c => c.Configure(entityType, model));
        }
コード例 #4
0
        public void IsComplexType_should_return_true_when_type_is_complex()
        {
            var modelConfiguration = new ModelConfiguration();
            modelConfiguration.Add(new Mock<ComplexTypeConfiguration>(typeof(object)).Object);

            Assert.True(modelConfiguration.IsComplexType(typeof(object)));
        }
コード例 #5
0
        public void GetStructuralTypeConfiguration_should_return_registered_complex_type_configuration()
        {
            var modelConfiguration = new ModelConfiguration();
            var complexTypeConfiguration = new Mock<ComplexTypeConfiguration>(typeof(object)).Object;
            modelConfiguration.Add(complexTypeConfiguration);

            Assert.Same(complexTypeConfiguration, modelConfiguration.GetStructuralTypeConfiguration(typeof(object)));
        }
コード例 #6
0
        public void GetStructuralTypeConfiguration_should_return_registered_entity_configuration()
        {
            var modelConfiguration = new ModelConfiguration();
            var entityTypeConfiguration = new Mock<EntityTypeConfiguration>(typeof(object)).Object;
            modelConfiguration.Add(entityTypeConfiguration);

            Assert.Same(entityTypeConfiguration, modelConfiguration.GetStructuralTypeConfiguration(typeof(object)));
        }
コード例 #7
0
        public void ComplexType_should_throw_when_configuration_is_not_for_complex_type()
        {
            var modelConfiguration = new ModelConfiguration();
            modelConfiguration.Add(new Mock<EntityTypeConfiguration>(typeof(object)).Object);

            Assert.Equal(
                Strings.ComplexTypeConfigurationMismatch(typeof(object)),
                Assert.Throws<InvalidOperationException>(() => modelConfiguration.ComplexType(typeof(object))).Message);
        }
コード例 #8
0
        public void Can_add_and_get_complex_type_configuration()
        {
            var modelConfiguration = new ModelConfiguration();
            var complexTypeConfiguration = new Mock<ComplexTypeConfiguration>(typeof(object)).Object;
            modelConfiguration.Add(complexTypeConfiguration);

            Assert.Same(complexTypeConfiguration, modelConfiguration.ComplexType(typeof(object)));
        }
コード例 #9
0
        public void Can_add_and_get_entity_configuration()
        {
            var modelConfiguration = new ModelConfiguration();
            var entityTypeConfiguration = new Mock<EntityTypeConfiguration>(typeof(object)).Object;
            modelConfiguration.Add(entityTypeConfiguration);

            Assert.Same(entityTypeConfiguration, modelConfiguration.Entity(typeof(object)));
        }
コード例 #10
0
        public void Adding_complex_type_and_entity_configurations_should_throw()
        {
            var modelConfiguration = new ModelConfiguration();
            var complexTypeConfiguration = new Mock<ComplexTypeConfiguration>(typeof(object)).Object;
            var entityTypeConfiguration = new Mock<EntityTypeConfiguration>(typeof(object)).Object;
            modelConfiguration.Add(complexTypeConfiguration);

            Assert.Equal(
                Strings.DuplicateStructuralTypeConfiguration(typeof(object)),
                Assert.Throws<InvalidOperationException>(() => modelConfiguration.Add(entityTypeConfiguration)).Message);
        }