Mercurial > altnet-hispano
annotate Agendas/trunk/src/Agendas.Tests/Cruds/EventoCrud.cs @ 66:a61f3204c9f7
Merge
author | jorge.rowies |
---|---|
date | Tue, 17 May 2011 18:25:17 -0300 |
parents | c40b97bbed01 |
children | 96d7609f2e08 |
rev | line source |
---|---|
60 | 1 using System; |
62
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
2 using System.Linq; |
60 | 3 using AltNetHispano.Agendas.Domain; |
4 using AltNetHispano.Agendas.Domain.Repositories; | |
5 using NUnit.Framework; | |
6 | |
7 namespace AltNetHispano.Agendas.Tests.Cruds | |
8 { | |
9 public class EventoCrud | |
10 { | |
62
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
11 private readonly IEventoRepository _eventoRepository; |
60 | 12 private readonly Func<IDisposable> _requestEmulator; |
62
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
13 private readonly IPonenteRepository _ponenteRepository; |
60 | 14 |
62
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
15 public EventoCrud(Func<IEventoRepository> createEventoRepository, Func<IPonenteRepository> createPonenteRepository, Func<IDisposable> requestEmulator) |
60 | 16 { |
62
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
17 _eventoRepository = createEventoRepository.Invoke(); |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
18 _ponenteRepository = createPonenteRepository.Invoke(); |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
19 |
60 | 20 _requestEmulator = requestEmulator; |
21 } | |
22 | |
23 public Guid Create() | |
24 { | |
25 using (_requestEmulator.Invoke()) | |
26 { | |
62
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
27 var ponente = new Ponente("Carlos Blé"); |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
28 _ponenteRepository.Save(ponente); |
60 | 29 |
62
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
30 var van = Evento.Proponer("TDD - Diseño Basado en Ejemplos", ponente); |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
31 _eventoRepository.Save(van); |
60 | 32 |
33 return van.Id; | |
34 } | |
35 } | |
36 | |
37 public void Read() | |
38 { | |
39 Guid eventoId = Create(); | |
40 | |
41 using (_requestEmulator.Invoke()) | |
42 { | |
62
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
43 Evento van = _eventoRepository.Get(eventoId); |
60 | 44 |
45 Assert.IsNotNull(van); | |
46 Assert.IsNotNull(van.Ponente); | |
47 Assert.AreEqual("Carlos Blé", van.Ponente.Nombre); | |
62
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
48 Assert.AreEqual(1, van.Ponente.Eventos.Count()); |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
49 Assert.AreEqual(van, van.Ponente.Eventos.First()); |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
50 |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
51 Assert.AreEqual(1, van.Tracks.Where(t => t.Accion == Accion.Proponer).Count()); |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
52 |
60 | 53 Assert.AreEqual("TDD - Diseño Basado en Ejemplos", van.Titulo); |
54 } | |
55 } | |
56 | |
57 public void Update() | |
58 { | |
59 Guid eventoId = Create(); | |
60 | |
61 using (_requestEmulator.Invoke()) | |
62 { | |
62
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
63 Evento van = _eventoRepository.Get(eventoId); |
60 | 64 |
65 Assert.IsNotNull(van); | |
66 | |
67 van.CambiarTitulo("TDD & Ejemplos"); | |
62
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
68 |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
69 var otroPonente = new Ponente("José"); |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
70 _ponenteRepository.Save(otroPonente); |
60 | 71 |
62
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
72 van.Actualizar(otroPonente, new DateTime(2010, 04, 17)); |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
73 |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
74 _eventoRepository.Update(van); |
60 | 75 } |
76 | |
77 using (_requestEmulator.Invoke()) | |
78 { | |
62
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
79 Evento van = _eventoRepository.Get(eventoId); |
60 | 80 |
81 Assert.IsNotNull(van); | |
82 Assert.IsNotNull(van.Ponente); | |
62
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
83 Assert.AreEqual("José", van.Ponente.Nombre); |
60 | 84 Assert.AreEqual("TDD & Ejemplos", van.Titulo); |
85 Assert.AreEqual(new DateTime(2010, 04, 17), van.Fecha); | |
62
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
86 |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
87 var ponente1 = _ponenteRepository.GetByNombre("Carlos Blé"); |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
88 Assert.IsNotNull(ponente1); |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
89 Assert.AreEqual(0, ponente1.Eventos.Count()); |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
90 |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
91 var ponente2 = _ponenteRepository.GetByNombre("José"); |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
92 Assert.IsNotNull(ponente2); |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
93 Assert.AreEqual(1, ponente2.Eventos.Count()); |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
94 |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
95 Assert.AreEqual(1, van.Tracks.Where(t => t.Accion == Accion.Proponer).Count()); |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
96 Assert.AreEqual(1, van.Tracks.Where(t => t.Accion == Accion.Modificar).Count()); |
60 | 97 } |
98 } | |
99 | |
100 public void Delete() | |
101 { | |
102 Guid eventoId = Create(); | |
103 | |
104 using (_requestEmulator.Invoke()) | |
105 { | |
62
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
106 Evento van = _eventoRepository.Get(eventoId); |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
107 Assert.IsNotNull(van); |
60 | 108 |
62
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
109 _eventoRepository.Delete(van); |
60 | 110 } |
111 | |
112 using (_requestEmulator.Invoke()) | |
113 { | |
62
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
114 Evento van = _eventoRepository.Get(eventoId); |
60 | 115 |
116 Assert.IsNull(van); | |
62
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
117 |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
118 var ponente = _ponenteRepository.GetByNombre("Carlos Blé"); |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
119 |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
120 Assert.IsNotNull(ponente); |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
121 Assert.AreEqual(0, ponente.Eventos.Count()); |
60 | 122 } |
123 } | |
124 } | |
125 } |