PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

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

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