Пример #1
0
        public void SetListIndex()
        {
            var hbm = new HbmList();

            new ListMapper <Animal, Animal>(hbm);
            hbm.Item.Should().Not.Be.Null().And.Be.OfType <HbmListIndex>();
        }
Пример #2
0
        public ListMapper(System.Type ownerType, System.Type elementType, IAccessorPropertyMapper accessorMapper, HbmList mapping)
        {
            if (ownerType == null)
            {
                throw new ArgumentNullException("ownerType");
            }
            if (elementType == null)
            {
                throw new ArgumentNullException("elementType");
            }
            if (mapping == null)
            {
                throw new ArgumentNullException("mapping");
            }
            OwnerType    = ownerType;
            ElementType  = elementType;
            this.mapping = mapping;
            if (mapping.Key == null)
            {
                mapping.key = new HbmKey();
            }
            keyMapper = new KeyMapper(ownerType, mapping.Key);
            var listIndex = new HbmListIndex();

            mapping.Item         = listIndex;
            listIndexMapper      = new ListIndexMapper(ownerType, listIndex);
            entityPropertyMapper = accessorMapper;
        }
Пример #3
0
        private void BindListSecondPass(HbmList listMapping, List model,
                                        IDictionary <string, PersistentClass> persistentClasses, IDictionary <string, MetaAttribute> inheritedMetas)
        {
            BindCollectionSecondPass(listMapping, model, persistentClasses, inheritedMetas);

            // Index
            BindCollectionIndex(listMapping, model);
            if (listMapping.ListIndex != null && !string.IsNullOrEmpty(listMapping.ListIndex.@base))
            {
                model.BaseIndex = Convert.ToInt32(listMapping.ListIndex.@base);
            }

            if (model.IsOneToMany && !model.Key.IsNullable && !model.IsInverse)
            {
                string          entityName = ((OneToMany)model.Element).ReferencedEntityName;
                PersistentClass referenced = mappings.GetClass(entityName);
                var             ib         = new IndexBackref();
                ib.Name           = '_' + model.OwnerEntityName + "." + listMapping.Name + "IndexBackref";
                ib.IsUpdateable   = false;
                ib.IsSelectable   = false;
                ib.CollectionRole = model.Role;
                ib.EntityName     = model.Owner.EntityName;
                ib.Value          = model.Index;
                referenced.AddProperty(ib);
            }
        }
Пример #4
0
        public void SetWhere()
        {
            var hbm    = new HbmList();
            var mapper = new ListMapper <Animal, Animal>(hbm);

            mapper.Where = "c > 10";
            hbm.Where.Should().Be.EqualTo("c > 10");
        }
Пример #5
0
        public void SetCollectionTypeByType()
        {
            var hbm    = new HbmList();
            var mapper = new ListMapper(typeof(Animal), typeof(Animal), hbm);

            mapper.Type(typeof(FakeUserCollectionType));
            hbm.CollectionType.Should().Contain("FakeUserCollectionType");
        }
Пример #6
0
        public void SetWhere()
        {
            var hbm    = new HbmList();
            var mapper = new ListMapper(typeof(Animal), typeof(Animal), hbm);

            mapper.Where("c > 10");
            hbm.Where.Should().Be.EqualTo("c > 10");
        }
Пример #7
0
        public void SetBatchSize()
        {
            var hbm    = new HbmList();
            var mapper = new ListMapper <Animal, Animal>(hbm);

            mapper.BatchSize = 10;
            hbm.BatchSize.Should().Be.EqualTo(10);
        }
Пример #8
0
        public void SetBatchSize()
        {
            var hbm    = new HbmList();
            var mapper = new ListMapper(typeof(Animal), typeof(Animal), hbm);

            mapper.BatchSize(10);
            hbm.BatchSize.Should().Be.EqualTo(10);
        }
Пример #9
0
 private void AddListSecondPass(HbmList listMapping, List model, IDictionary <string, MetaAttribute> inheritedMetas)
 {
     mappings.AddSecondPass(delegate(IDictionary <string, PersistentClass> persistentClasses)
     {
         PreCollectionSecondPass(model);
         BindListSecondPass(listMapping, model, persistentClasses, inheritedMetas);
         PostCollectionSecondPass(model);
     });
 }
Пример #10
0
        public void CanChangeListIndexDef()
        {
            var hbm    = new HbmList();
            var mapper = new ListMapper(typeof(Animal), typeof(Animal), hbm);

            mapper.Index(i => { i.Column("Pepe");
                                i.Base(1); });
            hbm.Item.Should().Be.OfType <HbmListIndex>().And.Value.Satisfy(i => i.column1 == "Pepe" && i.@base == "1");
        }
Пример #11
0
        public void CanSetAFilterThroughAction()
        {
            var hbm    = new HbmList();
            var mapper = new ListMapper(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");
        }
Пример #12
0
        public void CanSetCache()
        {
            var hbm    = new HbmList();
            var mapper = new ListMapper(typeof(Animal), typeof(Animal), hbm);

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

            hbm.cache.Should().Not.Be.Null();
        }
Пример #13
0
        private Mapping.Collection CreateList(HbmList listMapping, string prefix, string path,
                                              PersistentClass owner, System.Type containingType, IDictionary <string, MetaAttribute> inheritedMetas)
        {
            var list = new List(owner);

            BindCollection(listMapping, list, prefix, path, containingType, inheritedMetas);
            AddListSecondPass(listMapping, list, inheritedMetas);
            return(list);
        }
Пример #14
0
        public void WhenActionIsNullThenAddFilterName()
        {
            var hbm    = new HbmList();
            var mapper = new ListMapper(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);
        }
Пример #15
0
        public void SetMutable()
        {
            var hbm    = new HbmList();
            var mapper = new ListMapper(typeof(Animal), typeof(Animal), hbm);

            mapper.Mutable(true);
            hbm.Mutable.Should().Be.True();
            mapper.Mutable(false);
            hbm.Mutable.Should().Be.False();
        }
Пример #16
0
        public void CallKeyMapper()
        {
            var  hbm      = new HbmList();
            var  mapper   = new ListMapper <Animal, Animal>(hbm);
            bool kmCalled = false;

            mapper.Key(km => kmCalled = true);
            hbm.Key.Should().Not.Be.Null();
            kmCalled.Should().Be.True();
        }
Пример #17
0
 public ListMapper(HbmList mapping)
 {
     this.mapping = mapping;
     if (mapping.Key == null)
     {
         mapping.key = new HbmKey();
     }
     keyMapper    = new KeyMapper <TEntity>(mapping.Key);
     mapping.Item = new HbmListIndex();
 }
Пример #18
0
        public void SetMutable()
        {
            var hbm    = new HbmList();
            var mapper = new ListMapper <Animal, Animal>(hbm);

            mapper.Mutable = true;
            hbm.Mutable.Should().Be.True();
            mapper.Mutable = false;
            hbm.Mutable.Should().Be.False();
        }
Пример #19
0
        public void CanChangeAccessor()
        {
            var hbm = new HbmList {
                name = "Children"
            };
            var mapper = new ListMapper(typeof(Animal), typeof(Animal), hbm);

            mapper.Access(Accessor.Field);

            hbm.Access.Should().Not.Be.Null();
        }
        public void List(MemberInfo property, Action <IListPropertiesMapper> collectionMapping, Action <ICollectionElementRelation> mapping)
        {
            var hbm = new HbmList {
                name = property.Name
            };

            System.Type collectionElementType = property.DetermineRequiredCollectionElementType();
            collectionMapping(new ListMapper(Container, collectionElementType, new NoMemberPropertyMapper(), hbm));
            mapping(new CollectionElementRelation(collectionElementType, MapDoc, rel => hbm.Item1 = rel));
            AddProperty(hbm);
        }
Пример #21
0
        public void SetLazy()
        {
            var hbm    = new HbmList();
            var mapper = new ListMapper <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);
        }
Пример #22
0
        private void BindListSecondPass(HbmList listMapping, List model,
                                        IDictionary <string, PersistentClass> persistentClasses, IDictionary <string, MetaAttribute> inheritedMetas)
        {
            BindCollectionSecondPass(listMapping, model, persistentClasses, inheritedMetas);

            // Index
            BindCollectionIndex(listMapping, model);
            if (listMapping.ListIndex != null && !string.IsNullOrEmpty(listMapping.ListIndex.@base))
            {
                model.BaseIndex = Convert.ToInt32(listMapping.ListIndex.@base);
            }
        }
Пример #23
0
        public void WhenSameNameThenOverrideCondition()
        {
            var hbm    = new HbmList();
            var mapper = new ListMapper(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"));
        }
        public virtual void List(MemberInfo property, Action <IListPropertiesMapper> collectionMapping, Action <ICollectionElementRelation> mapping)
        {
            var hbm = new HbmList {
                name = property.Name
            };

            System.Type propertyType          = property.GetPropertyOrFieldType();
            System.Type collectionElementType = propertyType.DetermineCollectionElementType();
            collectionMapping(new ListMapper(container, collectionElementType, hbm));
            mapping(new CollectionElementRelation(collectionElementType, MapDoc, rel => hbm.Item1 = rel));
            AddProperty(hbm);
        }
Пример #25
0
        public void SetLazy()
        {
            var hbm    = new HbmList();
            var mapper = new ListMapper(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);
        }
Пример #26
0
        public void List <TElement>(Expression <Func <TEntity, IEnumerable <TElement> > > property,
                                    Action <ICollectionPropertiesMapper <TEntity, TElement> > collectionMapping,
                                    Action <ICollectionElementRelation <TElement> > mapping) where TElement : class
        {
            var memberInfo = TypeUtils.DecodeMemberAccessExpression(property);
            var hbm        = new HbmList {
                name = memberInfo.Name
            };

            collectionMapping(new ListMapper <TEntity, TElement>(hbm));
            mapping(new CollectionElementRelation <TElement>(MapDoc, rel => hbm.Item1 = rel));
            AddProperty(hbm);
        }
Пример #27
0
        public void List <TElement>(Expression <Func <TEntity, IEnumerable <TElement> > > property,
                                    Action <ICollectionPropertiesMapper <TEntity, TElement> > collectionMapping)
        {
            var memberInfo = TypeUtils.DecodeMemberAccessExpression(property);
            var hbm        = new HbmList {
                name = memberInfo.Name
            };

            collectionMapping(new ListMapper <TEntity, TElement>(hbm));
            hbm.Item1 = new HbmElement {
                type1 = TypeUtils.GetTypeName <TElement>()
            };
            AddProperty(hbm);
        }
Пример #28
0
        public void WhenSetTwoCachePropertiesInTwoActionsThenSetTheTwoValuesWithoutLostTheFirst()
        {
            var hbm    = new HbmList();
            var mapper = new ListMapper(typeof(Animal), typeof(Animal), hbm);

            mapper.Cache(ch => ch.Region("pizza"));
            mapper.Cache(ch => ch.Usage(CacheUsage.NonstrictReadWrite));

            var hbmCache = hbm.cache;

            hbmCache.Should().Not.Be.Null();
            hbmCache.region.Should().Be("pizza");
            hbmCache.usage.Should().Be(HbmCacheUsage.NonstrictReadWrite);
        }
Пример #29
0
        public void SetFetchMode()
        {
            var hbm    = new HbmList();
            var mapper = new ListMapper(typeof(Animal), typeof(Animal), hbm);

            mapper.Fetch(CollectionFetchMode.Subselect);
            hbm.fetch.Should().Be(HbmCollectionFetchMode.Subselect);
            hbm.fetchSpecified.Should().Be.True();
            mapper.Fetch(CollectionFetchMode.Join);
            hbm.fetch.Should().Be(HbmCollectionFetchMode.Join);
            hbm.fetchSpecified.Should().Be.True();
            mapper.Fetch(CollectionFetchMode.Select);
            hbm.fetch.Should().Be(HbmCollectionFetchMode.Select);
            hbm.fetchSpecified.Should().Be.False();
        }
Пример #30
0
 public ListMapper(System.Type ownerType, System.Type elementType, HbmList mapping)
     : this(ownerType, elementType, new AccessorPropertyMapper(ownerType, mapping.Name, x => mapping.access = x), mapping)
 {
 }