public ListMapper(Type ownerType, Type elementType, 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 = new AccessorPropertyMapper(ownerType, mapping.Name, x => mapping.access = x);
        }
 public void WhenAssignReferenceToNullThenNullifyReference()
 {
     var hbm = new HbmKey();
     var km = new KeyMapper(typeof(Animal), hbm);
     km.PropertyRef(null);
     hbm.propertyref.Should().Be.Null();
 }
 public void WhenExplicitAssignementThenOverrideDefaultColumnName()
 {
     var hbm = new HbmKey();
     var km = new KeyMapper(typeof(Animal), hbm);
     km.Column("blha");
     hbm.Columns.First().name.Should().Be.EqualTo("blha");
 }
 public void AutoAssignColumnNameByDefault()
 {
     var hbm = new HbmKey();
     var km = new KeyMapper(typeof (Animal), hbm);
     hbm.Columns.Should().Have.Count.EqualTo(1);
     hbm.Columns.First().name.Should().Not.Be.Empty().And.Not.Be.Null();
 }
        public void AssignPropertyReference()
        {
            var hbm = new HbmKey();
            var km = new KeyMapper(typeof(Animal), hbm);

            km.PropertyRef(ForClass<Animal>.Property(x=> x.Name));
            hbm.propertyref.Should().Be("Name");
        }
 public void AssignOnDeleteAction()
 {
     var hbm = new HbmKey();
     var km = new KeyMapper(typeof(Animal), hbm);
     km.OnDelete(OnDeleteAction.Cascade);
     hbm.ondelete.Should().Be.EqualTo(HbmOndelete.Cascade);
     km.OnDelete(OnDeleteAction.NoAction);
     hbm.ondelete.Should().Be.EqualTo(HbmOndelete.Noaction);
 }
 public JoinedSubclassMapper(Type subClass, HbmMapping mapDoc)
     : base(subClass, mapDoc)
 {
     var toAdd = new[] { classMapping };
     classMapping.name = subClass.GetShortClassName(mapDoc);
     classMapping.extends = subClass.BaseType.GetShortClassName(mapDoc);
     if (classMapping.key == null)
     {
         classMapping.key = new HbmKey { column1 = subClass.BaseType.Name.ToLowerInvariant() + "_key" };
     }
     keyMapper = new KeyMapper(subClass, classMapping.key);
     mapDoc.Items = mapDoc.Items == null ? toAdd : mapDoc.Items.Concat(toAdd).ToArray();
 }
        public void AssignUpdate()
        {
            var hbm = new HbmKey();
            var km = new KeyMapper(typeof(Animal), hbm);

            km.Update(false);
            hbm.update.Should().Be.False();
            hbm.updateSpecified.Should().Be.True();

            km.Update(true);
            hbm.update.Should().Be.True();
            hbm.updateSpecified.Should().Be.True();
        }
Esempio n. 9
0
        public JoinedSubclassMapper(Type subClass, HbmMapping mapDoc) : base(subClass, mapDoc)
        {
            var toAdd = new[] { classMapping };

            classMapping.name    = subClass.GetShortClassName(mapDoc);
            classMapping.extends = subClass.BaseType.GetShortClassName(mapDoc);
            if (classMapping.key == null)
            {
                classMapping.key = new HbmKey {
                    column1 = subClass.BaseType.Name.ToLowerInvariant() + "_key"
                };
            }
            keyMapper    = new KeyMapper(subClass, classMapping.key);
            mapDoc.Items = mapDoc.Items == null ? toAdd : mapDoc.Items.Concat(toAdd).ToArray();
        }
        public MapMapper(Type ownerType, Type keyType, Type valueType, HbmMap mapping, HbmMapping mapDoc)
        {
            if (ownerType == null)
            {
                throw new ArgumentNullException("ownerType");
            }
            if (keyType == null)
            {
                throw new ArgumentNullException("keyType");
            }
            if (valueType == null)
            {
                throw new ArgumentNullException("valueType");
            }
            if (mapping == null)
            {
                throw new ArgumentNullException("mapping");
            }
            OwnerType    = ownerType;
            KeyType      = keyType;
            ValueType    = valueType;
            this.mapping = mapping;
            this.mapDoc  = mapDoc;
            if (mapping.Key == null)
            {
                mapping.key = new HbmKey();
            }
            keyMapper = new KeyMapper(ownerType, mapping.Key);

            if (KeyType.IsValueType || KeyType == typeof(string))
            {
                mapping.Item = new HbmMapKey {
                    type = KeyType.GetNhTypeName()
                };
            }
            else
            {
                mapping.Item = new HbmMapKeyManyToMany {
                    @class = KeyType.GetShortClassName(mapDoc)
                };
            }
            entityPropertyMapper = new AccessorPropertyMapper(ownerType, mapping.Name, x => mapping.access = x);
        }
		public BagMapper(Type ownerType, Type elementType, HbmBag 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);
			entityPropertyMapper = new AccessorPropertyMapper(ownerType, mapping.Name, x => mapping.access = x);
		}
 public void WhenAssignReferenceOutSideTheOwnerEntityThenThrow()
 {
     var hbm = new HbmKey();
     var km = new KeyMapper(typeof(Animal), hbm);
     ActionAssert.Throws<ArgumentOutOfRangeException>(() => km.PropertyRef(ForClass<B>.Property(x => x.Name)));
 }