Exemple #1
0
        public void WhenCreatedHasId()
        {
            var hbm = new HbmIdbag();

            new IdBagMapper(typeof(Animal), typeof(Animal), hbm);
            Assert.That(hbm.collectionid, Is.Not.Null);
        }
 public IdBagMapper(System.Type ownerType, System.Type elementType, IAccessorPropertyMapper accessorMapper, HbmIdbag 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);
     if (mapping.collectionid == null)
     {
         mapping.collectionid = new HbmCollectionId();
     }
     idMapper             = new CollectionIdMapper(mapping.collectionid);
     entityPropertyMapper = accessorMapper;
 }
Exemple #3
0
        public void WhenCreatedHasId()
        {
            var hbm = new HbmIdbag();

            new IdBagMapper(typeof(Animal), typeof(Animal), hbm);
            hbm.collectionid.Should().Not.Be.Null();
        }
Exemple #4
0
        public void SetCollectionTypeByType()
        {
            var hbm    = new HbmIdbag();
            var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm);

            mapper.Type(typeof(FakeUserCollectionType));
            Assert.That(hbm.CollectionType, Is.StringContaining("FakeUserCollectionType"));
        }
Exemple #5
0
        public void SetWhere()
        {
            var hbm    = new HbmIdbag();
            var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm);

            mapper.Where("c > 10");
            Assert.That(hbm.Where, Is.EqualTo("c > 10"));
        }
Exemple #6
0
        public void SetCollectionTypeByType()
        {
            var hbm    = new HbmIdbag();
            var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm);

            mapper.Type(typeof(FakeUserCollectionType));
            hbm.CollectionType.Should().Contain("FakeUserCollectionType");
        }
Exemple #7
0
        public void SetCollectionTypeByWrongTypeShouldThrow()
        {
            var hbm    = new HbmIdbag();
            var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm);

            Assert.That(() => mapper.Type(null), Throws.TypeOf <ArgumentNullException>());
            Assert.That(() => mapper.Type(typeof(object)), Throws.TypeOf <ArgumentOutOfRangeException>());
        }
Exemple #8
0
        public void SetBatchSize()
        {
            var hbm    = new HbmIdbag();
            var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm);

            mapper.BatchSize(10);
            Assert.That(hbm.BatchSize, Is.EqualTo(10));
        }
Exemple #9
0
        public void SetCollectionTypeByWrongTypeShouldThrow()
        {
            var hbm    = new HbmIdbag();
            var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm);

            Executing.This(() => mapper.Type(null)).Should().Throw <ArgumentNullException>();
            Executing.This(() => mapper.Type(typeof(object))).Should().Throw <ArgumentOutOfRangeException>();
        }
Exemple #10
0
        public void SetCollectionTypeByGenericType()
        {
            var hbm    = new HbmIdbag();
            var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm);

            mapper.Type <FakeUserCollectionType>();
            Assert.That(hbm.CollectionType, Does.Contain("FakeUserCollectionType"));
        }
Exemple #11
0
        public void SetBatchSize()
        {
            var hbm    = new HbmIdbag();
            var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm);

            mapper.BatchSize(10);
            hbm.BatchSize.Should().Be.EqualTo(10);
        }
Exemple #12
0
        public void SetWhere()
        {
            var hbm    = new HbmIdbag();
            var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm);

            mapper.Where("c > 10");
            hbm.Where.Should().Be.EqualTo("c > 10");
        }
Exemple #13
0
        public void WhenConfigureIdThenCallMapper()
        {
            var hbm    = new HbmIdbag();
            var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm);

            mapper.Id(x => x.Column("catchMe"));

            Assert.That(hbm.collectionid.Columns.Single().name, Is.EqualTo("catchMe"));
        }
Exemple #14
0
        private Mapping.Collection CreateIdentifierBag(HbmIdbag idbagMapping, string prefix, string path,
                                                       PersistentClass owner, System.Type containingType, IDictionary <string, MetaAttribute> inheritedMetas)
        {
            var idbag = new IdentifierBag(owner);

            BindCollection(idbagMapping, idbag, prefix, path, containingType, inheritedMetas);
            AddIdentifierCollectionSecondPass(idbagMapping, idbag, inheritedMetas);
            return(idbag);
        }
Exemple #15
0
 private void AddIdentifierCollectionSecondPass(HbmIdbag idbagMapping, IdentifierCollection model, IDictionary <string, MetaAttribute> inheritedMetas)
 {
     mappings.AddSecondPass(delegate(IDictionary <string, PersistentClass> persistentClasses)
     {
         PreCollectionSecondPass(model);
         BindIdentifierCollectionSecondPass(idbagMapping, model, persistentClasses, inheritedMetas);
         PostCollectionSecondPass(model);
     });
 }
Exemple #16
0
        public void WhenConfigureIdThenCallMapper()
        {
            var hbm    = new HbmIdbag();
            var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm);

            mapper.Id(x => x.Column("catchMe"));

            hbm.collectionid.Columns.Single().name.Should().Be("catchMe");
        }
Exemple #17
0
        public void SetMutable()
        {
            var hbm    = new HbmIdbag();
            var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm);

            mapper.Mutable(true);
            hbm.Mutable.Should().Be.True();
            mapper.Mutable(false);
            hbm.Mutable.Should().Be.False();
        }
Exemple #18
0
        public void CallKeyMapper()
        {
            var  hbm      = new HbmIdbag();
            var  mapper   = new IdBagMapper(typeof(Animal), typeof(Animal), hbm);
            bool kmCalled = false;

            mapper.Key(km => kmCalled = true);
            Assert.That(hbm.Key, Is.Not.Null);
            Assert.That(kmCalled, Is.True);
        }
Exemple #19
0
        public void CallKeyMapper()
        {
            var  hbm      = new HbmIdbag();
            var  mapper   = new IdBagMapper(typeof(Animal), typeof(Animal), hbm);
            bool kmCalled = false;

            mapper.Key(km => kmCalled = true);
            hbm.Key.Should().Not.Be.Null();
            kmCalled.Should().Be.True();
        }
Exemple #20
0
        public void SetMutable()
        {
            var hbm    = new HbmIdbag();
            var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm);

            mapper.Mutable(true);
            Assert.That(hbm.Mutable, Is.True);
            mapper.Mutable(false);
            Assert.That(hbm.Mutable, Is.False);
        }
        public void IdBag(MemberInfo property, Action <IIdBagPropertiesMapper> collectionMapping, Action <ICollectionElementRelation> mapping)
        {
            var hbm = new HbmIdbag {
                name = property.Name
            };

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

            mapper.Access(Accessor.Field);

            hbm.Access.Should().Not.Be.Null();
        }
Exemple #23
0
        public void CanSetCache()
        {
            var hbm = new HbmIdbag {
                name = "Children"
            };
            var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm);

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

            hbm.cache.Should().Not.Be.Null();
        }
Exemple #24
0
        public void CanSetAFilterThroughAction()
        {
            var hbm = new HbmIdbag {
                name = "Children"
            };
            var mapper = new IdBagMapper(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");
        }
Exemple #25
0
        public void CanSetCache()
        {
            var hbm = new HbmIdbag {
                name = "Children"
            };
            var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm);

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

            Assert.That(hbm.cache, Is.Not.Null);
        }
Exemple #26
0
        public void CanChangeAccessor()
        {
            var hbm = new HbmIdbag {
                name = "Children"
            };
            var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm);

            mapper.Access(Accessor.Field);

            Assert.That(hbm.Access, Is.Not.Null);
        }
Exemple #27
0
        public void WhenActionIsNullThenAddFilterName()
        {
            var hbm = new HbmIdbag {
                name = "Children"
            };
            var mapper = new IdBagMapper(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);
        }
Exemple #28
0
        public void WhenConfigureIdMoreThanOnceThenUseSameMapper()
        {
            var hbm    = new HbmIdbag();
            var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm);
            ICollectionIdMapper firstInstance  = null;
            ICollectionIdMapper secondInstance = null;

            mapper.Id(x => firstInstance  = x);
            mapper.Id(x => secondInstance = x);

            Assert.That(firstInstance, Is.SameAs(secondInstance));
        }
Exemple #29
0
        public void CanSetAFilterThroughAction()
        {
            var hbm = new HbmIdbag {
                name = "Children"
            };
            var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm);

            mapper.Filter("filter1", f => f.Condition("condition1"));
            Assert.That(hbm.filter.Length, Is.EqualTo(1));
            Assert.That(hbm.filter[0].condition, Is.EqualTo("condition1"));
            Assert.That(hbm.filter[0].name, Is.EqualTo("filter1"));
        }
Exemple #30
0
        public void SetLazy()
        {
            var hbm    = new HbmIdbag();
            var mapper = new IdBagMapper(typeof(Animal), typeof(Animal), hbm);

            mapper.Lazy(CollectionLazy.Extra);
            Assert.That(hbm.Lazy, Is.EqualTo(HbmCollectionLazy.Extra));
            mapper.Lazy(CollectionLazy.NoLazy);
            Assert.That(hbm.Lazy, Is.EqualTo(HbmCollectionLazy.False));
            mapper.Lazy(CollectionLazy.Lazy);
            Assert.That(hbm.Lazy, Is.EqualTo(HbmCollectionLazy.True));
        }