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);
 }
        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 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");
 }
 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");
 }
        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();
        }
		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;
		}
		public virtual 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, hbm));
			mapping(new CollectionElementRelation(collectionElementType, MapDoc, rel => hbm.Item1 = rel));
			AddProperty(hbm);
		}
 public void CallKeyMapper()
 {
     var hbm = new HbmList();
     var mapper = new ListMapper(typeof(Animal), typeof(Animal), hbm);
     bool kmCalled = false;
     mapper.Key(km => kmCalled = true);
     hbm.Key.Should().Not.Be.Null();
     kmCalled.Should().Be.True();
 }
		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);
				});
		}
		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 (NeedBackref(model))
			{
				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);
			}
		}
 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();
 }
 public void SetCollectionTypeByGenericType()
 {
     var hbm = new HbmList();
     var mapper = new ListMapper(typeof(Animal), typeof(Animal), hbm);
     mapper.Type<FakeUserCollectionType>();
     hbm.CollectionType.Should().Contain("FakeUserCollectionType");
 }
 public void SetListIndex()
 {
     var hbm = new HbmList();
     new ListMapper(typeof(Animal), typeof(Animal), hbm);
     hbm.Item.Should().Not.Be.Null().And.Be.OfType<HbmListIndex>();
 }
 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);
 }
 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();
 }
 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");
 }
		public 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, new NoMemberPropertyMapper(), hbm));
			mapping(new CollectionElementRelation(collectionElementType, MapDoc, rel => hbm.Item1 = rel));
			AddProperty(hbm);
		}
 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);
 }
 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 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);
        }
Example #21
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);
			}
		}