예제 #1
0
        public void CreateAttributeFromClassWrongName()
        {
            NhvmClassAttributename attributename = new NhvmClassAttributename();

            attributename.Text = new string[] { "assertanimal" };
            ActionAssert.Throws <InvalidAttributeNameException>(() => RuleAttributeFactory.CreateAttributeFromClass(typeof(Suricato), attributename));
        }
예제 #2
0
 public void CtorProtection()
 {
     ActionAssert.Throws <ArgumentNullException>(() => new RelationOn(null, null, null));
     ActionAssert.Throws <ArgumentNullException>(() => new RelationOn(typeof(A), null, null));
     ActionAssert.Throws <ArgumentNullException>(() => new RelationOn(null, null, typeof(A)));
     ActionAssert.Throws <ArgumentNullException>(() => new RelationOn(typeof(A), null, typeof(A)));
 }
예제 #3
0
		public void Ctor()
		{
			ActionAssert.Throws<ArgumentNullException>(() => new ParameterBinder(null, null, null));
			ActionAssert.Throws<ArgumentNullException>(() => new ParameterBinder(typeof(MyClass), null, null));
			ActionAssert.Throws<ArgumentNullException>(() => new ParameterBinder(typeof(MyClass), "", null));
			ActionAssert.Throws<ArgumentNullException>(() => new ParameterBinder(null, "A", null));
		}
        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)));
        }
        public void WhenApplierIsNotSupportedThenThrows()
        {
            IPatternsAppliersHolder source = new EmptyPatternsAppliersHolder();
            var applier = new Mock <IPatternApplier <int, string> >();

            ActionAssert.Throws <ArgumentOutOfRangeException>(() => source.Merge(applier.Object));
        }
예제 #6
0
        public void MappingDocumentParserTest()
        {
            // here we test only the exception since the other tests are included in MappingLoader
            MappingDocumentParser mdp = new MappingDocumentParser();

            ActionAssert.Throws <ArgumentNullException>(() => mdp.Parse(null));
        }
        public void RegisteringEntityAsComponentThrow()
        {
            var mapper = new ObjectRelationalMapper();

            mapper.TablePerClass <AComponent>();
            ActionAssert.Throws(() => mapper.Component <AComponent>()).Should().Be.InstanceOf <MappingException>();
        }
예제 #8
0
        public void GetInvalidValuesOfProperty()
        {
            IClassValidator cv = GetClassValidator(typeof(Address));

            cv.GetInvalidValues(null, "blacklistedZipCode").Should().Be.Empty();
            ActionAssert.Throws <ArgumentException>(() => cv.GetInvalidValues(new Suricato(), "blacklistedZipCode"));
        }
예제 #9
0
        public void WrongPropertyInCustomAttribute()
        {
            string tmpf = Path.GetTempFileName();

            using (StreamWriter sw = new StreamWriter(tmpf))
            {
                sw.WriteLine("<?xml version='1.0' encoding='utf-8' ?>");
                sw.WriteLine("<nhv-mapping xmlns='urn:nhibernate-validator-1.0'");
                sw.WriteLine(" assembly='NHibernate.Validator.Tests'");
                sw.WriteLine(" namespace='NHibernate.Validator.Tests.Configuration'>");
                sw.WriteLine("<class name='WellKnownRules'>");
                sw.WriteLine("<property name='AP'>");
                sw.WriteLine("<rule attribute='ACustomAttribute'>");
                sw.WriteLine("<param name='WrongName' value='A string value'/>");
                sw.WriteLine("</rule>");
                sw.WriteLine("</property>");
                sw.WriteLine("</class>");
                sw.WriteLine("</nhv-mapping>");
                sw.Flush();
            }

            XmlMappingLoader ml = new XmlMappingLoader();

            using (StreamReader sr = new StreamReader(tmpf))
            {
                ml.AddInputStream(sr.BaseStream, tmpf);
            }
            NhvMapping      map = ml.Mappings[0];
            NhvmClass       cm  = map.@class[0];
            XmlClassMapping rm  = new XmlClassMapping(cm);
            MemberInfo      mi;

            mi = typeof(WellKnownRules).GetField("AP");
            ActionAssert.Throws <InvalidPropertyNameException>(() => rm.GetMemberAttributes(mi));
        }
예제 #10
0
        public void GetInvalidValuesOfEntity()
        {
            IClassValidator cv = GetClassValidator(typeof(Address));

            cv.GetInvalidValues(null).Should().Be.Empty();

            ActionAssert.Throws <ArgumentException>(() => cv.GetInvalidValues(new Suricato()));
        }
        public void WhenSetInvalidTypeThenThrow()
        {
            var hbmDiscriminator = new HbmDiscriminator();
            var mapper           = new DiscriminatorMapper(hbmDiscriminator);

            ActionAssert.Throws <ArgumentOutOfRangeException>(() => mapper.Type(typeof(object)));
            ActionAssert.Throws <ArgumentNullException>(() => mapper.Type((Type)null));
        }
예제 #12
0
        public void GetterWithException()
        {
            TestingClass tc         = new TestingClass();
            MemberInfo   propMember = typeof(TestingClass).GetProperty("Problem");

            ActionAssert.Throws <InvalidStateException>(
                () => TypeUtils.GetMemberValue(tc, propMember));
        }
예제 #13
0
        public void CreateAttributeFromRule()
        {
            // Testing exception when a new element is added in XSD but not in factory
            ActionAssert.Throws <ValidatorConfigurationException>(() => RuleAttributeFactory.CreateAttributeFromRule("AnyObject", "", ""));

            // For wellKnownRules we can't do a sure tests because we don't have a way to auto-check all
            // classes derivered from serialization.
        }
예제 #14
0
        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)));
        }
예제 #15
0
        public void SetWrongProxy()
        {
            var subClass = typeof(Inherited);
            var mapdoc   = new HbmMapping();
            var mapper   = new JoinedSubclassMapper(subClass, mapdoc);

            ActionAssert.Throws <MappingException>(() => mapper.Proxy(typeof(Z)));
        }
        public void SetCollectionTypeByWrongTypeShouldThrow()
        {
            var hbm    = new HbmBag();
            var mapper = new BagMapper(typeof(Animal), typeof(Animal), hbm);

            ActionAssert.Throws <ArgumentNullException>(() => mapper.Type(null));
            ActionAssert.Throws <ArgumentOutOfRangeException>(() => mapper.Type(typeof(object)));
        }
예제 #17
0
        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 WhenSetMetaValueWithClassThenThrow()
        {
            var hbmMapping = new HbmMapping();
            var hbmAny     = new HbmAny();
            var mapper     = new AnyMapper(null, typeof(int), hbmAny, hbmMapping);

            ActionAssert.Throws <ArgumentOutOfRangeException>(() => mapper.MetaValue(typeof(MyReferenceClass), typeof(MyReferenceClass)));
        }
        public void WhenSetInvalidTypeThenThrow()
        {
            var member  = typeof(MyClass).GetProperty("Version");
            var mapping = new HbmVersion();
            var mapper  = new VersionMapper(member, mapping);

            ActionAssert.Throws <ArgumentOutOfRangeException>(() => mapper.Type(typeof(object)));
            ActionAssert.Throws <ArgumentNullException>(() => mapper.Type((Type)null));
        }
        public void AfterSetMultiColumnsCantSetSimpleColumn()
        {
            var member  = typeof(MyClass).GetProperty("Version");
            var mapping = new HbmVersion();
            var mapper  = new VersionMapper(member, mapping);

            mapper.Columns(cm => cm.Length(50), cm => cm.SqlType("VARCHAR(10)"));
            ActionAssert.Throws <ConfOrm.MappingException>(() => mapper.Column(cm => cm.Length(50)));
        }
예제 #21
0
        public void WhenSetInvalidTypeThenThrow()
        {
            var member  = typeof(MyClass).GetProperty("ReadOnly");
            var mapping = new HbmProperty();
            var mapper  = new PropertyMapper(member, mapping);

            ActionAssert.Throws <ArgumentOutOfRangeException>(() => mapper.Type(typeof(object), null));
            ActionAssert.Throws <ArgumentNullException>(() => mapper.Type(null, null));
        }
예제 #22
0
        public void WhenForceClassRelationToIncompatibleTypeThenThrows()
        {
            var hbmMapping = new HbmMapping();
            var member     = typeof(MyClass).GetProperty("TheOtherRelation");
            var mapping    = new HbmManyToOne();
            var mapper     = new ManyToOneMapper(member, mapping, hbmMapping);

            ActionAssert.Throws <ArgumentOutOfRangeException>(() => mapper.Class(typeof(Whatever)));
        }
        public void WhenDuplicatedMetaValueWithDifferentTypeThenThrow()
        {
            var hbmMapping = new HbmMapping();
            var hbmAny     = new HbmAny();
            var mapper     = new AnyMapper(null, typeof(int), hbmAny, hbmMapping);

            mapper.MetaValue('A', typeof(MyReferenceClass));
            ActionAssert.Throws <ArgumentException>(() => mapper.MetaValue('A', typeof(MyClass)));
        }
        public void WhenSetSecondMetaValueThenCheckCompatibility()
        {
            var hbmMapping = new HbmMapping();
            var hbmAny     = new HbmAny();
            var mapper     = new AnyMapper(null, typeof(int), hbmAny, hbmMapping);

            mapper.MetaValue('A', typeof(MyReferenceClass));
            ActionAssert.Throws <ArgumentException>(() => mapper.MetaValue(5, typeof(MyClass)));
        }
        public void WhenNullParameterThenThrow()
        {
            var hbmMapping = new HbmMapping();
            var hbmAny     = new HbmAny();
            var mapper     = new AnyMapper(null, typeof(int), hbmAny, hbmMapping);

            ActionAssert.Throws <ArgumentNullException>(() => mapper.MetaValue(null, typeof(MyReferenceClass)));
            ActionAssert.Throws <ArgumentNullException>(() => mapper.MetaValue('A', null));
        }
        public void WhenSetAccessorByTypeThenCheckCompatibility()
        {
            var member  = typeof(MyClass).GetProperty("ReadOnly");
            var mapping = new HbmVersion();
            var mapper  = new VersionMapper(member, mapping);

            ActionAssert.Throws <ArgumentOutOfRangeException>(() => mapper.Access(typeof(object)));
            ActionAssert.NotThrow(() => mapper.Access(typeof(FieldAccessor)));
            mapping.access.Should().Be.EqualTo(typeof(FieldAccessor).AssemblyQualifiedName);
        }
        public void MetaTypeShouldBeImmutable()
        {
            var hbmMapping = new HbmMapping();
            var hbmAny     = new HbmAny();
            var mapper     = new AnyMapper(null, typeof(int), hbmAny, hbmMapping);

            mapper.MetaValue('A', typeof(MyReferenceClass));
            ActionAssert.Throws <ArgumentException>(() => mapper.MetaType(NHibernateUtil.Int32));
            ActionAssert.Throws <ArgumentException>(mapper.MetaType <int>);
        }
예제 #28
0
        public void MappingHasDefaultAssembly()
        {
            var map = new Mapper();

            map.Assembly(typeof(Animal).Assembly);
            ActionAssert.Throws <ArgumentNullException>(() => map.Assembly(null));
            var hbm = map.GetCompiledMapping();

            hbm.assembly.Should().Be.EqualTo("MapDsl");
        }
        public void WhenMemberPropertyRefAcceptOnlyMemberOfExpectedType()
        {
            var hbm    = new HbmOneToOne();
            var mapper = new OneToOneMapper(typeof(MyClass).GetProperty("Relation"), hbm);

            mapper.PropertyReference(typeof(Relation).GetProperty("Whatever"));

            hbm.propertyref.Should().Be("Whatever");

            ActionAssert.Throws <ArgumentOutOfRangeException>(() => mapper.PropertyReference(typeof(Array).GetProperty("Length")));
        }
예제 #30
0
        public void WhenSetExtendsWithWrongBaseTypeThenThrow()
        {
            var subClass = typeof(Inherited);
            var mapdoc   = new HbmMapping {
                assembly = subClass.Assembly.FullName, @namespace = subClass.Namespace
            };
            var mapper = new JoinedSubclassMapper(subClass, mapdoc);

            ActionAssert.Throws <ArgumentOutOfRangeException>(() => mapper.Extends(typeof(Z)));
            ActionAssert.Throws <ArgumentOutOfRangeException>(() => mapper.Extends(typeof(Inherited2)));
        }