public void WhenCustomizedThenUseCustomizedPredicate() { var autoinspector = new SimpleModelInspector(); autoinspector.IsRootEntity((t, declared) => typeof(BaseEntity).Equals(t.BaseType)); var inspector = (IModelInspector)autoinspector; Assert.That(inspector.IsRootEntity(typeof(Person)), Is.False); Assert.That(inspector.IsRootEntity(typeof(Product)), Is.True); }
public void WhenMapPropertiesInTheBaseJumpedClassUsingMemberNameThenMapInInherited() { // ignoring MyClass and using Inherited, as root-class, I will try to map all properties using the base class. // NH have to recognize the case and map those properties in the inherited. var inspector = new SimpleModelInspector(); inspector.IsEntity((type, declared) => type == typeof(Inherited)); inspector.IsRootEntity((type, declared) => type == typeof(Inherited)); var mapper = new ModelMapper(inspector); mapper.Class<MyClass>(mc => { mc.Id(x => x.Id); mc.Property("Simple", map => map.Access(Accessor.Field)); mc.Property("ComplexType", map => map.Access(Accessor.Field)); mc.Bag<string>("Bag", y => y.Access(Accessor.Field)); mc.IdBag<MyCompo>("IdBag", y => y.Access(Accessor.Field)); mc.List<string>("List", y => y.Access(Accessor.Field)); mc.Set<string>("Set", y => y.Access(Accessor.Field)); mc.Map<int, string>("Map", y => y.Access(Accessor.Field)); mc.OneToOne<Related>("OneToOne", y => y.Access(Accessor.Field)); mc.ManyToOne<Related>("ManyToOne", y => y.Access(Accessor.Field)); mc.Any<object>("Any", typeof (int), y => y.Access(Accessor.Field)); mc.Component("DynamicCompo", new {A = 2}, y => y.Access(Accessor.Field)); mc.Component<MyCompo>("Compo", y => { y.Access(Accessor.Field); y.Property(c => c.Something); }); }); mapper.Class<Inherited>(mc => { }); HbmMapping mappings = mapper.CompileMappingForAllExplicitlyAddedEntities(); HbmClass hbmClass = mappings.RootClasses[0]; Assert.That(mappings.JoinedSubclasses, Is.Empty); Assert.That(hbmClass.Properties.Select(p => p.Name), Is.EquivalentTo(new [] {"Simple", "ComplexType", "Bag", "IdBag", "List", "Set", "Map", "Compo", "OneToOne", "ManyToOne", "Any", "DynamicCompo"})); Assert.That(hbmClass.Properties.Select(p => p.Access).All(a => a.StartsWith("field.")), Is.True); }
public void WhenMapPropertiesInTheBaseJumpedClassThenMapInInherited() { // ignoring MyClass and using Inherited, as root-class, I will try to map all properties using the base class. // NH have to recognize the case and map those properties in the inherited. var inspector = new SimpleModelInspector(); inspector.IsEntity((type, declared) => type == typeof(Inherited)); inspector.IsRootEntity((type, declared) => type == typeof(Inherited)); var mapper = new ModelMapper(inspector); mapper.Class<MyClass>(mc => { mc.Id(x => x.Id); mc.Property(x => x.Simple, map => map.Access(Accessor.Field)); mc.Property(x => x.ComplexType, map => map.Access(Accessor.Field)); mc.Bag(x => x.Bag, y => y.Access(Accessor.Field)); mc.IdBag(x => x.IdBag, y => y.Access(Accessor.Field)); mc.List(x => x.List, y => y.Access(Accessor.Field)); mc.Set(x => x.Set, y => y.Access(Accessor.Field)); mc.Map(x => x.Map, y => y.Access(Accessor.Field)); mc.OneToOne(x => x.OneToOne, y => y.Access(Accessor.Field)); mc.ManyToOne(x => x.ManyToOne, y => y.Access(Accessor.Field)); mc.Any(x => x.Any, typeof(int), y => y.Access(Accessor.Field)); mc.Component(x => x.DynamicCompo, new { A = 2 }, y => y.Access(Accessor.Field)); mc.Component(x => x.Compo, y => { y.Access(Accessor.Field); y.Property(c => c.Something); }); }); mapper.Class<Inherited>(mc =>{}); var mappings = mapper.CompileMappingForAllExplicitlyAddedEntities(); var hbmClass = mappings.RootClasses[0]; mappings.JoinedSubclasses.Should().Be.Empty(); hbmClass.Properties.Select(p => p.Name).Should().Have.SameValuesAs("Simple", "ComplexType", "Bag", "IdBag", "List", "Set", "Map", "Compo", "OneToOne", "ManyToOne", "Any", "DynamicCompo"); hbmClass.Properties.Select(p => p.Access).All(x => x.Satisfy(access => access.Contains("field."))); }