public void Add_complex_type_configuration_should_add_to_model_configuration()
        {
            var modelConfiguration = new ModelConfiguration();
            var complexTypeConfiguration = new ComplexTypeConfiguration<object>();

            new ConfigurationRegistrar(modelConfiguration).Add(complexTypeConfiguration);

            Assert.Same(complexTypeConfiguration.Configuration, modelConfiguration.ComplexType(typeof(object)));
        }
        public void Add_complex_type_configuration_should_add_to_model_configuration()
        {
            var modelConfiguration       = new ModelConfiguration();
            var complexTypeConfiguration = new ComplexTypeConfiguration <object>();

            new ConfigurationRegistrar(modelConfiguration).Add(complexTypeConfiguration);

            Assert.Same(complexTypeConfiguration.Configuration, modelConfiguration.ComplexType(typeof(object)));
        }
        /// <summary>
        /// Changes this entity type to a complex type.
        /// </summary>
        /// <returns>
        /// The same <see cref="ConventionTypeConfiguration" /> instance so that multiple calls can be chained.
        /// </returns>
        public ConventionTypeConfiguration IsComplexType()
        {
            ValidateConfiguration(ConfigurationAspect.IsComplexType);

            if (_entityTypeConfiguration == null &&
                _complexTypeConfiguration == null)
            {
                _modelConfiguration.ComplexType(_type);
            }

            return(this);
        }
        public void AddConfigurationTypesToModel_adds_complextypeconfigurations_into_model()
        {
            var complexTypeConfiguration = new ComplexTypeConfiguration(typeof(Random));

            var filter = new Mock<ConfigurationTypeFilter>();
            filter.Setup(f => f.IsEntityTypeConfiguration(It.IsAny<Type>())).Returns(false);
            filter.Setup(f => f.IsComplexTypeConfiguration(It.IsAny<Type>())).Returns(true);

            var activator = new Mock<ConfigurationTypeActivator>();
            activator.Setup(a => a.Activate<ComplexTypeConfiguration>(It.IsAny<Type>()))
                     .Returns(complexTypeConfiguration);

            var finder = new ConfigurationTypesFinder(activator.Object, filter.Object);

            var modelConfiguration = new ModelConfiguration();
            finder.AddConfigurationTypesToModel(new[] { typeof(Object) }, modelConfiguration);

            Assert.Same(complexTypeConfiguration, modelConfiguration.ComplexType(typeof(Random)));
        }
        public void AddConfigurationTypesToModel_adds_complextypeconfigurations_into_model()
        {
            var complexTypeConfiguration = new ComplexTypeConfiguration(typeof(Random));

            var filter = new Mock <ConfigurationTypeFilter>();

            filter.Setup(f => f.IsEntityTypeConfiguration(It.IsAny <Type>())).Returns(false);
            filter.Setup(f => f.IsComplexTypeConfiguration(It.IsAny <Type>())).Returns(true);

            var activator = new Mock <ConfigurationTypeActivator>();

            activator.Setup(a => a.Activate <ComplexTypeConfiguration>(It.IsAny <Type>()))
            .Returns(complexTypeConfiguration);

            var finder = new ConfigurationTypesFinder(activator.Object, filter.Object);

            var modelConfiguration = new ModelConfiguration();

            finder.AddConfigurationTypesToModel(new[] { typeof(Object) }, modelConfiguration);

            Assert.Same(complexTypeConfiguration, modelConfiguration.ComplexType(typeof(Random)));
        }
Esempio n. 6
0
 /// <summary>
 /// Registers a type as a complex type in the model and returns an object that can be used to
 /// configure the complex type. This method can be called multiple times for the same type to
 /// perform multiple lines of configuration.
 /// </summary>
 /// <typeparam name="TComplexType"> The type to be registered or configured. </typeparam>
 /// <returns> The configuration object for the specified complex type. </returns>
 public virtual ComplexTypeConfiguration <TComplexType> ComplexType <TComplexType>()
     where TComplexType : class
 {
     return(new ComplexTypeConfiguration <TComplexType>(_modelConfiguration.ComplexType(typeof(TComplexType))));
 }
        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).Name),
                Assert.Throws<InvalidOperationException>(() => modelConfiguration.ComplexType(typeof(object))).Message);
        }
        public void ComplexType_should_return_new_configuration_if_no_configuration_found()
        {
            var modelConfiguration = new ModelConfiguration();

            Assert.NotNull(modelConfiguration.ComplexType(typeof(object)));
        }
        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)));
        }
        public void ComplexTypes_returns_only_configured_non_ignored_complex_types()
        {
            var modelConfiguration = new ModelConfiguration();
            modelConfiguration.Entity(new MockType());
            var mockComplexType = new MockType();
            modelConfiguration.ComplexType(mockComplexType);
            var mockIgnoredComplexType = new MockType();
            modelConfiguration.ComplexType(mockIgnoredComplexType);
            modelConfiguration.Ignore(mockIgnoredComplexType);

            Assert.Same(mockComplexType.Object, modelConfiguration.ComplexTypes.Single());
        }
        public void ConfiguredTypes_returns_all_known_types()
        {
            var modelConfiguration = new ModelConfiguration();
            modelConfiguration.Entity(new MockType());
            modelConfiguration.ComplexType(new MockType());
            modelConfiguration.Ignore(new MockType());

            Assert.Equal(3, modelConfiguration.ConfiguredTypes.Count());
        }
        public void MapComplexType_should_set_namespace_when_provided_via_model_configuration()
        {
            var model = new EdmModel(DataSpace.CSpace);
            var mockType = new MockType("Foo");
            var modelConfiguration = new ModelConfiguration
                                         {
                                             ModelNamespace = "Bar"
                                         };
            modelConfiguration.ComplexType(mockType);
            var typeMapper = new TypeMapper(new MappingContext(modelConfiguration, new ConventionsConfiguration(), model));

            var complexType = typeMapper.MapComplexType(mockType);

            Assert.NotNull(complexType);
            Assert.Equal("Bar", complexType.NamespaceName);
        }
        public void MapComplexType_should_create_complex_type_with_clr_type_name_and_add_to_model()
        {
            var model = new EdmModel(DataSpace.CSpace);
            var mockType = new MockType("Foo");
            var modelConfiguration = new ModelConfiguration();
            modelConfiguration.ComplexType(mockType);
            var typeMapper = new TypeMapper(new MappingContext(modelConfiguration, new ConventionsConfiguration(), model));

            var complexType = typeMapper.MapComplexType(mockType);

            Assert.NotNull(complexType);
            Assert.Same(complexType, model.GetComplexType("Foo"));
        }
        public void MapEnumType_should_should_throw_for_new_type_if_complex_type_with_same_simple_name_already_used()
        {
            var model = new EdmModel(DataSpace.CSpace);

            var mockType1 = new MockType("Foo");
            var mockType2 = new MockType("Foo");

            var modelConfiguration = new ModelConfiguration();
            modelConfiguration.ComplexType(mockType1);

            mockType2.SetupGet(t => t.IsEnum).Returns(true);

            var typeMapper = new TypeMapper(new MappingContext(modelConfiguration, new ConventionsConfiguration(), model));

            Assert.NotNull(typeMapper.MapComplexType(mockType1));

            Assert.Equal(
                Strings.SimpleNameCollision("Foo", "Foo", "Foo"),
                Assert.Throws<NotSupportedException>(() => typeMapper.MapEnumType(mockType2)).Message);
        }
        public void MapComplexType_should_ignore_new_type_if_type_name_already_used()
        {
            var model = new EdmModel().Initialize();

            var mockType1 = new MockType("Foo");
            var mockType2 = new MockType("Foo");

            var modelConfiguration = new ModelConfiguration();
            modelConfiguration.ComplexType(mockType1);
            modelConfiguration.ComplexType(mockType2);

            var typeMapper = new TypeMapper(new MappingContext(modelConfiguration, new ConventionsConfiguration(), model));

            Assert.NotNull(typeMapper.MapComplexType(mockType1));
            Assert.Null(typeMapper.MapComplexType(mockType2));
        }
Esempio n. 16
0
        public void MapEnumType_should_should_throw_for_new_type_if_complex_type_with_same_simple_name_already_used()
        {
            var model = new EdmModel(DataSpace.CSpace);

            var modelConfiguration = new ModelConfiguration();
            modelConfiguration.ComplexType(typeof(Outer5.AType5));

            var typeMapper = new TypeMapper(new MappingContext(modelConfiguration, new ConventionsConfiguration(), model));

            Assert.NotNull(typeMapper.MapComplexType(typeof(Outer5.AType5)));

            Assert.Equal(
                Strings.SimpleNameCollision(typeof(AType5).FullName, typeof(Outer5.AType5).FullName, "AType5"),
                Assert.Throws<NotSupportedException>(() => typeMapper.MapEnumType(typeof(AType5))).Message);
        }