public void WhenExplicitRegisteredRecognizeRelation()
 {
     var mapper = new ObjectRelationalMapper();
     mapper.TablePerClass<AEntity>();
     mapper.TablePerClass<BEntity>();
     mapper.ManyToMany<AEntity, BEntity>();
     mapper.IsManyToMany(typeof(AEntity), typeof(BEntity)).Should().Be.True();
 }
        public void WhenExplicitRegisteredRecognizeInverseRelationAsImplicit()
        {
            var mapper = new ObjectRelationalMapper();

            mapper.TablePerClass <AEntity>();
            mapper.TablePerClass <BEntity>();
            mapper.ManyToMany <AEntity, BEntity>();
            mapper.IsMasterManyToMany(typeof(BEntity), typeof(AEntity)).Should().Be.False();
        }
예제 #3
0
        private void ConfOrmMapping(ObjectRelationalMapper orm, Mapper mapper)
        {
            orm.TablePerClassHierarchy <Product>();

            orm.ManyToMany <Customer, Product>();
            orm.Cascade <Movie, ActorRole>(Cascade.All);

            orm.NaturalId <Customer>(c => c.Name);
        }
        public void WhenFindInterfaceForRootClassInCollectionThenRecognizeRelation()
        {
            var orm = new ObjectRelationalMapper();
            orm.TablePerClass<Contact>();
            orm.TablePerClass<UserGroup>();
            orm.ManyToMany<UserGroup, ISecurity>();

            orm.IsManyToMany(typeof(ISecurity), typeof(UserGroup)).Should().Be.True();
        }
예제 #5
0
        public void GetBaseImplementorsShouldReturnOnlyTheFirstBaseClassOfTheHierarchy()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <Animal>();
            orm.ManyToMany <Human, Human>();
            orm.AddToDomain(new[] { typeof(Animal), typeof(Reptile), typeof(Lizard), typeof(Mammal), typeof(Human), typeof(DomesticAnimal), typeof(Cat), typeof(Dog) });
            orm.GetBaseImplementors(typeof(Animal)).Should().Have.SameValuesAs(new[] { typeof(Animal) });
        }
예제 #6
0
        public void WhenFindInterfaceForRootClassInCollectionThenRecognizeRelation()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <Contact>();
            orm.TablePerClass <UserGroup>();
            orm.ManyToMany <UserGroup, ISecurity>();

            orm.IsManyToMany(typeof(ISecurity), typeof(UserGroup)).Should().Be.True();
        }
        public void IntegrationWithObjectRelationalMapper()
        {
            var orm = new ObjectRelationalMapper();
            orm.TablePerClass<Person>();
            orm.TablePerClass<Animal>();
            orm.ManyToMany<Person, Animal>();
            HbmMapping mapping = GetMapping(orm);

            VerifyMapping(mapping);
        }
        public void DomainDefinition(ObjectRelationalMapper orm)
        {
            orm.TablePerClass<Animal>();
            orm.TablePerClass<User>();
            orm.TablePerClass<StateProvince>();
            orm.TablePerClassHierarchy<Zoo>();

            orm.ManyToMany<Human, Human>();
            orm.OneToOne<User, Human>();
        }
        public void DomainDefinition(ObjectRelationalMapper orm)
        {
            orm.TablePerClass <Animal>();
            orm.TablePerClass <User>();
            orm.TablePerClass <StateProvince>();
            orm.TablePerClassHierarchy <Zoo>();

            orm.ManyToMany <Human, Human>();
            orm.OneToOne <User, Human>();
        }
예제 #10
0
        public void IntegrationWithObjectRelationalMapper()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <Person>();
            orm.TablePerClass <Animal>();
            orm.ManyToMany <Person, Animal>();
            HbmMapping mapping = GetMapping(orm);

            VerifyMapping(mapping);
        }
예제 #11
0
        public void WhenCircularRelationThenIsManyToOneAndNotHeterogeneous()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <Animal>();
            orm.ManyToMany <Human, Human>();
            orm.AddToDomain(new[] { typeof(Animal), typeof(Reptile), typeof(Lizard), typeof(Mammal), typeof(Human), typeof(DomesticAnimal), typeof(Cat), typeof(Dog) });
            orm.IsManyToOne(typeof(Animal), typeof(Animal)).Should().Be.True();
            orm.IsHeterogeneousAssociation(ForClass <Animal> .Property(x => x.Mother)).Should().Be.False();
            orm.IsHeterogeneousAssociation(ForClass <Animal> .Property(x => x.Father)).Should().Be.False();
        }
예제 #12
0
        public void WhenManyToManyShouldNotMatch()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <Contact>();
            orm.TablePerClass <Company>();
            orm.ManyToMany <Contact, Company>();

            var        pattern    = new PolymorphismBidirectionalOneToManyMemberPattern(orm);
            MemberInfo memberInfo = ForClass <Contact> .Property(x => x.Companies);

            pattern.Match(memberInfo).Should().Be.False();
        }
        public void WhenExplicitManyToManyThenShouldMapSimpleRelationAsManyToOneByDefault()
        {
            var orm = new ObjectRelationalMapper();
            orm.TablePerClass<User>();
            orm.TablePerClass<Group>();
            orm.ManyToMany<Group, User>();

            orm.IsManyToOne(typeof(Group), typeof(User)).Should().Be.True();
            orm.IsManyToMany(typeof(Group), typeof(User)).Should().Be.True();
            orm.IsOneToMany(typeof(Group), typeof(User)).Should().Be.False();
            orm.IsOneToOne(typeof(Group), typeof(User)).Should().Be.False();
            orm.IsManyToMany(typeof(User), typeof(Group)).Should().Be.True();
            orm.IsOneToMany(typeof(User), typeof(Group)).Should().Be.False();
        }
예제 #14
0
        public void WhenExplicitManyToManyThenShouldMapSimpleRelationAsManyToOneByDefault()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <User>();
            orm.TablePerClass <Group>();
            orm.ManyToMany <Group, User>();

            orm.IsManyToOne(typeof(Group), typeof(User)).Should().Be.True();
            orm.IsManyToMany(typeof(Group), typeof(User)).Should().Be.True();
            orm.IsOneToMany(typeof(Group), typeof(User)).Should().Be.False();
            orm.IsOneToOne(typeof(Group), typeof(User)).Should().Be.False();
            orm.IsManyToMany(typeof(User), typeof(Group)).Should().Be.True();
            orm.IsOneToMany(typeof(User), typeof(Group)).Should().Be.False();
        }
        public void WhenManyToManyIsNotManyToOne()
        {
            var mapper = new ObjectRelationalMapper();
            mapper.TablePerClass<AEntity>();
            mapper.TablePerClass<BEntity>();
            mapper.ManyToMany<AEntity, BEntity>();
            mapper.IsOneToMany(typeof(AEntity), typeof(BEntity)).Should().Be.False();
            mapper.IsOneToMany(typeof(BEntity), typeof(AEntity)).Should().Be.False();

            // Commented because CfgORM-5
            // many-to-many should work only inside a collection.
            // many-to-one should work only outside a collection.
            //mapper.IsManyToOne(typeof(AEntity), typeof(BEntity)).Should().Be.False();
            //mapper.IsManyToOne(typeof(BEntity), typeof(AEntity)).Should().Be.False();
        }
        public void WhenManyToManyIsNotManyToOne()
        {
            var mapper = new ObjectRelationalMapper();

            mapper.TablePerClass <AEntity>();
            mapper.TablePerClass <BEntity>();
            mapper.ManyToMany <AEntity, BEntity>();
            mapper.IsOneToMany(typeof(AEntity), typeof(BEntity)).Should().Be.False();
            mapper.IsOneToMany(typeof(BEntity), typeof(AEntity)).Should().Be.False();

            // Commented because CfgORM-5
            // many-to-many should work only inside a collection.
            // many-to-one should work only outside a collection.
            //mapper.IsManyToOne(typeof(AEntity), typeof(BEntity)).Should().Be.False();
            //mapper.IsManyToOne(typeof(BEntity), typeof(AEntity)).Should().Be.False();
        }
예제 #17
0
        public void WhenComplexInheritanceSho()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <Animal>();
            orm.ManyToMany <Human, Human>();
            orm.AddToDomain(new[] { typeof(Animal), typeof(Reptile), typeof(Lizard), typeof(Mammal), typeof(Human), typeof(DomesticAnimal), typeof(Cat), typeof(Dog) });
            var mapper  = new Mapper(orm);
            var mapping = mapper.CompileMappingFor(new[] { typeof(Animal) });

            HbmClass rc = mapping.RootClasses.First(r => r.Name.Contains("Animal"));

            rc.Properties.Where(p => p.Name == "Mother").Single().Should().Be.OfType <HbmManyToOne>()
            .And.ValueOf.Class.Should().Be.Null();
            rc.Properties.Where(p => p.Name == "Father").Single().Should().Be.OfType <HbmManyToOne>()
            .And.ValueOf.Class.Should().Be.Null();
        }