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)); }
public void MapComplexType_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(AType6)); modelConfiguration.ComplexType(typeof(Outer6.AType6)); var typeMapper = new TypeMapper(new MappingContext(modelConfiguration, new ConventionsConfiguration(), model)); Assert.NotNull(typeMapper.MapComplexType(typeof(AType6))); Assert.Equal( Strings.SimpleNameCollision(typeof(Outer6.AType6).FullName, typeof(AType6).FullName, "AType6"), Assert.Throws <NotSupportedException>(() => typeMapper.MapComplexType(typeof(Outer6.AType6))).Message); }
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))); }
public void Build_should_not_throw_when_complex_type_ignored_then_configured() { var modelConfiguration = new ModelConfiguration(); var mockType = typeof(AType1); modelConfiguration.Ignore(mockType); modelConfiguration.ComplexType(mockType); var modelBuilder = new DbModelBuilder(); var databaseMapping = modelBuilder.Build(ProviderRegistry.Sql2008_ProviderInfo).DatabaseMapping; Assert.Equal(0, databaseMapping.Model.ComplexTypes.Count()); }
public void MapComplexType_should_create_complex_type_with_clr_type_name_and_add_to_model() { var model = new EdmModel(DataSpace.CSpace); var modelConfiguration = new ModelConfiguration(); modelConfiguration.ComplexType(typeof(AType1)); var typeMapper = new TypeMapper(new MappingContext(modelConfiguration, new ConventionsConfiguration(), model)); var complexType = typeMapper.MapComplexType(typeof(AType1)); Assert.NotNull(complexType); Assert.Same(complexType, model.GetComplexType("AType1")); }
public void MapComplexType_should_create_complex_type_with_clr_type_name_and_add_to_model() { var model = new EdmModel().Initialize(); 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 Build_should_map_types() { var modelConfiguration = new ModelConfiguration(); modelConfiguration.Entity(typeof(AType2)).Key(typeof(AType2).GetInstanceProperty("Id")); modelConfiguration.ComplexType(typeof(CType2)); var modelBuilder = new DbModelBuilder(modelConfiguration); var databaseMapping = modelBuilder.Build(ProviderRegistry.Sql2008_ProviderInfo).DatabaseMapping; Assert.NotNull(databaseMapping); Assert.Equal(1, databaseMapping.Model.EntityTypes.Count()); Assert.Equal(1, databaseMapping.Model.ComplexTypes.Count()); }
public void Build_should_map_types() { var modelConfiguration = new ModelConfiguration(); var mockType = new MockType("T").Property <int>("Id"); modelConfiguration.Entity(mockType).Key(mockType.GetProperty("Id")); modelConfiguration.ComplexType(new MockType("C")); var modelBuilder = new DbModelBuilder(modelConfiguration); var databaseMapping = modelBuilder.Build(ProviderRegistry.Sql2008_ProviderInfo).DatabaseMapping; Assert.NotNull(databaseMapping); Assert.Equal(1, databaseMapping.Model.GetEntityTypes().Count()); Assert.Equal(1, databaseMapping.Model.GetComplexTypes().Count()); }
public void MapComplexType_should_set_namespace_when_provided_via_model_configuration() { var model = new EdmModel(DataSpace.CSpace); var modelConfiguration = new ModelConfiguration { ModelNamespace = "Bar" }; modelConfiguration.ComplexType(typeof(AType7)); var typeMapper = new TypeMapper(new MappingContext(modelConfiguration, new ConventionsConfiguration(), model)); var complexType = typeMapper.MapComplexType(typeof(AType7)); Assert.NotNull(complexType); Assert.Equal("Bar", complexType.NamespaceName); }
public void MapComplexType_should_throw_for_new_type_if_entity_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(mockType2); var typeMapper = new TypeMapper(new MappingContext(modelConfiguration, new ConventionsConfiguration(), model)); Assert.NotNull(typeMapper.MapEntityType(mockType1)); Assert.Equal( Strings.SimpleNameCollision("Foo", "Foo", "Foo"), Assert.Throws <NotSupportedException>(() => typeMapper.MapComplexType(mockType2)).Message); }
public void MapComplexType_should_throw_for_new_type_if_enum_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(mockType2); mockType1.SetupGet(t => t.IsEnum).Returns(true); mockType1.Setup(t => t.GetEnumUnderlyingType()).Returns(typeof(int)); mockType1.Setup(t => t.GetEnumNames()).Returns(new string[] { }); mockType1.Setup(t => t.GetEnumValues()).Returns(new int[] { }); var typeMapper = new TypeMapper(new MappingContext(modelConfiguration, new ConventionsConfiguration(), model)); Assert.NotNull(typeMapper.MapEnumType(mockType1)); Assert.Equal( Strings.SimpleNameCollision("Foo", "Foo", "Foo"), Assert.Throws <NotSupportedException>(() => typeMapper.MapComplexType(mockType2)).Message); }
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); }
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()); }