public void WhenRegisteredAsDeepSubclassThenIsRegistered()
        {
            var inspector = new ExplicitlyDeclaredModel();

            inspector.AddAsRootEntity(typeof(MyClass));
            inspector.AddAsTablePerClassHierarchyEntity(typeof(Inherited2));

            Assert.That(inspector.IsTablePerClass(typeof(Inherited2)), Is.False);
            Assert.That(inspector.IsTablePerClassHierarchy(typeof(Inherited2)), Is.True);
            Assert.That(inspector.IsTablePerConcreteClass(typeof(Inherited2)), Is.False);
        }
Beispiel #2
0
        public void WhenRegisteredDeepSubclassThenTheStrategyIsDefinedEvenForRoot()
        {
            var inspector = new ExplicitlyDeclaredModel();

            inspector.AddAsRootEntity(typeof(MyClass));
            inspector.AddAsTablePerClassHierarchyEntity(typeof(Inherited2));

            inspector.IsTablePerClass(typeof(MyClass)).Should().Be.False();
            inspector.IsTablePerClassHierarchy(typeof(MyClass)).Should().Be.True();
            inspector.IsTablePerConcreteClass(typeof(MyClass)).Should().Be.False();
        }
Beispiel #3
0
        public void WhenRegisteredAsRootThenCantRegisterAsUnionSubclass()
        {
            var inspector = new ExplicitlyDeclaredModel();

            inspector.AddAsRootEntity(typeof(MyClass));
            Executing.This(() =>
            {
                inspector.AddAsTablePerConcreteClassEntity(typeof(MyClass));
                inspector.IsTablePerClass(typeof(MyClass));
            }).Should().Throw <MappingException>();
        }
Beispiel #4
0
        public void WhenRegisteredAsDeppJoinedSubclassThenIsRegistered()
        {
            var inspector = new ExplicitlyDeclaredModel();

            inspector.AddAsRootEntity(typeof(MyClass));
            inspector.AddAsTablePerClassEntity(typeof(Inherited2));

            inspector.IsTablePerClass(typeof(Inherited2)).Should().Be.True();
            inspector.IsTablePerClassHierarchy(typeof(Inherited2)).Should().Be.False();
            inspector.IsTablePerConcreteClass(typeof(Inherited2)).Should().Be.False();
        }
        public void WhenPropertyUsedAsComposedIdThenRegister()
        {
            var inspector = new ExplicitlyDeclaredModel();
            var mapper    = new ModelMapper(inspector);

            mapper.Class <MyClass>(map => map.ComponentAsId(x => x.Id));

            Assert.That(inspector.IsPersistentId(For <MyClass> .Property(x => x.Id)), Is.True);
            Assert.That(inspector.IsPersistentProperty(For <MyClass> .Property(x => x.Id)), Is.True);
            Assert.That(inspector.IsComponent(typeof(IMyCompo)), Is.True);
        }
Beispiel #6
0
        public void WhenRegisteredAsComponetThenCantRegisterAsUnionSubclass()
        {
            var inspector = new ExplicitlyDeclaredModel();

            inspector.AddAsComponent(typeof(MyComponent));

            Assert.That(() =>
            {
                inspector.AddAsTablePerConcreteClassEntity(typeof(MyComponent));
                inspector.IsTablePerConcreteClass(typeof(MyComponent));
            }, Throws.TypeOf <MappingException>());
        }
Beispiel #7
0
        public void WhenMultipleRootRegisteredThenThrowsMappingException()
        {
            var inspector = new ExplicitlyDeclaredModel();

            inspector.AddAsRootEntity(typeof(MyClass));
            inspector.AddAsRootEntity(typeof(Inherited1));
            Assert.That(() =>
            {
                inspector.AddAsTablePerClassEntity(typeof(Inherited2));
                inspector.IsTablePerClass(typeof(Inherited2));
            }, Throws.TypeOf <MappingException>());
        }
        public void WhenRegisteredAsComponetThenCantRegisterAsSubclass()
        {
            var inspector = new ExplicitlyDeclaredModel();

            inspector.AddAsComponent(typeof(MyComponent));

            Executing.This(() =>
            {
                inspector.AddAsTablePerClassHierarchyEntity(typeof(MyComponent));
                inspector.IsTablePerClassHierarchy(typeof(MyComponent));
            }).Should().Throw <MappingException>();
        }
Beispiel #9
0
        public void WhenMultipleRootRegisteredThenThrowsMappingException()
        {
            var inspector = new ExplicitlyDeclaredModel();

            inspector.AddAsRootEntity(typeof(MyClass));
            inspector.AddAsRootEntity(typeof(Inherited1));
            Executing.This(() =>
            {
                inspector.AddAsTablePerClassEntity(typeof(Inherited2));
                inspector.IsTablePerClass(typeof(Inherited2));
            }).Should().Throw <MappingException>();
        }
        public void WhenRegisteredAsSubclassThenCantRegisterAsJoinedSubclass()
        {
            var inspector = new ExplicitlyDeclaredModel();

            inspector.AddAsRootEntity(typeof(MyClass));
            inspector.AddAsTablePerClassHierarchyEntity(typeof(Inherited1));

            Executing.This(() =>
            {
                inspector.AddAsTablePerClassEntity(typeof(Inherited1));
                inspector.IsTablePerClass(typeof(Inherited1));
            }).Should().Throw <MappingException>();
        }
        public void WhenRegisteredAsUnionSubclassThenCantRegisterAsJoinedSubclass()
        {
            var inspector = new ExplicitlyDeclaredModel();

            inspector.AddAsRootEntity(typeof(MyClass));
            inspector.AddAsTablePerConcreteClassEntity(typeof(Inherited1));

            Assert.That(() =>
            {
                inspector.AddAsTablePerClassEntity(typeof(Inherited1));
                inspector.IsTablePerConcreteClass(typeof(Inherited1));
            }, Throws.TypeOf <MappingException>());
        }
Beispiel #12
0
        public void WhenPropertyUsedAsVersionThenRegister()
        {
            var inspector = new ExplicitlyDeclaredModel();
            var mapper    = new ModelMapper(inspector);

            mapper.Class <MyClass>(
                map =>
            {
                map.Id(x => x.Id, idmap => { });
                map.Version(x => x.Version, vm => { });
            });

            Assert.That(inspector.IsVersion(For <MyClass> .Property(x => x.Version)), Is.True);
        }
Beispiel #13
0
        public void WhenPropertyVersionFromBaseEntityThenFindItAsVersion()
        {
            var inspector = new ExplicitlyDeclaredModel();
            var mapper    = new ModelMapper(inspector);

            mapper.Class <MyClass>(
                map =>
            {
                map.Id(x => x.Id, idmap => { });
                map.Version(x => x.Version, vm => { });
            });

            Assert.That(inspector.IsVersion(For <MyRoot> .Property(x => x.Version)), Is.True);
        }
        public void WhenRegisterPropertySplitMoreThanOnceThenIgnore()
        {
            var inspector = new ExplicitlyDeclaredModel();
            var memberFromDeclaringType = For <MyClass> .Property(x => x.Something);

            var memberFromReferencedType = typeof(Inherited).GetProperty("Something");

            inspector.AddAsPropertySplit(new SplitDefinition(typeof(MyClass), "group", memberFromDeclaringType));
            inspector.AddAsPropertySplit(new SplitDefinition(typeof(Inherited), "group1", memberFromReferencedType));

            inspector.GetSplitGroupsFor(typeof(MyClass)).Should().Have.SameValuesAs("group");
            inspector.GetSplitGroupsFor(typeof(Inherited)).Should().Be.Empty();

            inspector.GetSplitGroupFor(memberFromDeclaringType).Should().Be("group");
            inspector.GetSplitGroupFor(memberFromReferencedType).Should().Be("group");
        }
        public void WhenRegisterPropertySplitMoreThanOnceThenIgnore()
        {
            var inspector = new ExplicitlyDeclaredModel();
            var memberFromDeclaringType = For <MyClass> .Property(x => x.Something);

            var memberFromReferencedType = typeof(Inherited).GetProperty("Something");

            inspector.AddAsPropertySplit(new SplitDefinition(typeof(MyClass), "group", memberFromDeclaringType));
            inspector.AddAsPropertySplit(new SplitDefinition(typeof(Inherited), "group1", memberFromReferencedType));

            Assert.That(inspector.GetSplitGroupsFor(typeof(MyClass)), Is.EquivalentTo(new [] { "group" }));
            Assert.That(inspector.GetSplitGroupsFor(typeof(Inherited)), Is.Empty);

            Assert.That(inspector.GetSplitGroupFor(memberFromDeclaringType), Is.EqualTo("group"));
            Assert.That(inspector.GetSplitGroupFor(memberFromReferencedType), Is.EqualTo("group"));
        }
        public void WhenSuperclassPropertyUsedAsComposedIdThenRegister()
        {
            var inspector = new ExplicitlyDeclaredModel();
            var mapper    = new ModelMapper(inspector);

            mapper.Class <MyOtherSubclass>(map =>
                                           map.ComposedId(cm =>
            {
                cm.Property(x => x.Id);
                cm.Property(x => x.SubId);
            })
                                           );
            var hbmMapping     = mapper.CompileMappingFor(new[] { typeof(MyOtherSubclass) });
            var hbmClass       = hbmMapping.RootClasses[0];
            var hbmCompositeId = hbmClass.CompositeId;

            hbmCompositeId.Items.Should().Have.Count.EqualTo(2);
        }
        public void WhenPropertyUsedAsComposedIdThenRegister()
        {
            var inspector = new ExplicitlyDeclaredModel();
            var mapper    = new ModelMapper(inspector);

            mapper.Class <MyClass>(map =>
                                   map.ComposedId(cm =>
            {
                cm.Property(x => x.Code);
                cm.ManyToOne(x => x.Relation);
            })
                                   );

            inspector.IsMemberOfComposedId(For <MyClass> .Property(x => x.Code)).Should().Be.True();
            inspector.IsMemberOfComposedId(For <MyClass> .Property(x => x.Relation)).Should().Be.True();
            inspector.IsPersistentProperty(For <MyClass> .Property(x => x.Code)).Should().Be.True();
            inspector.IsPersistentProperty(For <MyClass> .Property(x => x.Relation)).Should().Be.True();
            inspector.IsPersistentId(For <MyClass> .Property(x => x.Code)).Should().Be.False();
            inspector.IsPersistentId(For <MyClass> .Property(x => x.Relation)).Should().Be.False();
        }
        public void WhenSplittedPropertiesThenRegisterSplitGroupIds()
        {
            var inspector = new ExplicitlyDeclaredModel();
            var mapper    = new ModelMapper(inspector);

            mapper.Subclass <Inherited>(map =>
            {
                map.Join("MyClassSplit1", mj =>
                {
                    mj.Property(x => x.SomethingA1);
                    mj.Property(x => x.SomethingA2);
                });
                map.Join("MyClassSplit2", mj =>
                {
                    mj.Property(x => x.SomethingB1);
                    mj.Property(x => x.SomethingB2);
                });
                map.Property(x => x.Something0);
            });

            IEnumerable <string> tablePerClassSplits = inspector.GetPropertiesSplits(typeof(Inherited));

            Assert.That(tablePerClassSplits, Is.EquivalentTo(new [] { "MyClassSplit1", "MyClassSplit2" }));
        }
        public void WhenSplittedPropertiesThenRegisterSplitGroupIds()
        {
            var inspector = new ExplicitlyDeclaredModel();
            var mapper    = new ModelMapper(inspector);

            mapper.Subclass <Inherited>(map =>
            {
                map.Join("MyClassSplit1", mj =>
                {
                    mj.Property(x => x.SomethingA1);
                    mj.Property(x => x.SomethingA2);
                });
                map.Join("MyClassSplit2", mj =>
                {
                    mj.Property(x => x.SomethingB1);
                    mj.Property(x => x.SomethingB2);
                });
                map.Property(x => x.Something0);
            });

            IEnumerable <string> tablePerClassSplits = inspector.GetPropertiesSplits(typeof(Inherited));

            tablePerClassSplits.Should().Have.SameValuesAs("MyClassSplit1", "MyClassSplit2");
        }