Esempio n. 1
0
        public void MapProperty_GivenANonPropertyExpression_ThrowsArgumentException()
        {
            var validatedObject = new Mock<IValidatedObject>();
            var entity = new PropertyMapperTestEntity ();

            var propertyMapper = new PropertyMapper<PropertyMapperTestEntity>(entity, validatedObject.Object);

            propertyMapper.MapProperty ( e => e.SomeMethod(), "SomeString" );
        }
		public void WhenSetTypeByITypeThenSetTypeName()
		{
			var member = typeof(MyClass).GetProperty("ReadOnly");
			var mapping = new HbmProperty();
			var mapper = new PropertyMapper(member, mapping);
			mapper.Type(NHibernateUtil.String);

			mapping.Type.name.Should().Be.EqualTo("String");
		}
		public void WhenCreateWithGivenAccessorMapperThenUseTheGivenAccessoMapper()
		{
			var member = typeof (MyClass).GetProperty("ReadOnly");
			var mapping = new HbmProperty();
			var myAccessorMapper = new MyAccessorMapper();
			var mapper = new PropertyMapper(member, mapping, myAccessorMapper);
			mapper.Access(Accessor.Field);
			myAccessorMapper.AccessorCalled.Should().Be.True();
		}
Esempio n. 4
0
        public void Map_GivenAReadOnlyPropertyInfo_ThrowsArgumentException()
        {
            var validatedObject = new Mock<IValidatedObject>();
            var entity = new PropertyMapperTestEntity();
            var propertyMapper = new PropertyMapper<PropertyMapperTestEntity>(entity, validatedObject.Object);
            propertyMapper.MapProperty(p => p.ReadOnlyIntProperty, 1);

            propertyMapper.Map ();
        }
Esempio n. 5
0
        public void Map_GivenAPropertyInfoWithPrivateSet_Succeeds()
        {
            var validatedObject = new Mock<IValidatedObject>();
            var entity = new PropertyMapperTestEntity();
            var propertyMapper = new PropertyMapper<PropertyMapperTestEntity>(entity, validatedObject.Object);
            propertyMapper.MapProperty(p => p.ObjectPropertyWithPrivateSetter, null);

            bool returnValue = propertyMapper.Map();
        }
		public void WhenSetTypeByIUserTypeThenSetTypeName()
		{
			var member = typeof(MyClass).GetProperty("ReadOnly");
			var mapping = new HbmProperty();
			var mapper = new PropertyMapper(member, mapping);
			mapper.Type<MyType>();

			Assert.That(mapping.Type.name, Is.StringContaining("MyType"));
			Assert.That(mapping.type, Is.Null);
		}
		public void WhenSettingByTypeThenCheckCompatibility()
		{
			var member = typeof(MyClass).GetProperty("ReadOnly");
			var mapping = new HbmProperty();
			var mapper = new PropertyMapper(member, mapping);

			Executing.This(() => mapper.Access(typeof(object))).Should().Throw<ArgumentOutOfRangeException>();
			Executing.This(() => mapper.Access(typeof(FieldAccessor))).Should().NotThrow();
			mapping.Access.Should().Be.EqualTo(typeof(FieldAccessor).AssemblyQualifiedName);
		}
		public void WhenSettingByTypeThenCheckCompatibility()
		{
			var member = typeof(MyClass).GetProperty("ReadOnly");
			var mapping = new HbmProperty();
			var mapper = new PropertyMapper(member, mapping);

			Assert.That(() => mapper.Access(typeof(object)), Throws.TypeOf<ArgumentOutOfRangeException>());
			Assert.That(() => mapper.Access(typeof(FieldAccessor)), Throws.Nothing);
			Assert.That(mapping.Access, Is.EqualTo(typeof(FieldAccessor).AssemblyQualifiedName));
		}
		public void WhenSetTypeByIUserTypeThenSetTypeName()
		{
			var member = typeof(MyClass).GetProperty("ReadOnly");
			var mapping = new HbmProperty();
			var mapper = new PropertyMapper(member, mapping);
			mapper.Type<MyType>();

			mapping.Type.name.Should().Contain("MyType");
			mapping.type.Should().Be.Null();
		}
Esempio n. 10
0
        public void MapProperty_GivenAllProperParameters_Succeeds()
        {
            var validatedObject = new Mock<IValidatedObject>();
            var entity = new PropertyMapperTestEntity();

            var propertyMapper = new PropertyMapper<PropertyMapperTestEntity>(entity, validatedObject.Object);

            var returnValue = propertyMapper.MapProperty(e => e.StringProperty, "SomeString");

            Assert.AreSame( propertyMapper, returnValue );
        }
Esempio n. 11
0
        public void Map_GivenAWritablePropertyInfo_Succeeds()
        {
            var stringValue = "SomeString";
            var validatedObject = new Mock<IValidatedObject>();
            var entity = new PropertyMapperTestEntity();
            var propertyMapper = new PropertyMapper<PropertyMapperTestEntity>(entity, validatedObject.Object);
            propertyMapper.MapProperty(p => p.StringProperty, stringValue);

            bool returnValue = propertyMapper.Map();

            Assert.IsTrue(returnValue);
            Assert.AreEqual(entity.StringProperty, stringValue);
        }
		public void WhenSetLazyThenSetAttributes()
		{
			var member = For<MyClass>.Property(x => x.ReadOnly);
			var mapping = new HbmProperty();
			var mapper = new PropertyMapper(member, mapping);

			mapper.Lazy(true);
			mapping.lazy.Should().Be.True();
			mapping.IsLazyProperty.Should().Be.True();
		}
		public void WhenSetInsertThenSetAttributes()
		{
			var member = For<MyClass>.Property(x => x.ReadOnly);
			var mapping = new HbmProperty();
			var mapper = new PropertyMapper(member, mapping);

			mapper.Insert(false);
			mapping.insert.Should().Be.False();
			mapping.insertSpecified.Should().Be.True();
		}
		public void WhenSetBasicColumnValuesThroughShortCutThenMergeColumn()
		{
			var member = typeof(MyClass).GetProperty("Autoproperty");
			var mapping = new HbmProperty();
			var mapper = new PropertyMapper(member, mapping);
			mapper.Column("pizza");
			mapper.Length(50);
			mapper.Precision(10);
			mapper.Scale(2);
			mapper.NotNullable(true);
			mapper.Unique(true);
			mapper.UniqueKey("AA");
			mapper.Index("II");

			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);
			mapping.uniquekey.Should().Be("AA");
			mapping.index.Should().Be("II");
		}
		public void AfterSetMultiColumnsCantSetSimpleColumn()
		{
			var member = typeof(MyClass).GetProperty("ReadOnly");
			var mapping = new HbmProperty();
			var mapper = new PropertyMapper(member, mapping);
			mapper.Columns(cm => cm.Length(50), cm => cm.SqlType("VARCHAR(10)"));
			Executing.This(() => mapper.Column(cm => cm.Length(50))).Should().Throw<MappingException>();
		}
		public void WhenSetMultiColumnsValuesThenAutoassignColumnNames()
		{
			var member = typeof(MyClass).GetProperty("ReadOnly");
			var mapping = new HbmProperty();
			var mapper = new PropertyMapper(member, 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 WhenSetInsertThenSetAttributes()
		{
			var member = For<MyClass>.Property(x => x.ReadOnly);
			var mapping = new HbmProperty();
			var mapper = new PropertyMapper(member, mapping);

			mapper.Insert(false);
			Assert.That(mapping.insert, Is.False);
			Assert.That(mapping.insertSpecified, Is.True);
		}
		public void WhenSetDefaultColumnNameThenDoesNotSetTheName()
		{
			var member = typeof(MyClass).GetProperty("Autoproperty");
			var mapping = new HbmProperty();
			var mapper = new PropertyMapper(member, mapping);
			mapper.Column(cm => { cm.Name("Autoproperty"); cm.Length(50); });
			mapping.column.Should().Be.Null();
			mapping.length.Should().Be("50");
			mapping.Columns.Should().Be.Empty();
		}
		public void WhenSetColumnValuesThenAddColumnTag()
		{
			var member = typeof(MyClass).GetProperty("Autoproperty");
			var mapping = new HbmProperty();
			var mapper = new PropertyMapper(member, 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 AfterSetMultiColumnsCantSetSimpleColumn()
		{
			var member = typeof(MyClass).GetProperty("ReadOnly");
			var mapping = new HbmProperty();
			var mapper = new PropertyMapper(member, mapping);
			mapper.Columns(cm => cm.Length(50), cm => cm.SqlType("VARCHAR(10)"));
			Assert.That(() => mapper.Column(cm => cm.Length(50)), Throws.TypeOf<MappingException>());
		}
		public void WhenSetDifferentColumnNameThenSetTheName()
		{
			var member = typeof(MyClass).GetProperty("Autoproperty");
			var mapping = new HbmProperty();
			var mapper = new PropertyMapper(member, mapping);
			mapper.Column(cm => cm.Name("pepe"));

			mapping.Columns.Should().Have.Count.EqualTo(1);
			mapping.Columns.Single().name.Should().Be("pepe");
		}
		public void WhenSetTypeByITypeTypeThenSetType()
		{
			var member = For<MyClass>.Property(c => c.EnumProp);
			var mapping = new HbmProperty();
			var mapper = new PropertyMapper(member, mapping);
			mapper.Type<EnumStringType<MyEnum>>();

			mapping.Type.name.Should().Contain(typeof(EnumStringType<MyEnum>).FullName);
			mapping.type.Should().Be.Null();
		}
		public void WhenSetTypeByIUserTypeWithParamsThenSetType()
		{
			var member = typeof(MyClass).GetProperty("ReadOnly");
			var mapping = new HbmProperty();
			var mapper = new PropertyMapper(member, 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 WhenSetBasicColumnValuesThroughShortCutThenMergeColumn()
		{
			var member = typeof(MyClass).GetProperty("Autoproperty");
			var mapping = new HbmProperty();
			var mapper = new PropertyMapper(member, mapping);
			mapper.Column("pizza");
			mapper.Length(50);
			mapper.Precision(10);
			mapper.Scale(2);
			mapper.NotNullable(true);
			mapper.Unique(true);
			mapper.UniqueKey("AA");
			mapper.Index("II");

			Assert.That(mapping.Items, Is.Null);
			Assert.That(mapping.column, Is.EqualTo("pizza"));
			Assert.That(mapping.length, Is.EqualTo("50"));
			Assert.That(mapping.precision, Is.EqualTo("10"));
			Assert.That(mapping.scale, Is.EqualTo("2"));
			Assert.That(mapping.notnull, Is.EqualTo(true));
			Assert.That(mapping.unique, Is.EqualTo(true));
			Assert.That(mapping.uniquekey, Is.EqualTo("AA"));
			Assert.That(mapping.index, Is.EqualTo("II"));
		}
		public void WhenSetMultiColumnsValuesThenAutoassignColumnNames()
		{
			var member = typeof(MyClass).GetProperty("ReadOnly");
			var mapping = new HbmProperty();
			var mapper = new PropertyMapper(member, mapping);
			mapper.Columns(cm => cm.Length(50), cm => cm.SqlType("VARCHAR(10)"));
			Assert.That(mapping.Columns.Count(), Is.EqualTo(2));
			Assert.True(mapping.Columns.All(cm => !string.IsNullOrEmpty(cm.name)));
		}
		public void WhenSetBasicColumnValuesMoreThanOnesThenMergeColumn()
		{
			var member = typeof(MyClass).GetProperty("Autoproperty");
			var mapping = new HbmProperty();
			var mapper = new PropertyMapper(member, 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);
			mapping.notnullSpecified.Should().Be(true);
		}
		public void WhenSetBasicColumnValuesMoreThanOnesThenMergeColumn()
		{
			var member = typeof(MyClass).GetProperty("Autoproperty");
			var mapping = new HbmProperty();
			var mapper = new PropertyMapper(member, mapping);
			mapper.Column(cm => cm.Length(50));
			mapper.Column(cm => cm.NotNullable(true));

			Assert.That(mapping.Items, Is.Null);
			Assert.That(mapping.length, Is.EqualTo("50"));
			Assert.That(mapping.notnull, Is.EqualTo(true));
			Assert.That(mapping.notnullSpecified, Is.EqualTo(true));
		}
		public void WhenSetMultiColumnsValuesThenAddColumns()
		{
			var member = typeof(MyClass).GetProperty("ReadOnly");
			var mapping = new HbmProperty();
			var mapper = new PropertyMapper(member, 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 member = typeof(MyClass).GetProperty("ReadOnly");
			var mapping = new HbmProperty();
			var mapper = new PropertyMapper(member, mapping);
			Executing.This(() => mapper.Type(typeof(object), null)).Should().Throw<ArgumentOutOfRangeException>();
			Executing.This(() => mapper.Type(null, null)).Should().Throw<ArgumentNullException>();
		}
		public void WhenSetLazyThenSetAttributes()
		{
			var member = For<MyClass>.Property(x => x.ReadOnly);
			var mapping = new HbmProperty();
			var mapper = new PropertyMapper(member, mapping);

			mapper.Lazy(true);
			Assert.That(mapping.lazy, Is.True);
			Assert.That(mapping.IsLazyProperty, Is.True);
		}