Beispiel #1
0
        public void InvokeCustomizerOfDictionaryKeyManyToManyRelation()
        {
            var propertyPath      = new PropertyPath(null, ForClass <MyClass> .Property(x => x.MyDictionary));
            var customizersHolder = new CustomizersHolder();
            var elementMapper     = new Mock <IMapKeyManyToManyMapper>();

            customizersHolder.AddCustomizer(propertyPath, (IMapKeyManyToManyMapper x) => x.Column("pizza"));
            customizersHolder.InvokeCustomizers(propertyPath, elementMapper.Object);

            elementMapper.Verify(x => x.Column(It.Is <string>(v => v == "pizza")), Times.Once());
        }
        public void CallMapManyToOneMapper()
        {
            var mapdoc    = new HbmMapping();
            var component = new HbmCompositeMapKey();
            var mapper    = new ComponentMapKeyMapper(typeof(ToySkill), component, mapdoc);
            var called    = false;

            mapper.ManyToOne(ForClass <ToySkill> .Property(ts => ts.Skill), x => called = true);

            called.Should().Be.True();
        }
        public void WhenMapDocHasDefaultHasClassName()
        {
            var entityType = typeof(Person);
            var mapdoc     = new HbmMapping {
                assembly = entityType.Assembly.FullName, @namespace = entityType.Namespace
            };
            var component = new HbmComponent();

            new ComponentMapper(component, typeof(Name), ForClass <Person> .Property(p => p.Name), mapdoc);
            component.Class.Should().Be.EqualTo(typeof(Name).Name);
        }
Beispiel #4
0
        public void WhenRelationDeclaredAsManyToManyForDictionaryValueThenMatch()
        {
            var orm = new Mock <IDomainInspector>();

            orm.Setup(x => x.IsManyToMany(It.Is <Type>(t => t == typeof(MyClass)), It.Is <Type>(t => t == typeof(MyBidirect)))).Returns(true);
            var path = new PropertyPath(null, ForClass <MyClass> .Property(x => x.MapValue));

            var pattern = new ManyToManyInCollectionTableApplier(orm.Object);

            pattern.Match(path).Should().Be.False();
        }
Beispiel #5
0
        public void WhenLevel1ThenMatch()
        {
            var level0  = new PropertyPath(null, ForClass <MyClassWithComponent> .Property(x => x.Component1));
            var level1  = new PropertyPath(level0, ForClass <MyComponent> .Property(x => x.MyNested));
            var level2  = new PropertyPath(level1, ForClass <MyClass> .Property(x => x.Fake1));
            var pattern = new ComponentPropertyColumnNameApplier();
            var mapper  = new Mock <IPropertyMapper>();

            pattern.Apply(level2, mapper.Object);
            mapper.Verify(x => x.Column(It.Is <string>(columnName => columnName == "Component1MyNestedFake1")));
        }
Beispiel #6
0
        public void WhenInterfaceOnParentThenMatch()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <Parent>();
            orm.TablePerClass <Child>();

            var pattern = new PolymorphismBidirectionalOneToManyMemberPattern(orm);

            pattern.Match(ForClass <Parent> .Property(x => x.Children)).Should().Be.True();
        }
        public void WhenExplicitlyDeclaredAsBagThenDoesNotUseSet()
        {
            var mapper = new ObjectRelationalMapper();

            mapper.Patterns.Sets.Add(new BagCollectionPattern());
            mapper.Bag <A>(a => a.Others);

            mapper.IsBag(ForClass <A> .Property(a => a.Others)).Should().Be.True();
            mapper.IsSet(ForClass <A> .Property(a => a.NickNames)).Should().Be.True();
            mapper.IsSet(ForClass <A> .Property(a => a.Set)).Should().Be.True();
        }
        public void WhenComponentsCollectionThenMatch()
        {
            var orm     = new Mock <IDomainInspector>();
            var pattern = new CollectionOfComponentsKeyColumnApplier(orm.Object);

            orm.Setup(x => x.IsComponent(typeof(MyComponent))).Returns(true);

            var path = new PropertyPath(null, ForClass <MyClass> .Property(p => p.Components));

            pattern.Match(path).Should().Be.True();
        }
Beispiel #9
0
        public void WhenManySideIsNotAnEntityThenNoMatch()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <MyRoot1>();
            orm.TablePerClass <MyRoot2>();

            var pattern = new PolymorphismBidirectionalAnyToManyPattern(orm);

            pattern.Match(ForClass <MyRelatedNoRoot1> .Property(x => x.Items)).Should().Be.False();
        }
Beispiel #10
0
        public void WhenTheDomainDoesNotContainMoreImplsThenNoMatch()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <MyEntity>();
            orm.TablePerClass <MyRoot1>();

            var pattern = new PolymorphismBidirectionalAnyToManyPattern(orm);

            pattern.Match(ForClass <MyRelatedNoRoot1> .Property(x => x.Items)).Should().Be.False();
        }
Beispiel #11
0
        public void CanSetProxy()
        {
            var mapdoc = new HbmMapping();
            var rc     = new ClassMapper(typeof(EntityProxable), mapdoc, ForClass <EntityProxable> .Property(x => x.Id));

            rc.Proxy(typeof(IEntityProxable));

            var hbmEntity = mapdoc.RootClasses[0];

            hbmEntity.Proxy.Should().Contain("IEntityProxable");
        }
        public void CanMapManyToOne()
        {
            var mapdoc    = new HbmMapping();
            var component = new HbmNestedCompositeElement();
            var mapper    = new ComponentNestedElementMapper(typeof(Number), mapdoc, component, ForClass <Address> .Property(a => a.Number));

            mapper.ManyToOne(ForClass <Number> .Property(a => a.Parent), x => { });
            component.Properties.Should().Have.Count.EqualTo(1);
            component.Properties.First().Name.Should().Be.EqualTo("Parent");
            component.Properties.First().Should().Be.OfType <HbmManyToOne>();
        }
Beispiel #13
0
        public void WhenDictionaryIsInPlainEntityThenApplyClassNamePropertyName()
        {
            var orm     = new Mock <IDomainInspector>();
            var pattern = new CollectionOfElementsTableApplier(orm.Object);

            var mapper = new Mock <ICollectionPropertiesMapper>();
            var path   = new PropertyPath(null, ForClass <MyClass> .Property(p => p.MapOfStrings));

            pattern.Match(path).Should().Be.True();
            pattern.Apply(path, mapper.Object);
            mapper.Verify(km => km.Table(It.Is <string>(s => s == "MyClassMapOfStrings")));
        }
        public void GetContainerEntityWhenPropertyIsInComponentThenReturnEntity()
        {
            var orm = new Mock <IDomainInspector>();

            orm.Setup(x => x.IsEntity(typeof(MainEntity))).Returns(true);
            orm.Setup(x => x.IsRootEntity(typeof(MainEntity))).Returns(true);
            orm.Setup(x => x.IsEntity(typeof(InheritedEntity))).Returns(true);
            var level0 = new PropertyPath(null, ForClass <InheritedEntity> .Property(p => p.Component));
            var path   = new PropertyPath(level0, ForClass <MyComponent> .Property(p => p.Something));

            path.GetContainerEntity(orm.Object).Should().Be(typeof(InheritedEntity));
        }
Beispiel #15
0
        public void WhenSetTypeByITypeTypeThenSetType()
        {
            var member = ForClass <MyClass> .Property(c => c.EnumProp);

            var mapping = new HbmKeyProperty();
            var mapper  = new KeyPropertyMapper(member, mapping);

            mapper.Type <EnumStringType <MyEnum> >();

            mapping.Type.name.Should().Contain(typeof(EnumStringType <MyEnum>).FullName);
            mapping.type.Should().Be.Null();
        }
Beispiel #16
0
        public void WhenNoPolymorphicThenNoMatch()
        {
            // using the concrete implementation of IDomainInspector this test is more like an integration-test but it is exactly what I need.
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <Parent>();
            orm.TablePerClass <Child>();

            var pattern = new PolymorphismBidirectionalOneToManyMemberPattern(orm);

            pattern.Match(ForClass <Parent> .Property(x => x.Children)).Should().Be.False();
        }
Beispiel #17
0
        public void WhenSetFormulaWithNullThenDoNothing()
        {
            var member = ForClass <MyClass> .Property(c => c.Autoproperty);

            var mapping = new HbmProperty();
            var mapper  = new PropertyMapper(member, mapping);

            mapper.Column("MyColumn");
            mapper.Formula(null);
            mapping.formula.Should().Be.Null();
            mapping.column.Should().Not.Be.Null();
        }
Beispiel #18
0
        public void WhenRelationDeclaredAsManyToManyBidirectionalThenMatch()
        {
            var orm = new Mock <IDomainInspector>();

            orm.Setup(x => x.IsManyToMany(It.Is <Type>(t => t == typeof(MyClass)), It.Is <Type>(t => t == typeof(MyBidirect)))).Returns(true);
            orm.Setup(x => x.IsManyToMany(It.Is <Type>(t => t == typeof(MyBidirect)), It.Is <Type>(t => t == typeof(MyClass)))).Returns(true);

            var pattern = new ManyToManyPattern(orm.Object);

            pattern.Match(ForClass <MyClass> .Property(x => x.MyBidirects)).Should().Be.True();
            pattern.Match(ForClass <MyBidirect> .Property(x => x.MyClasses)).Should().Be.True();
        }
Beispiel #19
0
        public void WhenInterfaceOnChildAndPropertyExclusionOnInterfaceThenNoMatch()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <Parent>();
            orm.TablePerClass <Child>();
            orm.ExcludeProperty <IChild>(c => c.Parent);

            var pattern = new PolymorphismBidirectionalOneToManyMemberPattern(orm);

            pattern.Match(ForClass <Parent> .Property(x => x.Children)).Should().Be.False();
        }
Beispiel #20
0
        public void WhenInComponentThenApplyPropertyPath()
        {
            var applier        = new ManyToOneColumnApplier();
            var level0         = new PropertyPath(null, ForClass <MyClass> .Property(x => x.Component));
            var path           = new PropertyPath(level0, ForClass <MyComponent> .Property(x => x.AnotherClass));
            var mayToOneMapper = new Mock <IManyToOneMapper>();

            applier.Match(path).Should().Be.True();
            applier.Apply(path, mayToOneMapper.Object);

            mayToOneMapper.Verify(x => x.Column(It.Is <string>(columnName => columnName == "ComponentAnotherClassId")));
        }
        public void SettingColumnOverridesFormula()
        {
            var hbmMapping = new HbmMapping();
            var member     = ForClass <MyClass> .Property(c => c.Relation);

            var mapping = new HbmManyToOne();
            var mapper  = new ManyToOneMapper(member, mapping, hbmMapping);

            mapper.Formula("formula");
            mapper.Column(cm => cm.Unique(true));
            mapping.formula.Should().Be.Null();
        }
Beispiel #22
0
        public void SettingColumnPlainValuesOverridesFormula()
        {
            var member = ForClass <MyClass> .Property(c => c.Autoproperty);

            var mapping = new HbmProperty();
            var mapper  = new PropertyMapper(member, mapping);

            mapper.Formula("formula");
            mapper.Column("colName");
            mapping.formula.Should().Be.Null();
            mapping.column.Should().Be("colName");
        }
Beispiel #23
0
        public void WhenRelationIsNotOneToManyThenNoMatch()
        {
            var orm     = new Mock <IDomainInspector>();
            var pattern = new OneToManyKeyColumnApplier(orm.Object);

            orm.Setup(x => x.IsOneToMany(It.Is <Type>(t => t == typeof(MyClass)), It.Is <Type>(t => t == typeof(MyRelated)))).Returns(false);
            var pathCollection = new PropertyPath(null, ForClass <MyClass> .Property(p => p.Relateds));
            var pathMap        = new PropertyPath(null, ForClass <MyClass> .Property(p => p.Map));

            pattern.Match(pathCollection).Should().Be.False();
            pattern.Match(pathMap).Should().Be.False();
        }
Beispiel #24
0
        public void SettingFormulaOverridesColumn()
        {
            var member = ForClass <MyClass> .Property(c => c.Autoproperty);

            var mapping = new HbmProperty();
            var mapper  = new PropertyMapper(member, mapping);

            mapper.Column(cm => cm.Unique(true));
            mapper.Formula("formula");
            mapping.formula.Should().Be("formula");
            mapping.Items.Should().Be.Null();
        }
        public void CanMapProperty()
        {
            var mapdoc    = new HbmMapping();
            var component = new HbmNestedCompositeElement();
            var mapper    = new ComponentNestedElementMapper(typeof(Number), mapdoc, component, ForClass <Address> .Property(a => a.Number));

            mapper.Property(ForClass <Number> .Property(a => a.Block), x => { });
            mapper.Property(ForClass <Number> .Property(a => a.Dir), x => { });

            component.Properties.Should().Have.Count.EqualTo(2);
            component.Properties.Select(cp => cp.Name).Should().Have.SameValuesAs("Block", "Dir");
        }
Beispiel #26
0
        public void WhenRelationIsOneToManyInsideComponentThenNoMatch()
        {
            var orm     = new Mock <IDomainInspector>();
            var pattern = new CollectionOfElementsColumnApplier(orm.Object);

            orm.Setup(x => x.IsOneToMany(It.Is <Type>(t => t == typeof(MyComponent)), It.Is <Type>(t => t == typeof(MyRelated)))).Returns(true);

            var level0 = new PropertyPath(null, ForClass <MyClass> .Property(p => p.Component));
            var path   = new PropertyPath(level0, ForClass <MyComponent> .Property(p => p.Relateds));

            pattern.Match(path).Should().Be.False();
        }
        private Mock <IDomainInspector> GetMockedDomainInspector()
        {
            var orm = new Mock <IDomainInspector>();

            orm.Setup(m => m.IsEntity(It.IsAny <Type>())).Returns(true);
            orm.Setup(m => m.IsRootEntity(It.IsAny <Type>())).Returns(true);
            orm.Setup(m => m.IsTablePerClass(It.IsAny <Type>())).Returns(true);
            orm.Setup(m => m.IsPersistentId(It.Is <MemberInfo>(mi => mi.Name == "Id"))).Returns(true);
            orm.Setup(m => m.IsPersistentProperty(It.Is <MemberInfo>(mi => mi.Name != "Id"))).Returns(true);
            orm.Setup(m => m.IsDictionary(It.Is <MemberInfo>(mi => mi == ForClass <MyClass> .Property(p => p.Dictionary)))).Returns(true);
            return(orm);
        }
Beispiel #28
0
        public void CanMapManyToOne()
        {
            var mapdoc    = new HbmMapping();
            var component = new HbmCompositeMapKey();
            var mapper    = new ComponentMapKeyMapper(typeof(ToySkill), component, mapdoc);

            mapper.ManyToOne(ForClass <ToySkill> .Property(ts => ts.Skill), x => { });

            component.Properties.Should().Have.Count.EqualTo(1);
            component.Properties.First().Name.Should().Be.EqualTo("Skill");
            component.Properties.First().Should().Be.OfType <HbmKeyManyToOne>();
        }
Beispiel #29
0
        public void WhenCollectionOfElementsInsideComponentThenApplyPropertyPathNameElement()
        {
            var orm     = new Mock <IDomainInspector>();
            var pattern = new CollectionOfElementsColumnApplier(orm.Object);

            var mapper = new Mock <IElementMapper>();
            var level0 = new PropertyPath(null, ForClass <MyClass> .Property(p => p.Component));
            var path   = new PropertyPath(level0, ForClass <MyComponent> .Property(p => p.Strings));

            pattern.Apply(path, mapper.Object);
            mapper.Verify(elementMapper => elementMapper.Column(It.Is <string>(s => s == "ComponentStringsElement")));
        }
        public void WhenSetFormulaWithNullThenDoNothing()
        {
            var hbmMapping = new HbmMapping();
            var member     = ForClass <MyClass> .Property(c => c.Relation);

            var mapping = new HbmManyToOne();
            var mapper  = new ManyToOneMapper(member, mapping, hbmMapping);

            mapper.Column("MyColumn");
            mapper.Formula(null);
            mapping.formula.Should().Be.Null();
            mapping.column.Should().Not.Be.Null();
        }