PageRenderTime 56ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

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

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