public void AfterSetMultiColumnsCantSetSimpleColumn()
 {
     var mapping = new HbmElement();
     var mapper = new ElementMapper(typeof(string), mapping);
     mapper.Columns(cm => cm.Length(50), cm => cm.SqlType("VARCHAR(10)"));
     ActionAssert.Throws<ConfOrm.MappingException>(() => mapper.Column(cm => cm.Length(50)));
 }
 public void WhenCreatedWithEnumThenNoAutoAssignType()
 {
     // Note: the responsibility of the type name is delegated to NHibernate: NHibernateUtil.Enum(typeClass)
     var elementMapping = new HbmElement();
     new ElementMapper(typeof(MyEnum), elementMapping);
     elementMapping.type1.Should().Not.Be.Empty();
 }
		public void BindSimpleValue(HbmElement element, string propertyPath, bool isNullable)
		{
			new TypeBinder(value, Mappings).Bind(element.Type);
			var formulas = element.Formulas.ToArray();
			if (formulas.Length > 0)
			{
				BindFormulas(formulas);
			}
			else
			{
				new ColumnsBinder(value, Mappings).Bind(element.Columns, isNullable,
																								() =>
																								new HbmColumn
																								{
																									name = mappings.NamingStrategy.PropertyToColumnName(propertyPath),
																									length = element.length,
																									scale = element.scale,
																									precision = element.precision,
																									notnull = element.notnull,
																									notnullSpecified = true,
																									unique = element.unique,
																									uniqueSpecified = true,
																								});
			}
		}
        public void CanSetFormula()
        {
            var mapping = new HbmElement();
            var mapper = new ElementMapper(typeof(string), mapping);

            mapper.Formula("SomeFormula");
            mapping.formula.Should().Be("SomeFormula");
        }
 public void SettingColumnOverridesFormula()
 {
     var mapping = new HbmElement();
     var mapper = new ElementMapper(typeof(string), mapping);
     mapper.Formula("formula");
     mapper.Column(cm => cm.Unique(true));
     mapping.formula.Should().Be.Null();
 }
 public void SettingColumnPlainValuesOverridesFormula()
 {
     var mapping = new HbmElement();
     var mapper = new ElementMapper(typeof(string), mapping);
     mapper.Formula("formula");
     mapper.Column("colName");
     mapping.formula.Should().Be.Null();
     mapping.column.Should().Be("colName");
 }
 public void SettingFormulaOverridesColumnNodes()
 {
     var mapping = new HbmElement();
     var mapper = new ElementMapper(typeof(string), mapping);
     mapper.Column(cm => cm.SqlType("VARCHAR(80)"));
     mapper.Formula("formula");
     mapping.formula.Should().Be("formula");
     mapping.column.Should().Be(null);
     mapping.Items.Should().Be.Null();
 }
        public void WhenSetBasicColumnValuesMoreThanOnesThenMergeColumn()
        {
            var mapping = new HbmElement();
            var mapper = new ElementMapper(typeof(string), mapping);
            mapper.Column(cm => cm.Length(50));
            mapper.Column(cm => cm.NotNullable(true));

            mapping.Items.Should().Be.Null();
            mapping.length.Should().Be("50");
            mapping.notnull.Should().Be(true);
        }
 public void SettingFormulaOverridesColumnPlainValues()
 {
     var mapping = new HbmElement();
     var mapper = new ElementMapper(typeof(string), mapping);
     mapper.Column("colName");
     mapper.Length(10);
     mapper.NotNullable(true);
     mapper.Formula("formula");
     mapping.formula.Should().Be("formula");
     mapping.column.Should().Be(null);
     mapping.length.Should().Be(null);
     mapping.notnull.Should().Be(false);
     mapping.Items.Should().Be.Null();
 }
Пример #10
0
		private void BindElement(HbmElement elementMapping, Mapping.Collection model)
		{
			var element = new SimpleValue(model.CollectionTable);
			model.Element = element;
			if (model.IsGeneric)
			{
				switch (model.GenericArguments.Length)
				{
					case 1:
						// a collection with a generic type parameter
						element.TypeName = model.GenericArguments[0].AssemblyQualifiedName;
						break;
					case 2:
						// a map (IDictionary) with 2 parameters
						element.TypeName = model.GenericArguments[1].AssemblyQualifiedName;
						break;
				}
			}
			new ValuePropertyBinder(element, Mappings).BindSimpleValue(elementMapping, Mapping.Collection.DefaultKeyColumnName, true);
		}
        public void WhenSetTypeByNotFormalITypeThenSetTypeFullName()
        {
            var mapping = new HbmElement();
            var mapper = new ElementMapper(typeof(string), mapping);
            mapper.Type<EnumStringType<MyEnum>>();

            mapping.Type.name.Should().Contain(typeof(EnumStringType<MyEnum>).FullName);
        }
        public void WhenSetTypeByIUserTypeWithParamsThenSetType()
        {
            var mapping = new HbmElement();
            var mapper = new ElementMapper(typeof(string), mapping);
            mapper.Type<MyType>(new { Param1 = "a", Param2 = 12 });

            mapping.type1.Should().Be.Null();
            mapping.Type.name.Should().Contain("MyType");
            mapping.Type.param.Should().Have.Count.EqualTo(2);
            mapping.Type.param.Select(p => p.name).Should().Have.SameValuesAs("Param1", "Param2");
            mapping.Type.param.Select(p => p.GetText()).Should().Have.SameValuesAs("a", "12");
        }
        public void WhenSetTypeByIUserTypeWithNullParamsThenSetTypeName()
        {
            var mapping = new HbmElement();
            var mapper = new ElementMapper(typeof(string), mapping);
            mapper.Type<MyType>(null);

            mapping.Type.name.Should().Contain("MyType");
            mapping.type.Should().Be.Null();
        }
        public void WhenSetTypeByITypeThenSetTypeName()
        {
            var mapping = new HbmElement();
            var mapper = new ElementMapper(typeof(string), mapping);
            mapper.Type(NHibernateUtil.Int64);

            mapping.Type.name.Should().Be.EqualTo("Int64");
        }
 public void WhenSetMultiColumnsValuesThenAutoassignColumnNames()
 {
     var mapping = new HbmElement();
     var mapper = new ElementMapper(typeof(string), mapping);
     mapper.Columns(cm => cm.Length(50), cm => cm.SqlType("VARCHAR(10)"));
     mapping.Columns.Should().Have.Count.EqualTo(2);
     mapping.Columns.All(cm => cm.name.Satisfy(n => !string.IsNullOrEmpty(n)));
 }
 public void WhenSetMultiColumnsValuesThenAddColumns()
 {
     var mapping = new HbmElement();
     var mapper = new ElementMapper(typeof(string), mapping);
     mapper.Type<MyType>();
     mapper.Columns(cm =>
     {
         cm.Name("column1");
         cm.Length(50);
     }, cm =>
     {
         cm.Name("column2");
         cm.SqlType("VARCHAR(10)");
     });
     mapping.Columns.Should().Have.Count.EqualTo(2);
 }
 public void WhenSetInvalidTypeThenThrow()
 {
     var mapping = new HbmElement();
     var mapper = new ElementMapper(typeof(string), mapping);
     ActionAssert.Throws<ArgumentOutOfRangeException>(() => mapper.Type(typeof(object), null));
     ActionAssert.Throws<ArgumentNullException>(() => mapper.Type(null, null));
 }
 public void WhenSetFormulaThenResetColumn()
 {
     var mapping = new HbmElement();
     var mapper = new ElementMapper(typeof(string), mapping);
     mapper.Column("MyColumn");
     mapper.Formula("SomeFormula");
     mapping.formula.Should().Be("SomeFormula");
     mapping.column.Should().Be.Null();
     mapping.Items.Should().Be.Null();
 }
 public void WhenCreatedThenAutoAssignType()
 {
     var elementMapping = new HbmElement();
     var mapper = new ElementMapper(typeof(string), elementMapping);
     elementMapping.type1.Should().Be("String");
 }
		public void Element(Action<IElementMapper> mapping)
		{
			var hbm = new HbmElement();
			mapping(new ElementMapper(collectionElementType, hbm));
			elementRelationshipAssing(hbm);
		}
 public void WhenSetFormulaWithMultipleLinesThenSetFormulaNode()
 {
     var mapping = new HbmElement();
     var mapper = new ElementMapper(typeof(string), mapping);
     var formula = @"Line1
     Line2";
     mapper.Formula(formula);
     mapping.formula.Should().Be.Null();
     mapping.Items.FirstOrDefault().Should().Not.Be.Null().And.Be.OfType<HbmFormula>();
     var hbmFormula = (HbmFormula)(mapping.Items.First());
     hbmFormula.Text.Length.Should().Be(2);
     hbmFormula.Text[0].Should().Be("Line1");
     hbmFormula.Text[1].Should().Be("Line2");
 }
        public void WhenSetColumnNameThenSetTheName()
        {
            var mapping = new HbmElement();
            var mapper = new ElementMapper(typeof(string), mapping);
            mapper.Column(cm => cm.Name("pepe"));

            mapping.Columns.Should().Have.Count.EqualTo(1);
            mapping.Columns.Single().name.Should().Be("pepe");
        }
 public void WhenSetColumnValuesThenAddColumnTag()
 {
     var mapping = new HbmElement();
     var mapper = new ElementMapper(typeof(string), mapping);
     mapper.Column(cm =>
     {
         cm.SqlType("VARCHAR(50)");
         cm.NotNullable(true);
     });
     mapping.Items.Should().Not.Be.Null();
     mapping.Columns.Should().Have.Count.EqualTo(1);
 }
        public void WhenSetBasicColumnValuesThroughShortCutThenMergeColumn()
        {
            var mapping = new HbmElement();
            var mapper = new ElementMapper(typeof(string), mapping);
            mapper.Column("pizza");
            mapper.Length(50);
            mapper.Precision(10);
            mapper.Scale(2);
            mapper.NotNullable(true);
            mapper.Unique(true);

            mapping.Items.Should().Be.Null();
            mapping.column.Should().Be("pizza");
            mapping.length.Should().Be("50");
            mapping.precision.Should().Be("10");
            mapping.scale.Should().Be("2");
            mapping.notnull.Should().Be(true);
            mapping.unique.Should().Be(true);
        }
 public void WhenSetFormulaWithNullThenDoNothing()
 {
     var mapping = new HbmElement();
     var mapper = new ElementMapper(typeof(string), mapping);
     mapper.Column("MyColumn");
     mapper.Formula(null);
     mapping.formula.Should().Be.Null();
     mapping.column.Should().Not.Be.Null();
 }