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