Mercurial > altnet-hispano
diff Agendas/trunk/src/Agendas.Tests/Cruds/EventoCrudNhTests.cs @ 63:963b71ea6028
Repositorios con NH
author | nelopauselli |
---|---|
date | Tue, 17 May 2011 14:02:25 -0300 |
parents | |
children | c8099df941bd |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Agendas/trunk/src/Agendas.Tests/Cruds/EventoCrudNhTests.cs Tue May 17 14:02:25 2011 -0300 @@ -0,0 +1,88 @@ +using System; +using AltNetHispano.Agendas.Domain; +using AltNetHispano.Agendas.Repositories.NHibernate; +using Moq; +using NHibernate; +using NHibernate.Cfg; +using NHibernate.Context; +using NHibernate.Tool.hbm2ddl; +using NUnit.Framework; + +namespace AltNetHispano.Agendas.Tests.Cruds +{ + [TestFixture] + public class EventoCrudNhTests + { + private EventoCrud _eventoCrud; + + #region SetUp + + [SetUp] + public void BorrarRepositorios() + { + Configuration cfg =NhHelper.GetConfiguration(); + var schemaExport = new SchemaExport(cfg); + schemaExport.Create(false, true); + } + + [SetUp] + public void SetearUsuario() + { + var seguridad = new Mock<ISeguridad>(); + seguridad.Setup(s => s.GetUserName()).Returns("neluz"); + IdentityContext.Current = seguridad.Object; + } + + [SetUp] + public void CreateCrud() + { + ISessionFactory sessionFactory=NhHelper.GetSessionFactory(); + _eventoCrud = new EventoCrud(() => new EventoRepository(sessionFactory), () => new PonenteRepository(sessionFactory), + () => new RequestEmulator(sessionFactory)); + } + + #endregion + + [Test] + public void Create() + { + _eventoCrud.Create(); + } + + [Test] + public void Read() + { + _eventoCrud.Read(); + } + + [Test] + public void Update() + { + _eventoCrud.Update(); + } + + [Test] + public void Delete() + { + _eventoCrud.Delete(); + } + + } + + public class RequestEmulator : IDisposable + { + private readonly ISession _session; + + public RequestEmulator(ISessionFactory sessionFactory) + { + _session = sessionFactory.OpenSession(); + CurrentSessionContext.Bind(_session); + } + + public void Dispose() + { + _session.Flush(); + _session.Close(); + } + } +} \ No newline at end of file