PageRenderTime 61ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/src/FluentNHibernate.Testing/ConventionsTests/Inspection/SubclassInspectorMapsToSubclassMapping.cs

https://github.com/carbrito/fluent-nhibernate
C# | 398 lines | 342 code | 56 blank | 0 comment | 0 complexity | c093ac9beb3e43bc6475035f6293059f MD5 | raw file
  1. using System;
  2. using System.Linq;
  3. using System.Linq.Expressions;
  4. using System.Reflection;
  5. using FluentNHibernate.Automapping.TestFixtures;
  6. using FluentNHibernate.Conventions;
  7. using FluentNHibernate.Conventions.Inspections;
  8. using FluentNHibernate.MappingModel;
  9. using FluentNHibernate.MappingModel.ClassBased;
  10. using FluentNHibernate.MappingModel.Collections;
  11. using FluentNHibernate.Utils;
  12. using NUnit.Framework;
  13. namespace FluentNHibernate.Testing.ConventionsTests.Inspection
  14. {
  15. [TestFixture, Category("Inspection DSL")]
  16. public class SubclassInspectorMapsToSubclassMapping
  17. {
  18. private SubclassMapping mapping;
  19. private ISubclassInspector inspector;
  20. [SetUp]
  21. public void CreateDsl()
  22. {
  23. mapping = new SubclassMapping();
  24. inspector = new SubclassInspector(mapping);
  25. }
  26. [Test]
  27. public void AbstractMapped()
  28. {
  29. mapping.Abstract = true;
  30. inspector.Abstract.ShouldEqual(true);
  31. }
  32. [Test]
  33. public void AbstractIsSet()
  34. {
  35. mapping.Abstract = true;
  36. inspector.IsSet(Prop(x => x.Abstract))
  37. .ShouldBeTrue();
  38. }
  39. [Test]
  40. public void AbstractIsNotSet()
  41. {
  42. inspector.IsSet(Prop(x => x.Abstract))
  43. .ShouldBeFalse();
  44. }
  45. [Test]
  46. public void AnysCollectionHasSameCountAsMapping()
  47. {
  48. mapping.AddAny(new AnyMapping());
  49. inspector.Anys.Count().ShouldEqual(1);
  50. }
  51. [Test]
  52. public void AnysCollectionOfInspectors()
  53. {
  54. mapping.AddAny(new AnyMapping());
  55. inspector.Anys.First().ShouldBeOfType<IAnyInspector>();
  56. }
  57. [Test]
  58. public void AnysCollectionIsEmpty()
  59. {
  60. inspector.Anys.IsEmpty().ShouldBeTrue();
  61. }
  62. [Test]
  63. public void CollectionsCollectionHasSameCountAsMapping()
  64. {
  65. mapping.AddCollection(new BagMapping());
  66. inspector.Collections.Count().ShouldEqual(1);
  67. }
  68. [Test]
  69. public void CollectionsCollectionOfInspectors()
  70. {
  71. mapping.AddCollection(new BagMapping());
  72. inspector.Collections.First().ShouldBeOfType<ICollectionInspector>();
  73. }
  74. [Test]
  75. public void CollectionsCollectionIsEmpty()
  76. {
  77. inspector.Collections.IsEmpty().ShouldBeTrue();
  78. }
  79. [Test]
  80. public void DiscriminatorValueMapped()
  81. {
  82. mapping.DiscriminatorValue = "value";
  83. inspector.DiscriminatorValue.ShouldEqual("value");
  84. }
  85. [Test]
  86. public void DiscriminatorValueIsSet()
  87. {
  88. mapping.DiscriminatorValue = "value";
  89. inspector.IsSet(Prop(x => x.DiscriminatorValue))
  90. .ShouldBeTrue();
  91. }
  92. [Test]
  93. public void DiscriminatorValueIsNotSet()
  94. {
  95. inspector.IsSet(Prop(x => x.DiscriminatorValue))
  96. .ShouldBeFalse();
  97. }
  98. [Test]
  99. public void DynamicInsertMapped()
  100. {
  101. mapping.DynamicInsert = true;
  102. inspector.DynamicInsert.ShouldEqual(true);
  103. }
  104. [Test]
  105. public void DynamicInsertIsSet()
  106. {
  107. mapping.DynamicInsert = true;
  108. inspector.IsSet(Prop(x => x.DynamicInsert))
  109. .ShouldBeTrue();
  110. }
  111. [Test]
  112. public void DynamicInsertIsNotSet()
  113. {
  114. inspector.IsSet(Prop(x => x.DynamicInsert))
  115. .ShouldBeFalse();
  116. }
  117. [Test]
  118. public void DynamicUpdateMapped()
  119. {
  120. mapping.DynamicUpdate = true;
  121. inspector.DynamicUpdate.ShouldEqual(true);
  122. }
  123. [Test]
  124. public void DynamicUpdateIsSet()
  125. {
  126. mapping.DynamicUpdate = true;
  127. inspector.IsSet(Prop(x => x.DynamicUpdate))
  128. .ShouldBeTrue();
  129. }
  130. [Test]
  131. public void DynamicUpdateIsNotSet()
  132. {
  133. inspector.IsSet(Prop(x => x.DynamicUpdate))
  134. .ShouldBeFalse();
  135. }
  136. [Test]
  137. public void ExtendsMapped()
  138. {
  139. mapping.Extends = "other-class";
  140. inspector.Extends.ShouldEqual("other-class");
  141. }
  142. [Test]
  143. public void ExtendsIsSet()
  144. {
  145. mapping.Extends = "other-class";
  146. inspector.IsSet(Prop(x => x.Extends))
  147. .ShouldBeTrue();
  148. }
  149. [Test]
  150. public void ExtendsIsNotSet()
  151. {
  152. inspector.IsSet(Prop(x => x.Extends))
  153. .ShouldBeFalse();
  154. }
  155. [Test]
  156. public void JoinsCollectionHasSameCountAsMapping()
  157. {
  158. mapping.AddJoin(new JoinMapping());
  159. inspector.Joins.Count().ShouldEqual(1);
  160. }
  161. [Test]
  162. public void JoinsCollectionOfInspectors()
  163. {
  164. mapping.AddJoin(new JoinMapping());
  165. inspector.Joins.First().ShouldBeOfType<IJoinInspector>();
  166. }
  167. [Test]
  168. public void JoinsCollectionIsEmpty()
  169. {
  170. inspector.Joins.IsEmpty().ShouldBeTrue();
  171. }
  172. [Test]
  173. public void LazyMapped()
  174. {
  175. mapping.Lazy = true;
  176. inspector.LazyLoad.ShouldEqual(true);
  177. }
  178. [Test]
  179. public void LazyIsSet()
  180. {
  181. mapping.Lazy = true;
  182. inspector.IsSet(Prop(x => x.LazyLoad))
  183. .ShouldBeTrue();
  184. }
  185. [Test]
  186. public void LazyIsNotSet()
  187. {
  188. inspector.IsSet(Prop(x => x.LazyLoad))
  189. .ShouldBeFalse();
  190. }
  191. [Test]
  192. public void NameMapped()
  193. {
  194. mapping.Name = "name";
  195. inspector.Name.ShouldEqual("name");
  196. }
  197. [Test]
  198. public void NameIsSet()
  199. {
  200. mapping.Name = "name";
  201. inspector.IsSet(Prop(x => x.Name))
  202. .ShouldBeTrue();
  203. }
  204. [Test]
  205. public void NameIsNotSet()
  206. {
  207. inspector.IsSet(Prop(x => x.Name))
  208. .ShouldBeFalse();
  209. }
  210. [Test]
  211. public void OneToOnesCollectionHasSameCountAsMapping()
  212. {
  213. mapping.AddOneToOne(new OneToOneMapping());
  214. inspector.OneToOnes.Count().ShouldEqual(1);
  215. }
  216. [Test]
  217. public void OneToOnesCollectionOfInspectors()
  218. {
  219. mapping.AddOneToOne(new OneToOneMapping());
  220. inspector.OneToOnes.First().ShouldBeOfType<IOneToOneInspector>();
  221. }
  222. [Test]
  223. public void OneToOnesCollectionIsEmpty()
  224. {
  225. inspector.OneToOnes.IsEmpty().ShouldBeTrue();
  226. }
  227. [Test]
  228. public void PropertiesCollectionHasSameCountAsMapping()
  229. {
  230. mapping.AddProperty(new PropertyMapping());
  231. inspector.Properties.Count().ShouldEqual(1);
  232. }
  233. [Test]
  234. public void PropertiesCollectionOfInspectors()
  235. {
  236. mapping.AddProperty(new PropertyMapping());
  237. inspector.Properties.First().ShouldBeOfType<IPropertyInspector>();
  238. }
  239. [Test]
  240. public void PropertiesCollectionIsEmpty()
  241. {
  242. inspector.Properties.IsEmpty().ShouldBeTrue();
  243. }
  244. [Test]
  245. public void ProxyMapped()
  246. {
  247. mapping.Proxy = "proxy";
  248. inspector.Proxy.ShouldEqual("proxy");
  249. }
  250. [Test]
  251. public void ProxyIsSet()
  252. {
  253. mapping.Proxy = "proxy";
  254. inspector.IsSet(Prop(x => x.Proxy))
  255. .ShouldBeTrue();
  256. }
  257. [Test]
  258. public void ProxyIsNotSet()
  259. {
  260. inspector.IsSet(Prop(x => x.Proxy))
  261. .ShouldBeFalse();
  262. }
  263. [Test]
  264. public void ReferencesCollectionHasSameCountAsMapping()
  265. {
  266. mapping.AddReference(new ManyToOneMapping());
  267. inspector.References.Count().ShouldEqual(1);
  268. }
  269. [Test]
  270. public void ReferencesCollectionOfInspectors()
  271. {
  272. mapping.AddReference(new ManyToOneMapping());
  273. inspector.References.First().ShouldBeOfType<IManyToOneInspector>();
  274. }
  275. [Test]
  276. public void ReferencesCollectionIsEmpty()
  277. {
  278. inspector.References.IsEmpty().ShouldBeTrue();
  279. }
  280. [Test]
  281. public void SelectBeforeUpdateMapped()
  282. {
  283. mapping.SelectBeforeUpdate = true;
  284. inspector.SelectBeforeUpdate.ShouldEqual(true);
  285. }
  286. [Test]
  287. public void SelectBeforeUpdateIsSet()
  288. {
  289. mapping.SelectBeforeUpdate = true;
  290. inspector.IsSet(Prop(x => x.SelectBeforeUpdate))
  291. .ShouldBeTrue();
  292. }
  293. [Test]
  294. public void SelectBeforeUpdateIsNotSet()
  295. {
  296. inspector.IsSet(Prop(x => x.SelectBeforeUpdate))
  297. .ShouldBeFalse();
  298. }
  299. [Test]
  300. public void SubclassesCollectionHasSameCountAsMapping()
  301. {
  302. mapping.AddSubclass(new SubclassMapping());
  303. inspector.Subclasses.Count().ShouldEqual(1);
  304. }
  305. [Test]
  306. public void SubclassesCollectionOfInspectors()
  307. {
  308. mapping.AddSubclass(new SubclassMapping());
  309. inspector.Subclasses.First().ShouldBeOfType<ISubclassInspector>();
  310. }
  311. [Test]
  312. public void SubclassesCollectionIsEmpty()
  313. {
  314. inspector.Subclasses.IsEmpty().ShouldBeTrue();
  315. }
  316. [Test]
  317. public void TypeMapped()
  318. {
  319. mapping.Type = typeof(ExampleClass);
  320. inspector.Type.ShouldEqual(typeof(ExampleClass));
  321. }
  322. [Test]
  323. public void TypeIsSet()
  324. {
  325. mapping.Type = typeof(ExampleClass);
  326. inspector.IsSet(Prop(x => x.Type))
  327. .ShouldBeTrue();
  328. }
  329. [Test]
  330. public void TypeIsNotSet()
  331. {
  332. inspector.IsSet(Prop(x => x.Type))
  333. .ShouldBeFalse();
  334. }
  335. #region Helpers
  336. private PropertyInfo Prop(Expression<Func<ISubclassInspector, object>> propertyExpression)
  337. {
  338. return ReflectionHelper.GetProperty(propertyExpression);
  339. }
  340. #endregion
  341. }
  342. }