comparison 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
comparison
equal deleted inserted replaced
62:c40b97bbed01 63:963b71ea6028
1 using System;
2 using AltNetHispano.Agendas.Domain;
3 using AltNetHispano.Agendas.Repositories.NHibernate;
4 using Moq;
5 using NHibernate;
6 using NHibernate.Cfg;
7 using NHibernate.Context;
8 using NHibernate.Tool.hbm2ddl;
9 using NUnit.Framework;
10
11 namespace AltNetHispano.Agendas.Tests.Cruds
12 {
13 [TestFixture]
14 public class EventoCrudNhTests
15 {
16 private EventoCrud _eventoCrud;
17
18 #region SetUp
19
20 [SetUp]
21 public void BorrarRepositorios()
22 {
23 Configuration cfg =NhHelper.GetConfiguration();
24 var schemaExport = new SchemaExport(cfg);
25 schemaExport.Create(false, true);
26 }
27
28 [SetUp]
29 public void SetearUsuario()
30 {
31 var seguridad = new Mock<ISeguridad>();
32 seguridad.Setup(s => s.GetUserName()).Returns("neluz");
33 IdentityContext.Current = seguridad.Object;
34 }
35
36 [SetUp]
37 public void CreateCrud()
38 {
39 ISessionFactory sessionFactory=NhHelper.GetSessionFactory();
40 _eventoCrud = new EventoCrud(() => new EventoRepository(sessionFactory), () => new PonenteRepository(sessionFactory),
41 () => new RequestEmulator(sessionFactory));
42 }
43
44 #endregion
45
46 [Test]
47 public void Create()
48 {
49 _eventoCrud.Create();
50 }
51
52 [Test]
53 public void Read()
54 {
55 _eventoCrud.Read();
56 }
57
58 [Test]
59 public void Update()
60 {
61 _eventoCrud.Update();
62 }
63
64 [Test]
65 public void Delete()
66 {
67 _eventoCrud.Delete();
68 }
69
70 }
71
72 public class RequestEmulator : IDisposable
73 {
74 private readonly ISession _session;
75
76 public RequestEmulator(ISessionFactory sessionFactory)
77 {
78 _session = sessionFactory.OpenSession();
79 CurrentSessionContext.Bind(_session);
80 }
81
82 public void Dispose()
83 {
84 _session.Flush();
85 _session.Close();
86 }
87 }
88 }