public void CanSetUnsavedValue()
 {
     var hbmId = new HbmId();
     var mapper = new IdMapper(null, hbmId);
     mapper.UnsavedValue(-1);
     hbmId.unsavedvalue.Should().Be("-1");
 }
 public void CanSetColumnName()
 {
     var hbmId = new HbmId();
     var mapper = new IdMapper(null, hbmId);
     mapper.Column("MyName");
     hbmId.Columns.Single().name.Should().Be("MyName");
 }
Esempio n. 3
0
		private void CreateIdentifierProperty(HbmId idSchema, PersistentClass rootClass, SimpleValue id)
		{
			if (idSchema.name != null)
			{
				string access = idSchema.access ?? mappings.DefaultAccess;
				id.SetTypeUsingReflection(rootClass.MappedClass.AssemblyQualifiedName, idSchema.name, access);

				Mapping.Property property = new Mapping.Property(id);
				property.Name = idSchema.name;

				if (property.Value.Type == null)
					throw new MappingException("could not determine a property type for: " + property.Name);

				property.PropertyAccessorName = idSchema.access ?? mappings.DefaultAccess;
				property.Cascade = mappings.DefaultCascade;
				property.IsUpdateable = true;
				property.IsInsertable = true;
				property.IsOptimisticLocked = true;
				property.Generation = PropertyGeneration.Never;
				property.MetaAttributes = GetMetas(idSchema);

				rootClass.IdentifierProperty = property;

				LogMappedProperty(property);
			}
		}
Esempio n. 4
0
		public void BindId(HbmId idSchema, PersistentClass rootClass, Table table)
		{
			if (idSchema != null)
			{
				var id = new SimpleValue(table);
				new TypeBinder(id, Mappings).Bind(idSchema.Type);

				rootClass.Identifier = id;

				Func<HbmColumn> defaultColumn = () => new HbmColumn
				{
					name = idSchema.name ?? RootClass.DefaultIdentifierColumnName,
					length = idSchema.length
				};

				new ColumnsBinder(id, Mappings).Bind(idSchema.Columns, false, defaultColumn);

				CreateIdentifierProperty(idSchema, rootClass, id);
				VerifiyIdTypeIsValid(id.Type, rootClass.EntityName);

				new IdGeneratorBinder(Mappings).BindGenerator(id, GetIdGenerator(idSchema));

				id.Table.SetIdentifierValue(id);

				BindUnsavedValue(idSchema, id);
			}
		}
Esempio n. 5
0
		public void CanSetGeneratorForeign()
		{
			var hbmId = new HbmId();
			new IdMapper(hbmId).Generator(Generators.Foreign<MyClass>(mc => mc.OneToOne));
			[email protected]().Be.EqualTo("foreign");
			hbmId.generator.param.Should().Not.Be.Null().And.Have.Count.EqualTo(1);
			hbmId.generator.param.Single().Satisfy(p => p.name == "property" && p.GetText() == "OneToOne");
		}
Esempio n. 6
0
		private static SimpleValue CreateIdentifier(HbmId idSchema, PersistentClass rootClass, Table table)
		{
			SimpleValue iv = new SimpleValue(table);
			iv.TypeName = idSchema.type;
			rootClass.Identifier = iv;

			return iv;
		}
 public void Should_get_null_given_column_is_null()
 {
     HbmId id = new HbmId
         {
             column = null
         };
     bool? result = id.CanBeNull();
     result.ShouldBeNull();
 }
Esempio n. 8
0
		public void CanSetGeneratorWithParameters()
		{
			var hbmId = new HbmId();
			new IdMapper(hbmId).Generator(Generators.HighLow, p => p.Params(new { max_low = 99, where = "TableName" }));
			[email protected]().Be.EqualTo("hilo");
			hbmId.generator.param.Should().Have.Count.EqualTo(2);
			hbmId.generator.param.Select(p => p.name).Should().Have.SameValuesAs("max_low", "where");
			hbmId.generator.param.Select(p => p.GetText()).Should().Have.SameValuesAs("99", "TableName");
		}
Esempio n. 9
0
		public void CanSetGeneratorWithParameters()
		{
			var hbmId = new HbmId();
			new IdMapper(hbmId).Generator(Generators.HighLow, p => p.Params(new { max_low = 99, where = "TableName" }));
			Assert.That(hbmId.generator.@class, Is.EqualTo("hilo"));
			Assert.That(hbmId.generator.param, Has.Length.EqualTo(2));
			Assert.That(hbmId.generator.param.Select(p => p.name), Is.EquivalentTo(new [] {"max_low", "where"}));
			Assert.That(hbmId.generator.param.Select(p => p.GetText()), Is.EquivalentTo(new [] {"99", "TableName"}));
		}
Esempio n. 10
0
		public void CanSetGeneratorForeign()
		{
			var hbmId = new HbmId();
			new IdMapper(hbmId).Generator(Generators.Foreign<MyClass>(mc => mc.OneToOne));
			Assert.That(hbmId.generator.@class, Is.EqualTo("foreign"));
			Assert.That(hbmId.generator.param, Is.Not.Null.And.Length.EqualTo(1));
			var p = hbmId.generator.param.Single();
			Assert.That(p.GetText(), Is.EqualTo("OneToOne"));
			Assert.That(p.name, Is.EqualTo("property"));
		}
Esempio n. 11
0
		private void AddColumns(HbmId idSchema, SimpleValue id)
		{
			if (idSchema.column1 != null)
				AddColumnFromAttribute(idSchema, id);
			else
				AddColumnsFromList(idSchema, id);

			if (id.ColumnSpan == 0)
				AddDefaultColumn(idSchema, id);
		}
Esempio n. 12
0
        private static void BindUnsavedValue(HbmId idSchema, SimpleValue id)
        {
            if (idSchema.unsavedvalue != null)
                id.NullValue = idSchema.unsavedvalue;

            else if (id.IdentifierGeneratorStrategy == "assigned")
                // TODO: H3 has id.setNullValue("undefined") here, but NH doesn't (yet) allow "undefined"
                // for id unsaved-value, so we use "null" here
                id.NullValue = "null";

            else
                id.NullValue = null;
        }
Esempio n. 13
0
        private static Column CreateColumn(HbmId idSchema)
        {
            Column column = new Column();

            if (idSchema.length != null)
                column.Length = int.Parse(idSchema.length);

            column.IsNullable = false;
            column.IsUnique = false;
            column.CheckConstraint = string.Empty;
            column.SqlType = null;

            return column;
        }
Esempio n. 14
0
        public void BindId(HbmId idSchema, PersistentClass rootClass, Table table)
        {
            if (idSchema != null)
            {
                SimpleValue id = CreateIdentifier(idSchema, rootClass, table);

                AddColumns(idSchema, id);
                CreateIdentifierProperty(idSchema, rootClass, id);
                VerifiyIdTypeIsValid(id, rootClass.MappedClass.Name);
                BindGenerator(idSchema, id);
                id.Table.SetIdentifierValue(id);
                BindUnsavedValue(idSchema, id);
            }
        }
 public void Should_get_null_given_column_notnullSpecified_is_false()
 {
     HbmId id = new HbmId
         {
             column = new[]
                 {
                     new HbmColumn
                         {
                             notnullSpecified = false
                         }
                 }
         };
     bool? result = id.CanBeNull();
     result.ShouldBeNull();
 }
 public IdMapper(MemberInfo member, HbmId hbmId)
 {
     this.hbmId = hbmId;
     if (member != null)
     {
         var idType = member.GetPropertyOrFieldType();
         hbmId.name = member.Name;
         hbmId.type1 = idType.GetNhTypeName();
         accessorMapper = new AccessorPropertyMapper(member.DeclaringType, member.Name, x => hbmId.access = x);
     }
     else
     {
         accessorMapper = new NoMemberPropertyMapper();
     }
 }
 public void Should_get__true__given_column_notnullSpecified_is_true_and_notnull_is_false()
 {
     HbmId id = new HbmId
         {
             column = new[]
                 {
                     new HbmColumn
                         {
                             notnullSpecified = true,
                             notnull = false
                         }
                 }
         };
     bool? result = id.CanBeNull();
     result.ShouldNotBeNull();
     result.Value.ShouldBeTrue();
 }
        public ClassMapper(Type rootClass, HbmMapping mapDoc, MemberInfo idProperty)
            : base(rootClass, mapDoc)
        {
            classMapping = new HbmClass();
            var toAdd = new[] { classMapping };
            classMapping.name = rootClass.GetShortClassName(mapDoc);
            if(rootClass.IsAbstract)
            {
                classMapping.@abstract = true;
                classMapping.abstractSpecified = true;
            }

            var hbmId = new HbmId();
            classMapping.Item = hbmId;
            idMapper = new IdMapper(idProperty, hbmId);

            mapDoc.Items = mapDoc.Items == null ? toAdd : mapDoc.Items.Concat(toAdd).ToArray();
        }
 public void Should_get_the_correct_value_from_column()
 {
     const string expected = "Name";
     HbmId id = new HbmId
         {
             column = new[]
                 {
                     new HbmColumn
                         {
                             index = expected
                         }
                 }
         };
     string result = id.GetUniqueIndex();
     result.ShouldNotBeNull();
     result.ShouldBeEqualTo(expected);
 }
 public void Should_get_null_given_null_index_and_column_index()
 {
     HbmId id = new HbmId
         {
             column = new[] {new HbmColumn()}
         };
     string result = id.GetUniqueIndex();
     result.ShouldBeNull();
 }
Esempio n. 21
0
		public void CanSetGeneratorAssigned()
		{
			var hbmId = new HbmId();
			new IdMapper(hbmId).Generator(Generators.Assigned);
			[email protected]().Be.EqualTo("assigned");
		}
Esempio n. 22
0
		public void CanSetGeneratorSequence()
		{
			var hbmId = new HbmId();
			new IdMapper(hbmId).Generator(Generators.Sequence);
			[email protected]().Be.EqualTo("sequence");
		}
Esempio n. 23
0
		public void CanSetGeneratorIdentity()
		{
			var hbmId = new HbmId();
			new IdMapper(hbmId).Generator(Generators.Identity);
			[email protected]().Be.EqualTo("identity");
		}
Esempio n. 24
0
		public void CanSetGeneratorEnhancedTable()
		{
			var hbmId = new HbmId();
			new IdMapper(hbmId).Generator(Generators.EnhancedTable);
			[email protected]().Be.EqualTo("enhanced-table");
		}
Esempio n. 25
0
		public void CanSetGeneratorGuidComb()
		{
			var hbmId = new HbmId();
			new IdMapper(hbmId).Generator(Generators.GuidComb);
			[email protected]().Be.EqualTo("guid.comb");
		}
Esempio n. 26
0
		public void CanSetGenerator()
		{
			var hbmId = new HbmId();
			new IdMapper(hbmId).Generator(Generators.HighLow);
			[email protected]().Be.EqualTo("hilo");
		}
Esempio n. 27
0
		public void CanSetLength()
		{
			var hbmId = new HbmId();
			var mapper = new IdMapper(null, hbmId);
			mapper.Length(10);
			hbmId.length.Should().Be("10");
		}
Esempio n. 28
0
		public void UnsavedValueUnsetWhenNotSet()
		{
			var hbmId = new HbmId();
			var mapper = new IdMapper(null, hbmId);
			hbmId.unsavedvalue.Should().Be(null);
		}
Esempio n. 29
0
		public void CanSetUnsavedValue(object unsavedValue, string expectedUnsavedValue)
		{
			var hbmId = new HbmId();
			var mapper = new IdMapper(null, hbmId);
			mapper.UnsavedValue(unsavedValue);
			hbmId.unsavedvalue.Should().Be(expectedUnsavedValue);
		}
Esempio n. 30
0
		public void WhenHasMemberCanSetAccessor()
		{
			var member = typeof(Entity).GetProperty("Id",
																							 BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic
																							 | BindingFlags.FlattenHierarchy);
			var hbmId = new HbmId();
			var mapper = new IdMapper(member, hbmId);
			mapper.Access(Accessor.NoSetter);
			hbmId.access.Should().Be("nosetter.camelcase");
		}