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);
 }
		private void BindKey(JoinedSubclass subclass, HbmKey keyMapping, Table mytable)
		{
			// TODO : property-ref ?? 
			SimpleValue key = new DependantValue(mytable, subclass.Identifier);
			subclass.Key = key;
			key.IsCascadeDeleteEnabled = keyMapping.ondelete == HbmOndelete.Cascade;
			key.ForeignKeyName = keyMapping.foreignkey;

			new ValuePropertyBinder(key, Mappings).BindSimpleValue(keyMapping, subclass.EntityName, false);
		}
		public void BindSimpleValue(HbmKey propertyMapping, string propertyPath, bool isNullable)
		{
			new ColumnsBinder(value, Mappings).Bind(propertyMapping.Columns, isNullable,
			                                        () =>
			                                        new HbmColumn
			                                        	{
			                                        		name = mappings.NamingStrategy.PropertyToColumnName(propertyPath),
			                                        		notnull = propertyMapping.notnull,
			                                        		notnullSpecified = propertyMapping.notnullSpecified,
			                                        		unique = propertyMapping.unique,
			                                        		uniqueSpecified = propertyMapping.uniqueSpecified,
			                                        	});
		}
        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();
        }
		private void BindKey(HbmKey keyMapping, Mapping.Collection model)
		{
			if (keyMapping == null)
			{
				return;
			}
			string propRef = model.ReferencedPropertyName;
			IKeyValue keyValue;
			if (propRef == null)
			{
				keyValue = model.Owner.Identifier;
			}
			else
			{
				keyValue = (IKeyValue) model.Owner.GetProperty(propRef).Value;
			}
			var key = new DependantValue(model.CollectionTable, keyValue)
						{IsCascadeDeleteEnabled = keyMapping.ondelete == HbmOndelete.Cascade};

			new ValuePropertyBinder(key, Mappings).BindSimpleValue(keyMapping, Mapping.Collection.DefaultKeyColumnName, model.IsOneToMany);

			if (key.Type.ReturnedClass.IsArray)
				throw new MappingException("illegal use of an array as an identifier (arrays don't reimplement Equals)");
			model.Key = key;

			key.SetNullable(!keyMapping.IsNullable.HasValue || keyMapping.IsNullable.Value);
			key.SetUpdateable(!keyMapping.IsUpdatable.HasValue || keyMapping.IsUpdatable.Value);
			BindForeignKey(keyMapping.foreignkey, key);
		}
Esempio n. 10
0
		public KeyMapper(Type ownerEntityType, HbmKey mapping)
		{
			this.ownerEntityType = ownerEntityType;
			this.mapping = mapping;
			this.mapping.column1 = DefaultColumnName(ownerEntityType);
		}
 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)));
 }