Example #1
0
        public void Start(string prefix, MappedPropertyInfo item)
        {
            HbmSet              set       = item.HbmObject <HbmSet>();
            MappedPropertyInfo  childItem = new MappedPropertyInfo(set.Item, item.FileName);
            PropertyMappingType subType   = childItem.Type;

            if (subType == PropertyMappingType.ManyToMany)
            {
                _builder.StartMethod(prefix, string.Format("{0}<{1}>(x => x.{2})", FluentNHibernateNames.HasManyToMany, item.ReturnType, item.Name));
                _builder.AddLine(string.Format(".{0}(\"{1}\")", KeyColumn.FluentNHibernateNames.ChildKeyColumn, childItem.ColumnName));
            }
            else if (subType == PropertyMappingType.OneToMany)
            {
                _builder.StartMethod(prefix, string.Format("{0}<{1}>(x => x.{2})", FluentNHibernateNames.HasMany, item.ReturnType, item.Name));
            }
            else
            {
                _builder.StartMethod(prefix, "set?(x => x" + item.Name + ")");
            }
            _builder.AddLine(string.Format(".{0}()", FluentNHibernateNames.AsSet));
            _keyColumn.Add(set.inverse, item.ColumnName, subType);
            _lazyLoad.Add(set.lazySpecified, set.lazy);
            _table.Add(set.table);
            _inverse.Add(set.inverse);
            _cascade.Add(set.cascade);
            _fetch.Add(set.fetch);
            _orderBy.Add(set.orderby);
            _where.Add(set.where);
            _cacheBuilder.Add(set.cache);
        }
Example #2
0
        public void SetCollectionTypeByType()
        {
            var hbm    = new HbmSet();
            var mapper = new SetMapper(typeof(Animal), typeof(Animal), hbm);

            mapper.Type(typeof(FakeUserCollectionType));
            hbm.CollectionType.Should().Contain("FakeUserCollectionType");
        }
Example #3
0
        public void SetCollectionTypeByWrongTypeShouldThrow()
        {
            var hbm    = new HbmSet();
            var mapper = new SetMapper(typeof(Animal), typeof(Animal), hbm);

            Executing.This(() => mapper.Type(null)).Should().Throw <ArgumentNullException>();
            Executing.This(() => mapper.Type(typeof(object))).Should().Throw <ArgumentOutOfRangeException>();
        }
Example #4
0
        public void SetBatchSize()
        {
            var hbm    = new HbmSet();
            var mapper = new SetMapper(typeof(Animal), typeof(Animal), hbm);

            mapper.BatchSize(10);
            hbm.BatchSize.Should().Be.EqualTo(10);
        }
Example #5
0
        public void SetSort()
        {
            var hbm    = new HbmSet();
            var mapper = new SetMapper(typeof(Animal), typeof(Animal), hbm);

            mapper.Sort();
            hbm.Sort.Should().Be.EqualTo("natural");
        }
Example #6
0
        public void SetWhere()
        {
            var hbm    = new HbmSet();
            var mapper = new SetMapper <Animal, Animal>(hbm);

            mapper.Where = "c > 10";
            hbm.Where.Should().Be.EqualTo("c > 10");
        }
Example #7
0
 public static bool?IsUnique(this HbmSet item)
 {
     if (item.key == null || !item.key.uniqueSpecified)
     {
         return(null);
     }
     return(item.key.unique);
 }
Example #8
0
        public void SetBatchSize()
        {
            var hbm    = new HbmSet();
            var mapper = new SetMapper <Animal, Animal>(hbm);

            mapper.BatchSize = 10;
            hbm.BatchSize.Should().Be.EqualTo(10);
        }
Example #9
0
        public void SetSort()
        {
            var hbm    = new HbmSet();
            var mapper = new SetMapper <Animal, Animal>(hbm);

            mapper.Sort();
            hbm.Sort.Should().Be.EqualTo("natural");
        }
Example #10
0
        public void SetWhere()
        {
            var hbm    = new HbmSet();
            var mapper = new SetMapper(typeof(Animal), typeof(Animal), hbm);

            mapper.Where("c > 10");
            hbm.Where.Should().Be.EqualTo("c > 10");
        }
        public void SetCollectionTypeByWrongTypeShouldThrow()
        {
            var hbm    = new HbmSet();
            var mapper = new SetMapper(typeof(Animal), typeof(Animal), hbm);

            ActionAssert.Throws <ArgumentNullException>(() => mapper.Type(null));
            ActionAssert.Throws <ArgumentOutOfRangeException>(() => mapper.Type(typeof(object)));
        }
Example #12
0
        private Mapping.Collection CreateSet(HbmSet setMapping, string prefix, string path,
                                             PersistentClass owner, System.Type containingType, IDictionary <string, MetaAttribute> inheritedMetas)
        {
            var setCollection = new Set(owner);

            BindCollection(setMapping, setCollection, prefix, path, containingType, inheritedMetas);
            AddSetSecondPass(setMapping, setCollection, inheritedMetas);
            return(setCollection);
        }
Example #13
0
 private void AddSetSecondPass(HbmSet setMapping, Set model, IDictionary <string, MetaAttribute> inheritedMetas)
 {
     mappings.AddSecondPass(delegate(IDictionary <string, PersistentClass> persistentClasses)
     {
         PreCollectionSecondPass(model);
         BindSetSecondPass(setMapping, model, persistentClasses, inheritedMetas);
         PostCollectionSecondPass(model);
     });
 }
Example #14
0
 public SetMapper(HbmSet mapping)
 {
     this.mapping = mapping;
     if (mapping.Key == null)
     {
         mapping.key = new HbmKey();
     }
     keyMapper = new KeyMapper <TEntity>(mapping.Key);
 }
Example #15
0
        public void CanSetCache()
        {
            var hbm    = new HbmSet();
            var mapper = new SetMapper(typeof(Animal), typeof(Animal), hbm);

            mapper.Cache(x => x.Region("pizza"));

            hbm.cache.Should().Not.Be.Null();
        }
Example #16
0
        public void WhenActionIsNullThenAddFilterName()
        {
            var hbm    = new HbmSet();
            var mapper = new SetMapper(typeof(Animal), typeof(Animal), hbm);

            mapper.Filter("filter1", null);
            hbm.filter.Length.Should().Be(1);
            hbm.filter[0].Satisfy(f => f.name == "filter1" && f.condition == null);
        }
Example #17
0
        public void CanSetAFilterThroughAction()
        {
            var hbm    = new HbmSet();
            var mapper = new SetMapper(typeof(Animal), typeof(Animal), hbm);

            mapper.Filter("filter1", f => f.Condition("condition1"));
            hbm.filter.Length.Should().Be(1);
            hbm.filter[0].Satisfy(f => f.name == "filter1" && f.condition == "condition1");
        }
Example #18
0
        public void CallKeyMapper()
        {
            var  hbm      = new HbmSet();
            var  mapper   = new SetMapper <Animal, Animal>(hbm);
            bool kmCalled = false;

            mapper.Key(km => kmCalled = true);
            hbm.Key.Should().Not.Be.Null();
            kmCalled.Should().Be.True();
        }
            public void Should_get_null_given_key_is_null()
            {
                HbmSet set = new HbmSet
                {
                    key = null
                };
                bool?result = set.IsUnique();

                result.ShouldBeNull();
            }
Example #20
0
        private void BindSetSecondPass(HbmSet setMapping, Set model,
                                       IDictionary <string, PersistentClass> persistentClasses, IDictionary <string, MetaAttribute> inheritedMetas)
        {
            BindCollectionSecondPass(setMapping, model, persistentClasses, inheritedMetas);

            if (!model.IsOneToMany)
            {
                model.CreatePrimaryKey();
            }
        }
Example #21
0
        public void SetMutable()
        {
            var hbm    = new HbmSet();
            var mapper = new SetMapper <Animal, Animal>(hbm);

            mapper.Mutable = true;
            hbm.Mutable.Should().Be.True();
            mapper.Mutable = false;
            hbm.Mutable.Should().Be.False();
        }
Example #22
0
        public void SetMutable()
        {
            var hbm    = new HbmSet();
            var mapper = new SetMapper(typeof(Animal), typeof(Animal), hbm);

            mapper.Mutable(true);
            hbm.Mutable.Should().Be.True();
            mapper.Mutable(false);
            hbm.Mutable.Should().Be.False();
        }
            public void Should_get_the_correct_value()
            {
                const string expected = "FirstName";
                HbmSet       set      = new HbmSet
                {
                    name = expected
                };
                string result = set.GetPropertyName();

                result.ShouldBeEqualTo(expected);
            }
        public void Set(MemberInfo property, Action <ISetPropertiesMapper> collectionMapping, Action <ICollectionElementRelation> mapping)
        {
            var hbm = new HbmSet {
                name = property.Name
            };

            System.Type collectionElementType = property.DetermineRequiredCollectionElementType();
            collectionMapping(new SetMapper(Container, collectionElementType, new NoMemberPropertyMapper(), hbm));
            mapping(new CollectionElementRelation(collectionElementType, MapDoc, rel => hbm.Item = rel));
            AddProperty(hbm);
        }
Example #25
0
        public void CanChangeAccessor()
        {
            var hbm = new HbmSet {
                name = "Children"
            };
            var mapper = new SetMapper(typeof(Animal), typeof(Animal), hbm);

            mapper.Access(Accessor.Field);

            hbm.Access.Should().Not.Be.Null();
        }
            public void Should_get__false__given_inverse_is_false()
            {
                HbmSet set = new HbmSet
                {
                    inverse = false
                };
                bool?result = set.CanBeNull();

                result.ShouldNotBeNull();
                result.Value.ShouldBeFalse();
            }
Example #27
0
        public void SetLazy()
        {
            var hbm    = new HbmSet();
            var mapper = new SetMapper <Animal, Animal>(hbm);

            mapper.Lazy = CollectionLazy.Extra;
            hbm.Lazy.Should().Be.EqualTo(HbmCollectionLazy.Extra);
            mapper.Lazy = CollectionLazy.NoLazy;
            hbm.Lazy.Should().Be.EqualTo(HbmCollectionLazy.False);
            mapper.Lazy = CollectionLazy.Lazy;
            hbm.Lazy.Should().Be.EqualTo(HbmCollectionLazy.True);
        }
        public virtual void Set(MemberInfo property, Action <ISetPropertiesMapper> collectionMapping, Action <ICollectionElementRelation> mapping)
        {
            var hbm = new HbmSet {
                name = property.Name
            };

            System.Type propertyType          = property.GetPropertyOrFieldType();
            System.Type collectionElementType = propertyType.DetermineCollectionElementType();
            collectionMapping(new SetMapper(container, collectionElementType, hbm));
            mapping(new CollectionElementRelation(collectionElementType, MapDoc, rel => hbm.Item = rel));
            AddProperty(hbm);
        }
Example #29
0
        public void SetLazy()
        {
            var hbm    = new HbmSet();
            var mapper = new SetMapper(typeof(Animal), typeof(Animal), hbm);

            mapper.Lazy(CollectionLazy.Extra);
            hbm.Lazy.Should().Be.EqualTo(HbmCollectionLazy.Extra);
            mapper.Lazy(CollectionLazy.NoLazy);
            hbm.Lazy.Should().Be.EqualTo(HbmCollectionLazy.False);
            mapper.Lazy(CollectionLazy.Lazy);
            hbm.Lazy.Should().Be.EqualTo(HbmCollectionLazy.True);
        }
Example #30
0
        public void WhenSameNameThenOverrideCondition()
        {
            var hbm    = new HbmSet();
            var mapper = new SetMapper(typeof(Animal), typeof(Animal), hbm);

            mapper.Filter("filter1", f => f.Condition("condition1"));
            mapper.Filter("filter2", f => f.Condition("condition2"));
            mapper.Filter("filter1", f => f.Condition("anothercondition1"));
            hbm.filter.Length.Should().Be(2);
            hbm.filter.Satisfy(filters => filters.Any(f => f.name == "filter1" && f.condition == "anothercondition1"));
            hbm.filter.Satisfy(filters => filters.Any(f => f.name == "filter2" && f.condition == "condition2"));
        }