public void SetCollectionTypeByGenericType()
 {
     var hbm = new HbmBag();
     var mapper = new BagMapper(typeof(Animal), typeof(Animal), hbm);
     mapper.Type<FakeUserCollectionType>();
     hbm.CollectionType.Should().Contain("FakeUserCollectionType");
 }
 public void SetBatchSize()
 {
     var hbm = new HbmBag();
     var mapper = new BagMapper(typeof(Animal), typeof(Animal), hbm);
     mapper.BatchSize(10);
     hbm.BatchSize.Should().Be.EqualTo(10);
 }
		public virtual void Bag(MemberInfo property, Action<IBagPropertiesMapper> collectionMapping, Action<ICollectionElementRelation> mapping)
		{
			var hbm = new HbmBag {name = property.Name};
			System.Type collectionElementType = property.DetermineRequiredCollectionElementType();
			collectionMapping(new BagMapper(container, collectionElementType, hbm));
			mapping(new CollectionElementRelation(collectionElementType, MapDoc, rel => hbm.Item = rel));
			AddProperty(hbm);
		}
Ejemplo n.º 4
0
		private Mapping.Collection CreateBag(HbmBag bagMapping, string prefix, string path,
			PersistentClass owner, System.Type containingType, IDictionary<string, MetaAttribute> inheritedMetas)
		{
			var bag = new Bag(owner);
			BindCollection(bagMapping, bag, prefix, path, containingType, inheritedMetas);
			AddCollectionSecondPass(bagMapping, bag, inheritedMetas);
			return bag;
		}
        public void CanChangeAccessor()
        {
            var hbm = new HbmBag {name = "Children"};
            var mapper = new BagMapper(typeof(Animal), typeof(Animal), hbm);
            mapper.Access(Accessor.Field);

            hbm.Access.Should().Not.Be.Null();
        }
        public void CanSetCache()
        {
            var hbm = new HbmBag { name = "Children" };
            var mapper = new BagMapper(typeof(Animal), typeof(Animal), hbm);
            mapper.Cache(x=> x.Region("pizza"));

            hbm.cache.Should().Not.Be.Null();
        }
 public void CanSetAFilterThroughAction()
 {
     var hbm = new HbmBag { name = "Children" };
     var mapper = new BagMapper(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 Should_get_null_given_key_is_null()
 {
     HbmBag bag = new HbmBag
         {
             key = null
         };
     bool? result = bag.IsUnique();
     result.ShouldBeNull();
 }
 public void CallKeyMapper()
 {
     var hbm = new HbmBag();
     var mapper = new BagMapper(typeof(Animal), typeof(Animal), hbm);
     bool kmCalled = false;
     mapper.Key(km => kmCalled = true);
     hbm.Key.Should().Not.Be.Null();
     kmCalled.Should().Be.True();
 }
Ejemplo n.º 10
0
 public void Should_get__true__given_inverse_is_true()
 {
     HbmBag bag = new HbmBag
         {
             inverse = true
         };
     bool? result = bag.CanBeNull();
     result.ShouldNotBeNull();
     result.Value.ShouldBeTrue();
 }
Ejemplo n.º 11
0
 public void Should_get_null_given_key_uniqueSpecified_is_false()
 {
     HbmBag bag = new HbmBag
         {
             key = new HbmKey
                 {
                     uniqueSpecified = false,
                     unique = true
                 }
         };
     bool? result = bag.IsUnique();
     result.ShouldBeNull();
 }
Ejemplo n.º 12
0
 public void Should_get__false__given_key_uniqueSpecified_is_true_and_unique_is_false()
 {
     HbmBag bag = new HbmBag
         {
             key = new HbmKey
                 {
                     uniqueSpecified = true,
                     unique = false
                 }
         };
     bool? result = bag.IsUnique();
     result.ShouldNotBeNull();
     result.Value.ShouldBeFalse();
 }
Ejemplo n.º 13
0
 public void Should_get_the_correct_value()
 {
     const string expected = "System.String";
     HbmBag bag = new HbmBag
         {
             Item = new HbmOneToMany
                 {
                     @class = expected + ", mscorlib"
                 }
         };
     string result = bag.GetReturnType();
     result.ShouldBeEqualTo(expected);
 }
 public void WhenSameNameThenOverrideCondition()
 {
     var hbm = new HbmBag { name = "Children" };
     var mapper = new BagMapper(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 HbmBag { name = "Children" };
            var mapper = new BagMapper(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);
        }
 public void WhenActionIsNullThenAddFilterName()
 {
     var hbm = new HbmBag { name = "Children" };
     var mapper = new BagMapper(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 SetWhere()
 {
     var hbm = new HbmBag();
     var mapper = new BagMapper(typeof(Animal), typeof(Animal), hbm);
     mapper.Where("c > 10");
     hbm.Where.Should().Be.EqualTo("c > 10");
 }
		public void Bag(MemberInfo property, Action<IBagPropertiesMapper> collectionMapping, Action<ICollectionElementRelation> mapping)
		{
			var hbm = new HbmBag { name = property.Name };
			System.Type propertyType = property.GetPropertyOrFieldType();
			System.Type collectionElementType = propertyType.DetermineCollectionElementType();
			collectionMapping(new BagMapper(Container, collectionElementType, new NoMemberPropertyMapper(), hbm));
			mapping(new CollectionElementRelation(collectionElementType, MapDoc, rel => hbm.Item = rel));
			AddProperty(hbm);
		}
 public void SetCollectionTypeByWrongTypeShouldThrow()
 {
     var hbm = new HbmBag();
     var mapper = new BagMapper(typeof(Animal), typeof(Animal), hbm);
     ActionAssert.Throws<ArgumentNullException>(() => mapper.Type(null));
     ActionAssert.Throws<ArgumentOutOfRangeException>(() => mapper.Type(typeof(object)));
 }
 public void SetFetchMode()
 {
     var hbm = new HbmBag();
     var mapper = new BagMapper(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 SetLazy()
 {
     var hbm = new HbmBag();
     var mapper = new BagMapper(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);
 }
Ejemplo n.º 22
0
 public void Should_get_the_correct_value()
 {
     const string expected = "FirstName";
     HbmBag bag = new HbmBag
         {
             name = expected
         };
     string result = bag.GetPropertyName();
     result.ShouldBeEqualTo(expected);
 }
 public void SetMutable()
 {
     var hbm = new HbmBag();
     var mapper = new BagMapper(typeof(Animal), typeof(Animal), hbm);
     mapper.Mutable(true);
     hbm.Mutable.Should().Be.True();
     mapper.Mutable(false);
     hbm.Mutable.Should().Be.False();
 }
Ejemplo n.º 24
0
 public void Should_get_the_correct_value_from_key()
 {
     const string expected = "FirstName";
     HbmBag bag = new HbmBag
         {
             key = new HbmKey
                 {
                     column1 = expected
                 }
         };
     string result = bag.GetColumnName();
     result.ShouldBeEqualTo(expected);
 }