Exemplo n.º 1
0
        public void WhenArrayThenNoMatch()
        {
            var member = ForClass <MyClass> .Property(x => x.Array);

            var pattern = new UseBagWhenGenericListPattern();

            pattern.Match(member).Should().Be.False();
        }
        public void WhenListThenNoMatch()
        {
            var member = ForClass <MyClass> .Property(x => x.List);

            var pattern = new UseSetWhenGenericCollectionPattern();

            pattern.Match(member).Should().Be.False();
        }
        public void AssignPropertyReference()
        {
            var hbm = new HbmKey();
            var km  = new KeyMapper(typeof(Animal), hbm);

            km.PropertyRef(ForClass <Animal> .Property(x => x.Name));
            hbm.propertyref.Should().Be("Name");
        }
Exemplo n.º 4
0
        public void WhenListThenMatch()
        {
            var member = ForClass <MyClass> .Property(x => x.List);

            var pattern = new UseBagWhenGenericListPattern();

            pattern.Match(member).Should().Be.True();
        }
        public void WhenGenericCollectionThenMatch()
        {
            var member = ForClass <MyClass> .Property(x => x.Collection);

            var pattern = new UseSetWhenGenericCollectionPattern();

            pattern.Match(member).Should().Be.True();
        }
        public void WhenRelationIsElementsInsideComponentThenNoMatch()
        {
            var orm     = new Mock <IDomainInspector>();
            var pattern = new CollectionOfComponentsKeyColumnApplier(orm.Object);
            var path    = new PropertyPath(new PropertyPath(null, ForClass <MyClass> .Property(p => p.Components)), ForClass <MyComponent> .Property(p => p.Elements));

            pattern.Match(path).Should().Be.False();
        }
        public void WhenNoGenericCollectionThenNoMatch()
        {
            var orm     = new Mock <IDomainInspector>();
            var pattern = new CollectionOfComponentsKeyColumnApplier(orm.Object);
            var path    = new PropertyPath(null, ForClass <MyClass> .Property(p => p.Something));

            pattern.Match(path).Should().Be.False();
        }
Exemplo n.º 8
0
        public void WhenCollectionOfComponentsThenNoMatch()
        {
            var orm = GetDomainInspectorMock();

            var pattern = new UnidirectionalOneToManyMemberPattern(orm.Object);

            pattern.Match(ForClass <MyClass> .Property(mc => mc.Components)).Should().Be.False();
        }
Exemplo n.º 9
0
        public void WhenDictionaryUnidirectionalThenMatch()
        {
            var orm = GetDomainInspectorMock();

            var pattern = new UnidirectionalOneToManyMemberPattern(orm.Object);

            pattern.Match(ForClass <MyClass> .Property(mc => mc.DicRelateds)).Should().Be.True();
        }
Exemplo n.º 10
0
        public void WhenRelationNotDeclaredAsManyToManyUnidirectionalThenNoMatch()
        {
            var orm     = new Mock <IDomainInspector>();
            var pattern = new ManyToManyPattern(orm.Object);

            pattern.Match(ForClass <MyClass> .Property(x => x.MyOtherClasses)).Should().Be.False();
            pattern.Match(ForClass <MyClass> .Property(x => x.MyBidirects)).Should().Be.False();
            pattern.Match(ForClass <MyBidirect> .Property(x => x.MyClasses)).Should().Be.False();
        }
Exemplo n.º 11
0
        public void WhenNullableEnumAlwaysApplyColumnType()
        {
            var propertyMapper = new Mock <IElementMapper>();
            var applier        = new EnumElementAsStringApplier();

            applier.Apply(ForClass <MyClass> .Property(x => x.MyEnumNullable), propertyMapper.Object);

            propertyMapper.Verify(x => x.Type(It.Is <Type>(t => t == typeof(EnumStringType <MyEnum?>)), It.Is <object>(p => p == null)));
        }
Exemplo n.º 12
0
        public void WhenPreviousLevelIsCollectionThenDoesNotMatch()
        {
            var lelev0  = new PropertyPath(null, ForClass <MyClassWithComponent> .Property(x => x.Component1));
            var lelev1  = new PropertyPath(lelev0, ForClass <MyComponent> .Property(x => x.Collection));
            var lelev2  = new PropertyPath(lelev1, ForClass <MyClass> .Property(x => x.Fake1));
            var pattern = new ComponentMemberDeepPathPattern();

            pattern.Match(lelev2).Should().Be.False();
        }
Exemplo n.º 13
0
        public void AlwaysApplyCurrencyType()
        {
            var propertyMapper = new Mock <IPropertyMapper>();
            var applier        = new UseCurrencyForDecimalApplier();

            applier.Apply(ForClass <MyClass> .Property(x => x.Price), propertyMapper.Object);

            propertyMapper.Verify(x => x.Type(It.Is <IType>(t => t == NHibernateUtil.Currency)));
        }
        public void CanSetLazy()
        {
            var mapdoc    = new HbmMapping();
            var component = new HbmComponent();
            var mapper    = new ComponentMapper(component, typeof(Name), ForClass <Person> .Property(p => p.Name), mapdoc);

            mapper.Lazy(true);
            component.lazy.Should().Be.True();
        }
Exemplo n.º 15
0
        public void WhenCollectionOfComponentsThenNoMatch()
        {
            var orm = GetDomainInspectorMock();

            var pattern  = new UnidirectionalOneToManyMultipleCollectionsKeyColumnApplier(orm.Object);
            var property = new PropertyPath(null, ForClass <MyClass> .Property(mc => mc.Components));

            pattern.Match(property).Should().Be.False();
        }
Exemplo n.º 16
0
        public void AlwaysApplyColumnType()
        {
            var propertyMapper = new Mock <IPropertyMapper>();
            var applier        = new MsSQL2008DateTimeApplier();

            applier.Apply(ForClass <MyClass> .Property(x => x.CreatedAt), propertyMapper.Object);

            propertyMapper.Verify(x => x.Type(It.Is <IType>(t => t == NHibernateUtil.DateTime2)));
        }
Exemplo n.º 17
0
        public void MatchAnyValidPropertyPath()
        {
            var applier = new ListIndexAsPropertyPosColumnNameApplier();

            applier.Match(null).Should().Be.False();
            var ppath = new PropertyPath(null, ForClass <MyClass> .Property(mc => mc.Numbers));

            applier.Match(ppath).Should().Be.True();
        }
        public void CanSetInsert()
        {
            var mapdoc    = new HbmMapping();
            var component = new HbmComponent();
            var mapper    = new ComponentMapper(component, typeof(Name), ForClass <Person> .Property(p => p.Name), mapdoc);

            mapper.Insert(false);
            component.insert.Should().Be.False();
        }
        public void CanSetParentAccessor()
        {
            var mapdoc    = new HbmMapping();
            var component = new HbmComponent();
            var mapper    = new ComponentMapper(component, typeof(Name), ForClass <Person> .Property(p => p.Name), mapdoc);

            mapper.Parent(typeof(Address).GetProperty("Parent"), pm => pm.Access(Accessor.Field));
            component.Parent.access.Should().Contain("field");
        }
        public void CanSetOptimisticLock()
        {
            var mapdoc    = new HbmMapping();
            var component = new HbmComponent();
            var mapper    = new ComponentMapper(component, typeof(Name), ForClass <Person> .Property(p => p.Name), mapdoc);

            mapper.OptimisticLock(false);
            component.optimisticlock.Should().Be.False();
        }
        public void WhenRelationIsNotOneToManyThenNoMatch()
        {
            var orm     = new Mock <IDomainInspector>();
            var pattern = new OneToManyPattern(orm.Object);

            orm.Setup(x => x.IsOneToMany(It.Is <Type>(t => t == typeof(MyClass)), It.Is <Type>(t => t == typeof(Element)))).Returns(false);

            pattern.Match(ForClass <MyClass> .Property(p => p.Elements)).Should().Be.False();
        }
Exemplo n.º 22
0
        public void WhenComponentsCollectionInsideComponentThenMatch()
        {
            var orm     = new Mock <IDomainInspector>();
            var pattern = new CollectionOfComponentsPattern(orm.Object);

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

            pattern.Match(ForClass <MyComponent> .Property(p => p.Components)).Should().Be.True();
        }
        public void WhenVersionPropertyDefinedOnInterfaceThenRecognizeItOnConcreteClass()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <MyVersionedEntityOnInterface>();
            orm.VersionProperty <IVersionedEntity>(versionedEntity => versionedEntity.Version);

            orm.IsVersion(ForClass <MyVersionedEntityOnInterface> .Property(e => e.Version)).Should().Be.True();
        }
        public void WhenRegisterExclusionPropertyOnInterfaceThenShouldExcludePropertyOfConcreteImpl()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <Person>();
            orm.ExcludeProperty <IEntity>(p => p.Something);

            orm.IsPersistentProperty(ForClass <Person> .Property(p => p.Something)).Should().Be.False();
        }
Exemplo n.º 25
0
        public void WhenDictionaryUnidirectionalThenMatch()
        {
            var orm = GetDomainInspectorMock();

            var pattern  = new UnidirectionalOneToManyMultipleCollectionsKeyColumnApplier(orm.Object);
            var property = new PropertyPath(null, ForClass <MyClass> .Property(mc => mc.DicRelateds));

            pattern.Match(property).Should().Be.True();
        }
Exemplo n.º 26
0
        public void WhenRegisterCollectionToCollectionThenFindRelation()
        {
            var orm = new ObjectRelationalMapper();

            orm.Bidirectional <B, A>(b => b.Generic, a => a.Bag);

            orm.GetBidirectionalMember(typeof(A), ForClass <A> .Property(x => x.Bag), typeof(B)).Should().Be(ForClass <B> .Property(x => x.Generic));
            orm.GetBidirectionalMember(typeof(B), ForClass <B> .Property(x => x.Generic), typeof(A)).Should().Be(ForClass <A> .Property(x => x.Bag));
        }
        public void WhenRegisterPersistentPropertyOnInterfaceThenShouldRecognizePropertyOfConcreteImpl()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <Person>();
            orm.PersistentProperty <IEntity>(p => p.IsValid);

            orm.IsPersistentProperty(ForClass <Person> .Property(p => p.IsValid)).Should().Be.True();
        }
        public void WhenSingleUsageThenNoMatch()
        {
            var orm = GetDomainInspectorMockForBaseTests();

            var applier  = new UnidirectionalOneToManyMultipleCollectionsKeyColumnApplier(orm.Object);
            var property = new PropertyPath(null, ForClass <MySingleUsage> .Property(x => x.CurrentPositions));

            applier.Match(property).Should().Be.False();
        }
        public void WhenRelationIsOneToManyInsideComponentThenNoMatch()
        {
            var orm     = new Mock <IDomainInspector>();
            var pattern = new CollectionOfElementsOnlyPattern(orm.Object);

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

            pattern.Match(ForClass <MyComponent> .Property(p => p.Relateds)).Should().Be.False();
        }
Exemplo n.º 30
0
        public void WhenRelationIsForMapKeyThenMatch()
        {
            var orm     = new Mock <IDomainInspector>();
            var pattern = new CollectionOfElementsPattern(orm.Object);

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

            pattern.Match(ForClass <MyClass> .Property(p => p.MapRelationOnKey)).Should().Be.True();
        }