PageRenderTime 85ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/src/FluentNHibernate.Testing/FluentInterfaceTests/AnyMutablePropertyModelGenerationTests.cs

http://github.com/jagregory/fluent-nhibernate
C# | 282 lines | 259 code | 23 blank | 0 comment | 0 complexity | 6aecb49994d125ad78522a64860c8994 MD5 | raw file
Possible License(s): BSD-3-Clause, CC-BY-SA-3.0, Apache-2.0
  1. using System.Linq;
  2. using FluentNHibernate.MappingModel;
  3. using FluentNHibernate.Testing.DomainModel;
  4. using FluentNHibernate.Testing.DomainModel.Mapping;
  5. using NUnit.Framework;
  6. namespace FluentNHibernate.Testing.FluentInterfaceTests
  7. {
  8. [TestFixture]
  9. public class AnyMutablePropertyModelGenerationTests : BaseModelFixture
  10. {
  11. [Test]
  12. public void AccessSetsModelAccessPropertyToValue()
  13. {
  14. Any<SecondMappedObject>()
  15. .Mapping(m => m
  16. .IdentityType<int>()
  17. .EntityIdentifierColumn("col")
  18. .EntityTypeColumn("col2")
  19. .Access.Field())
  20. .ModelShouldMatch(x => x.Access.ShouldEqual("field"));
  21. }
  22. [Test]
  23. public void CascadeSetsModelCascadePropertyToValue()
  24. {
  25. Any<SecondMappedObject>()
  26. .Mapping(m => m
  27. .IdentityType<int>()
  28. .EntityIdentifierColumn("col")
  29. .EntityTypeColumn("col2")
  30. .Cascade.All())
  31. .ModelShouldMatch(x => x.Cascade.ShouldEqual("all"));
  32. }
  33. [Test]
  34. public void IdentityTypeSetsModelIdTypePropertyToPropertyTypeName()
  35. {
  36. Any<SecondMappedObject>()
  37. .Mapping(m => m
  38. .IdentityType(x => x.Id)
  39. .EntityIdentifierColumn("col")
  40. .EntityTypeColumn("col2"))
  41. .ModelShouldMatch(x => x.IdType.ShouldEqual(typeof(long).AssemblyQualifiedName));
  42. }
  43. [Test]
  44. public void IdentityTypeSetsModelIdTypePropertyToTypeName()
  45. {
  46. Any<SecondMappedObject>()
  47. .Mapping(m => m
  48. .IdentityType<int>()
  49. .EntityIdentifierColumn("col")
  50. .EntityTypeColumn("col2"))
  51. .ModelShouldMatch(x => x.IdType.ShouldEqual(typeof(int).AssemblyQualifiedName));
  52. }
  53. [Test]
  54. public void InsertSetsModelInsertPropertyToTrue()
  55. {
  56. Any<SecondMappedObject>()
  57. .Mapping(m => m
  58. .IdentityType<int>()
  59. .EntityIdentifierColumn("col")
  60. .EntityTypeColumn("col2")
  61. .Insert())
  62. .ModelShouldMatch(x => x.Insert.ShouldBeTrue());
  63. }
  64. [Test]
  65. public void NotInsertSetsModelInsertPropertyToFalse()
  66. {
  67. Any<SecondMappedObject>()
  68. .Mapping(m => m
  69. .IdentityType<int>()
  70. .EntityIdentifierColumn("col")
  71. .EntityTypeColumn("col2")
  72. .Not.Insert())
  73. .ModelShouldMatch(x => x.Insert.ShouldBeFalse());
  74. }
  75. [Test]
  76. public void UpdateSetsModelUpdatePropertyToTrue()
  77. {
  78. Any<SecondMappedObject>()
  79. .Mapping(m => m
  80. .IdentityType<int>()
  81. .EntityIdentifierColumn("col")
  82. .EntityTypeColumn("col2")
  83. .Update())
  84. .ModelShouldMatch(x => x.Update.ShouldBeTrue());
  85. }
  86. [Test]
  87. public void NotUpdateSetsModelUpdatePropertyToFalse()
  88. {
  89. Any<SecondMappedObject>()
  90. .Mapping(m => m
  91. .IdentityType<int>()
  92. .EntityIdentifierColumn("col")
  93. .EntityTypeColumn("col2")
  94. .Not.Update())
  95. .ModelShouldMatch(x => x.Update.ShouldBeFalse());
  96. }
  97. [Test]
  98. public void ReadOnlySetsModelInsertPropertyToFalse()
  99. {
  100. Any<SecondMappedObject>()
  101. .Mapping(m => m
  102. .IdentityType<int>()
  103. .EntityIdentifierColumn("col")
  104. .EntityTypeColumn("col2")
  105. .ReadOnly())
  106. .ModelShouldMatch(x => x.Insert.ShouldBeFalse());
  107. }
  108. [Test]
  109. public void NotReadOnlySetsModelInsertPropertyToTrue()
  110. {
  111. Any<SecondMappedObject>()
  112. .Mapping(m => m
  113. .IdentityType<int>()
  114. .EntityIdentifierColumn("col")
  115. .EntityTypeColumn("col2")
  116. .Not.ReadOnly())
  117. .ModelShouldMatch(x => x.Insert.ShouldBeTrue());
  118. }
  119. [Test]
  120. public void ReadOnlySetsModelUpdatePropertyToFalse()
  121. {
  122. Any<SecondMappedObject>()
  123. .Mapping(m => m
  124. .IdentityType<int>()
  125. .EntityIdentifierColumn("col")
  126. .EntityTypeColumn("col2")
  127. .ReadOnly())
  128. .ModelShouldMatch(x => x.Update.ShouldBeFalse());
  129. }
  130. [Test]
  131. public void NotReadOnlySetsModelUpdatePropertyToTrue()
  132. {
  133. Any<SecondMappedObject>()
  134. .Mapping(m => m
  135. .IdentityType<int>()
  136. .EntityIdentifierColumn("col")
  137. .EntityTypeColumn("col2")
  138. .Not.ReadOnly())
  139. .ModelShouldMatch(x => x.Update.ShouldBeTrue());
  140. }
  141. [Test]
  142. public void LazyLoadSetsModelLazyPropertyToTrue()
  143. {
  144. Any<SecondMappedObject>()
  145. .Mapping(m => m
  146. .IdentityType<int>()
  147. .EntityIdentifierColumn("col")
  148. .EntityTypeColumn("col2")
  149. .LazyLoad())
  150. .ModelShouldMatch(x => x.Lazy.ShouldBeTrue());
  151. }
  152. [Test]
  153. public void NotLazyLoadSetsModelLazyPropertyToFalse()
  154. {
  155. Any<SecondMappedObject>()
  156. .Mapping(m => m
  157. .IdentityType<int>()
  158. .EntityIdentifierColumn("col")
  159. .EntityTypeColumn("col2")
  160. .Not.LazyLoad())
  161. .ModelShouldMatch(x => x.Lazy.ShouldBeFalse());
  162. }
  163. [Test]
  164. public void OptimisticLockSetsModelOptimisticLockPropertyToTrue()
  165. {
  166. Any<SecondMappedObject>()
  167. .Mapping(m => m
  168. .IdentityType<int>()
  169. .EntityIdentifierColumn("col")
  170. .EntityTypeColumn("col2")
  171. .OptimisticLock())
  172. .ModelShouldMatch(x => x.OptimisticLock.ShouldBeTrue());
  173. }
  174. [Test]
  175. public void NotOptimisticLockSetsModelOptimisticLockPropertyToFalse()
  176. {
  177. Any<SecondMappedObject>()
  178. .Mapping(m => m
  179. .IdentityType<int>()
  180. .EntityIdentifierColumn("col")
  181. .EntityTypeColumn("col2")
  182. .Not.OptimisticLock())
  183. .ModelShouldMatch(x => x.OptimisticLock.ShouldBeFalse());
  184. }
  185. [Test]
  186. public void MetaTypePropertyShouldBeSetToPropertyTypeIfNoMetaValuesSet()
  187. {
  188. Any<SecondMappedObject>()
  189. .Mapping(m => m
  190. .IdentityType<int>()
  191. .EntityIdentifierColumn("col")
  192. .EntityTypeColumn("col2"))
  193. .ModelShouldMatch(x => x.MetaType.ShouldEqual(new TypeReference(typeof(SecondMappedObject))));
  194. }
  195. [Test]
  196. public void MetaTypePropertyShouldBeSetToStringIfMetaValuesSet()
  197. {
  198. Any<SecondMappedObject>()
  199. .Mapping(m => m
  200. .IdentityType<int>()
  201. .EntityIdentifierColumn("col")
  202. .EntityTypeColumn("col2")
  203. .AddMetaValue<Record>("Rec"))
  204. .ModelShouldMatch(x => x.MetaType.ShouldEqual(new TypeReference(typeof(string))));
  205. }
  206. [Test]
  207. public void NamePropertyShouldBeSetToPropertyName()
  208. {
  209. Any<SecondMappedObject>()
  210. .Mapping(m => m
  211. .IdentityType<int>()
  212. .EntityIdentifierColumn("col")
  213. .EntityTypeColumn("col2"))
  214. .ModelShouldMatch(x => x.Name.ShouldEqual("Parent"));
  215. }
  216. [Test]
  217. public void EntityIdentifierColumnShouldAddToModelColumnsCollection()
  218. {
  219. Any<SecondMappedObject>()
  220. .Mapping(m => m
  221. .IdentityType<int>()
  222. .EntityIdentifierColumn("col")
  223. .EntityTypeColumn("col2"))
  224. .ModelShouldMatch(x => x.IdentifierColumns.Count().ShouldEqual(1));
  225. }
  226. [Test]
  227. public void EntityTypeColumnShouldAddToModelColumnsCollection()
  228. {
  229. Any<SecondMappedObject>()
  230. .Mapping(m => m
  231. .IdentityType<int>()
  232. .EntityIdentifierColumn("col")
  233. .EntityTypeColumn("col2"))
  234. .ModelShouldMatch(x => x.TypeColumns.Count().ShouldEqual(1));
  235. }
  236. [Test]
  237. public void AddMetaValueShouldAddToModelMetaValuesCollection()
  238. {
  239. Any<SecondMappedObject>()
  240. .Mapping(m => m
  241. .IdentityType<int>()
  242. .EntityIdentifierColumn("col")
  243. .EntityTypeColumn("col2")
  244. .AddMetaValue<Record>("Rec"))
  245. .ModelShouldMatch(x => x.MetaValues.Count().ShouldEqual(1));
  246. }
  247. [Test]
  248. public void MetaTypeShouldSetMetaTypePropertyOnModel()
  249. {
  250. Any<SecondMappedObject>()
  251. .Mapping(m => m
  252. .IdentityType<int>()
  253. .EntityIdentifierColumn("col")
  254. .EntityTypeColumn("col2")
  255. .MetaType<object>())
  256. .ModelShouldMatch(x => x.MetaType.ShouldEqual(new TypeReference(typeof(object))));
  257. }
  258. }
  259. }