PageRenderTime 46ms CodeModel.GetById 20ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 0ms

/src/NHibernate.Test/MappingTest/NonReflectiveBinderFixture.cs

https://github.com/Odyl/nhibernate-core
C# | 198 lines | 135 code | 33 blank | 30 comment | 0 complexity | 955222e16774e93c6ae65a7fc5511f79 MD5 | raw file
  1using System.IO;
  2using NHibernate.Cfg;
  3using NHibernate.Cfg.MappingSchema;
  4using NHibernate.Mapping;
  5using NUnit.Framework;
  6
  7namespace NHibernate.Test.MappingTest
  8{
  9	[TestFixture]
 10	public class NonReflectiveBinderFixture
 11	{
 12		// so far we are using this test to check metadata
 13		// TODO: fix the test to work without class implementations
 14		// all infos coming from XML should be solved Mapping classes and not
 15		// during parse.
 16
 17		private Configuration cfg;
 18
 19		[TestFixtureSetUp]
 20		public void SetUp()
 21		{
 22			cfg = new Configuration()
 23					.AddResource("NHibernate.Test.MappingTest.Wicked.hbm.xml", GetType().Assembly);
 24			cfg.BuildMappings();
 25		}
 26
 27		[TestFixtureTearDown]
 28		public void TearDown()
 29		{
 30			cfg = null;
 31		}
 32
 33		[Test]
 34		public void MetaInheritance()
 35		{
 36			PersistentClass cm = cfg.GetClassMapping("NHibernate.Test.MappingTest.Wicked");
 37			var m = cm.MetaAttributes;
 38			Assert.That(m, Is.Not.Null);
 39			Assert.That(cm.GetMetaAttribute("global"), Is.Not.Null);
 40			Assert.That(cm.GetMetaAttribute("globalnoinherit"), Is.Null);
 41
 42			MetaAttribute metaAttribute = cm.GetMetaAttribute("implements");
 43			Assert.That(metaAttribute, Is.Not.Null);
 44			Assert.That(metaAttribute.Name, Is.EqualTo("implements"));
 45			Assert.That(metaAttribute.IsMultiValued);
 46			var values = metaAttribute.Values;
 47			Assert.That(values.Count, Is.EqualTo(3));
 48			Assert.That(values[0], Is.EqualTo("IObserver"));
 49			Assert.That(values[1], Is.EqualTo("IObserver"));
 50			Assert.That(values[2], Is.EqualTo("Foo.BogusVisitor"));
 51
 52			foreach (var element in cm.PropertyIterator)
 53			{
 54				var ma = element.MetaAttributes;
 55				Assert.That(ma, Is.Not.Null);
 56				Assert.That(element.GetMetaAttribute("global"), Is.Not.Null,"inherited attribute missing for prop {0}",element.Name);
 57				MetaAttribute metaAttribute2 = element.GetMetaAttribute("implements");
 58				Assert.That(metaAttribute2, Is.Not.Null);
 59				Assert.That(element.GetMetaAttribute("globalnoinherit"), Is.Null);
 60			}
 61
 62			Property prop = cm.GetProperty("Component");
 63			var map = prop.MetaAttributes;
 64			Assert.That(map, Is.Not.Null);
 65			Assert.That(prop.GetMetaAttribute("global"), Is.Not.Null);
 66			Assert.That(prop.GetMetaAttribute("componentonly"), Is.Not.Null);
 67			Assert.That(prop.GetMetaAttribute("allcomponent"), Is.Not.Null);
 68			Assert.That(prop.GetMetaAttribute("globalnoinherit"), Is.Null);
 69
 70			MetaAttribute compimplements = prop.GetMetaAttribute("implements");
 71			Assert.That(compimplements, Is.Not.Null);
 72			Assert.That(compimplements.Value, Is.EqualTo("AnotherInterface"));
 73
 74			Property xp = ((NHibernate.Mapping.Component)prop.Value).GetProperty("X");
 75			MetaAttribute propximplements = xp.GetMetaAttribute("implements");
 76			Assert.That(propximplements, Is.Not.Null);
 77			Assert.That(propximplements.Value, Is.EqualTo("AnotherInterface"));
 78		}
 79
 80		[Test]
 81		public void NonMutatedInheritance()
 82		{
 83			PersistentClass cm = cfg.GetClassMapping("NHibernate.Test.MappingTest.Wicked");
 84			MetaAttribute metaAttribute = cm.GetMetaAttribute("globalmutated");
 85
 86			Assert.That(metaAttribute, Is.Not.Null);
 87			/*assertEquals( metaAttribute.getValues().size(), 2 );		
 88			assertEquals( "top level", metaAttribute.getValues().get(0) );*/
 89			Assert.That(metaAttribute.Value, Is.EqualTo("wicked level"));
 90
 91			Property property = cm.GetProperty("Component");
 92			MetaAttribute propertyAttribute = property.GetMetaAttribute("globalmutated");
 93
 94			Assert.That(propertyAttribute, Is.Not.Null);
 95			/*assertEquals( propertyAttribute.getValues().size(), 3 );
 96			assertEquals( "top level", propertyAttribute.getValues().get(0) );
 97			assertEquals( "wicked level", propertyAttribute.getValues().get(1) );*/
 98			Assert.That(propertyAttribute.Value, Is.EqualTo("monetaryamount level"));
 99
100			var component = (NHibernate.Mapping.Component)property.Value;
101			property = component.GetProperty("X");
102			propertyAttribute = property.GetMetaAttribute("globalmutated");
103
104			Assert.That(propertyAttribute, Is.Not.Null);
105			/*assertEquals( propertyAttribute.getValues().size(), 4 );
106			assertEquals( "top level", propertyAttribute.getValues().get(0) );
107			assertEquals( "wicked level", propertyAttribute.getValues().get(1) );
108			assertEquals( "monetaryamount level", propertyAttribute.getValues().get(2) );*/
109			Assert.That(propertyAttribute.Value, Is.EqualTo("monetaryamount x level"));
110
111			property = cm.GetProperty("SortedEmployee");
112			propertyAttribute = property.GetMetaAttribute("globalmutated");
113
114			Assert.That(propertyAttribute, Is.Not.Null);
115			/*assertEquals( propertyAttribute.getValues().size(), 3 );
116			assertEquals( "top level", propertyAttribute.getValues().get(0) );
117			assertEquals( "wicked level", propertyAttribute.getValues().get(1) );*/
118			Assert.That(propertyAttribute.Value, Is.EqualTo("sortedemployee level"));
119
120			property = cm.GetProperty("AnotherSet");
121			propertyAttribute = property.GetMetaAttribute("globalmutated");
122
123			Assert.That(propertyAttribute, Is.Not.Null);
124			/*assertEquals( propertyAttribute.getValues().size(), 2 );
125			assertEquals( "top level", propertyAttribute.getValues().get(0) );*/
126			Assert.That(propertyAttribute.Value, Is.EqualTo("wicked level"));
127
128			var bag = (Bag)property.Value;
129			component = (NHibernate.Mapping.Component)bag.Element;
130
131			Assert.That(component.MetaAttributes.Count, Is.EqualTo(4));
132
133			metaAttribute = component.GetMetaAttribute("globalmutated");
134			/*assertEquals( metaAttribute.getValues().size(), 3 );
135			assertEquals( "top level", metaAttribute.getValues().get(0) );
136			assertEquals( "wicked level", metaAttribute.getValues().get(1) );*/
137			Assert.That(metaAttribute.Value, Is.EqualTo("monetaryamount anotherSet composite level"));
138
139			property = component.GetProperty("Emp");
140			propertyAttribute = property.GetMetaAttribute("globalmutated");
141
142			Assert.That(propertyAttribute, Is.Not.Null);
143			/*assertEquals( propertyAttribute.getValues().size(), 4 );
144			assertEquals( "top level", propertyAttribute.getValues().get(0) );
145			assertEquals( "wicked level", propertyAttribute.getValues().get(1) );
146			assertEquals( "monetaryamount anotherSet composite level", propertyAttribute.getValues().get(2) );*/
147			Assert.That(propertyAttribute.Value, Is.EqualTo("monetaryamount anotherSet composite property emp level"));
148
149			property = component.GetProperty("Empinone");
150			propertyAttribute = property.GetMetaAttribute("globalmutated");
151
152			Assert.That(propertyAttribute, Is.Not.Null);
153			/*assertEquals( propertyAttribute.getValues().size(), 4 );
154			assertEquals( "top level", propertyAttribute.getValues().get(0) );
155			assertEquals( "wicked level", propertyAttribute.getValues().get(1) );
156			assertEquals( "monetaryamount anotherSet composite level", propertyAttribute.getValues().get(2) );*/
157			Assert.That(propertyAttribute.Value, Is.EqualTo("monetaryamount anotherSet composite property empinone level"));
158		}
159
160		[Test, Ignore("Not fixed, see the TODO of this test.")]
161		public void Comparator()
162		{
163			PersistentClass cm = cfg.GetClassMapping("NHibernate.Test.MappingTest.Wicked");
164
165			Property property = cm.GetProperty("SortedEmployee");
166			var col = (Mapping.Collection)property.Value;
167			Assert.That(col.ComparerClassName, Is.StringStarting("NHibernate.Test.MappingTest.NonExistingComparator"));
168		}
169
170		[Test]
171		public void ReadSubClasses()
172		{
173			PersistentClass cm = cfg.GetClassMapping("NHibernate.Test.MappingTest.DomesticAnimal");
174			MetaAttribute metaAttribute = cm.GetMetaAttribute("Auditable");
175			Assert.That(metaAttribute, Is.Not.Null);
176			
177			cm = cfg.GetClassMapping("NHibernate.Test.MappingTest.Cat");
178			metaAttribute = cm.GetMetaAttribute("Auditable");
179			Assert.That(metaAttribute, Is.Not.Null);
180			
181			cm = cfg.GetClassMapping("NHibernate.Test.MappingTest.Dog");
182			metaAttribute = cm.GetMetaAttribute("Auditable");
183			Assert.That(metaAttribute, Is.Not.Null);
184		}
185
186		[Test]
187		public void XmlSerialization()
188		{
189			// NH-1865 (have a look to comments in JIRA)
190			var mdp = new MappingDocumentParser();
191			using (Stream stream = GetType().Assembly.GetManifestResourceStream("NHibernate.Test.MappingTest.Wicked.hbm.xml"))
192			{
193				HbmMapping mapping = mdp.Parse(stream);
194				Assert.That(mapping, Is.XmlSerializable);
195			}
196		}
197	}
198}