Created
October 10, 2011 23:33
-
-
Save kylepace/1276872 to your computer and use it in GitHub Desktop.
Lunchage NHibernate Base Set Up
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestClass] | |
public class BaseNhTest | |
{ | |
protected Configuration Config; | |
private ISession session; | |
[TestInitialize] | |
public void Setup() | |
{ | |
this.Config = new Configuration(); | |
this.Config.CurrentSessionContext<CallSessionContext>(); | |
this.Config.DataBaseIntegration(x => { | |
x.Dialect<MySQLDialect>(); | |
x.ConnectionString = "server=YOUR_IP;database=DB_NAME;uid=USERNAME;pwd=PASSWORD"; | |
}); | |
var mappings = new ConventionsMapper().Mapping; | |
this.Config.AddDeserializedMapping(mappings, "LunchageModel"); | |
Console.Write(Serialize(mappings)); | |
var sessionFactory = this.Config.BuildSessionFactory(); | |
this.session = sessionFactory.OpenSession(); | |
} | |
[TestCleanup] | |
public void TearDown() | |
{ | |
this.session.Dispose(); | |
} | |
protected static string Serialize(HbmMapping hbmElement) | |
{ | |
var setting = new XmlWriterSettings { Indent = true }; | |
var serializer = new XmlSerializer(typeof(HbmMapping)); | |
using (var memStream = new MemoryStream()) { | |
using (var xmlWriter = XmlWriter.Create(memStream, setting)) { | |
serializer.Serialize(xmlWriter, hbmElement); | |
memStream.Flush(); | |
memStream.Position = 0; | |
var sr = new StreamReader(memStream); | |
return sr.ReadToEnd(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment