PageRenderTime 57ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/src/FluentNHibernate.Testing/AutoMapping/Steps/HasManyStepTests.cs

http://github.com/jagregory/fluent-nhibernate
C# | 108 lines | 90 code | 18 blank | 0 comment | 0 complexity | 51fa8b0f685ffe97808d13f93084a6ba MD5 | raw file
Possible License(s): BSD-3-Clause, CC-BY-SA-3.0, Apache-2.0
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Linq.Expressions;
  4. using FluentNHibernate.Automapping;
  5. using FluentNHibernate.Automapping.Steps;
  6. using FluentNHibernate.MappingModel;
  7. using FluentNHibernate.MappingModel.ClassBased;
  8. using FluentNHibernate.MappingModel.Collections;
  9. using FluentNHibernate.Utils.Reflection;
  10. using NUnit.Framework;
  11. namespace FluentNHibernate.Testing.AutoMapping.Steps
  12. {
  13. [TestFixture]
  14. public class HasManyStepTests
  15. {
  16. private HasManyStep mapper;
  17. [SetUp]
  18. public void CreateMapper()
  19. {
  20. mapper = new HasManyStep(new DefaultAutomappingConfiguration());
  21. }
  22. [Test]
  23. public void ShouldMapSets()
  24. {
  25. ShouldMap(x => x.Set);
  26. }
  27. [Test]
  28. public void ShouldMapLists()
  29. {
  30. ShouldMap(x => x.List);
  31. }
  32. [Test]
  33. public void ShouldntMapValueTypes()
  34. {
  35. ShouldntMap(x => x.Int);
  36. ShouldntMap(x => x.String);
  37. ShouldntMap(x => x.DateTime);
  38. }
  39. [Test]
  40. public void ShouldntMapEntities()
  41. {
  42. ShouldntMap(x => x.Entity);
  43. }
  44. [Test]
  45. public void ShouldMapListAsBag()
  46. {
  47. var classMapping = new ClassMapping();
  48. classMapping.Set(x => x.Type, Layer.Defaults, typeof(PropertyTarget));
  49. mapper.Map(classMapping, typeof(PropertyTarget).GetProperty("List").ToMember());
  50. classMapping.Collections
  51. .First().Collection.ShouldEqual(Collection.Bag);
  52. }
  53. [Test]
  54. public void ShouldMapSetAsSet()
  55. {
  56. var classMapping = new ClassMapping();
  57. classMapping.Set(x => x.Type, Layer.Defaults, typeof(PropertyTarget));
  58. mapper.Map(classMapping, typeof(PropertyTarget).GetProperty("Set").ToMember());
  59. classMapping.Collections
  60. .First().Collection.ShouldEqual(Collection.Set);
  61. }
  62. [Test]
  63. public void ShouldMapHashSetAsSet()
  64. {
  65. var classMapping = new ClassMapping();
  66. classMapping.Set(x => x.Type, Layer.Defaults, typeof(PropertyTarget));
  67. mapper.Map(classMapping, typeof(PropertyTarget).GetProperty("HashSet").ToMember());
  68. classMapping.Collections
  69. .First().Collection.ShouldEqual(Collection.Set);
  70. }
  71. protected void ShouldMap(Expression<System.Func<PropertyTarget, object>> property)
  72. {
  73. mapper.ShouldMap(ReflectionHelper.GetMember(property)).ShouldBeTrue();
  74. }
  75. protected void ShouldntMap(Expression<System.Func<PropertyTarget, object>> property)
  76. {
  77. mapper.ShouldMap(ReflectionHelper.GetMember(property)).ShouldBeFalse();
  78. }
  79. protected class PropertyTarget
  80. {
  81. public ISet<PropertyTarget> Set { get; set; }
  82. public HashSet<PropertyTarget> HashSet { get; set; }
  83. public IList<PropertyTarget> List { get; set; }
  84. public int Int { get; set; }
  85. public string String { get; set; }
  86. public System.DateTime DateTime { get; set; }
  87. public PropertyTarget Entity { get; set; }
  88. }
  89. }
  90. }