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

/src/NHibernate.Test/NHSpecificTest/NH3405/Fixture.cs

https://github.com/chester89/nhibernate-core
C# | 93 lines | 82 code | 11 blank | 0 comment | 0 complexity | 0dc08b25859fe66c36bb507f2b00a7f4 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, LGPL-2.1
  1. using System;
  2. using System.Linq;
  3. using System.Xml.Linq;
  4. using NHibernate.Cfg;
  5. using NHibernate.Cfg.MappingSchema;
  6. using NHibernate.Dialect;
  7. using NHibernate.Linq;
  8. using NHibernate.Mapping.ByCode;
  9. using NHibernate.Type;
  10. using NUnit.Framework;
  11. namespace NHibernate.Test.NHSpecificTest.NH3405
  12. {
  13. public class XmlTest
  14. {
  15. public virtual Int32 Id { get; set; }
  16. public virtual XDocument Data { get; set; }
  17. }
  18. public class Fixture : TestCaseMappingByCode
  19. {
  20. protected override void Configure(Configuration configuration)
  21. {
  22. configuration.SetProperty(Cfg.Environment.WrapResultSets, Boolean.TrueString);
  23. }
  24. protected override bool AppliesTo(Dialect.Dialect dialect)
  25. {
  26. return dialect is MsSql2005Dialect;
  27. }
  28. protected override HbmMapping GetMappings()
  29. {
  30. var mapper = new ModelMapper();
  31. mapper.Class<XmlTest>(rc =>
  32. {
  33. rc.Table("`XML_TEST`");
  34. rc.Id(x => x.Id,
  35. x =>
  36. {
  37. x.Column("`ID`");
  38. x.Generator(Generators.HighLow);
  39. });
  40. rc.Property(x => x.Data,
  41. x =>
  42. {
  43. x.Column("`DATA`");
  44. x.Type<XDocType>();
  45. x.NotNullable(true);
  46. });
  47. });
  48. return mapper.CompileMappingForAllExplicitlyAddedEntities();
  49. }
  50. protected override void OnSetUp()
  51. {
  52. using (var session = OpenSession())
  53. using (var transaction = session.BeginTransaction())
  54. {
  55. var t = new XmlTest { Data = XDocument.Parse("<test>123</test>") };
  56. session.Save(t);
  57. session.Flush();
  58. transaction.Commit();
  59. }
  60. }
  61. protected override void OnTearDown()
  62. {
  63. using (var session = OpenSession())
  64. using (var transaction = session.BeginTransaction())
  65. {
  66. session.Delete("from System.Object");
  67. session.Flush();
  68. transaction.Commit();
  69. }
  70. }
  71. [Test]
  72. public void CanLoadEntityWithXDocument()
  73. {
  74. using (var session = OpenSession())
  75. using (session.BeginTransaction())
  76. {
  77. var test = session.Query<XmlTest>().First();
  78. Assert.NotNull(test);
  79. }
  80. }
  81. }
  82. }