Skip to content

Instantly share code, notes, and snippets.

@kylepace
Created October 10, 2011 23:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylepace/1276872 to your computer and use it in GitHub Desktop.
Save kylepace/1276872 to your computer and use it in GitHub Desktop.
Lunchage NHibernate Base Set Up
[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