Mercurial > altnet-hispano
annotate Agendas/trunk/src/Agendas.Tests/Cruds/EventoCrud.cs @ 89:24e9488ac152
mapeo de property UrlInvitacion entre viewmodel y entity
author | jorge.rowies |
---|---|
date | Tue, 31 May 2011 16:31:24 -0300 |
parents | 26d0513a8410 |
children | db4b1e2cae49 |
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 |
87
26d0513a8410
A los publicadores les llega la lista de tracks producidos en la acción realizada
nelopauselli
parents:
80
diff
changeset
|
30 var evento = Evento.Proponer("TDD - Diseño Basado en Ejemplos", ponente, string.Empty); |
26d0513a8410
A los publicadores les llega la lista de tracks producidos en la acción realizada
nelopauselli
parents:
80
diff
changeset
|
31 _eventoRepository.Save(evento); |
60 | 32 |
87
26d0513a8410
A los publicadores les llega la lista de tracks producidos en la acción realizada
nelopauselli
parents:
80
diff
changeset
|
33 return evento.Id; |
60 | 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 |
80
c2d98fd6593f
Track como objeto identificable y con referencia al evento correspondiente.
nelopauselli
parents:
79
diff
changeset
|
51 var track1 = van.Tracks.Where(t => t.Accion == Accion.Proponer).FirstOrDefault(); |
c2d98fd6593f
Track como objeto identificable y con referencia al evento correspondiente.
nelopauselli
parents:
79
diff
changeset
|
52 Assert.IsNotNull(track1); |
c2d98fd6593f
Track como objeto identificable y con referencia al evento correspondiente.
nelopauselli
parents:
79
diff
changeset
|
53 Assert.AreEqual(van, track1.Evento); |
62
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
54 |
60 | 55 Assert.AreEqual("TDD - Diseño Basado en Ejemplos", van.Titulo); |
56 } | |
57 } | |
58 | |
59 public void Update() | |
60 { | |
61 Guid eventoId = Create(); | |
62 | |
63 using (_requestEmulator.Invoke()) | |
64 { | |
62
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
65 Evento van = _eventoRepository.Get(eventoId); |
60 | 66 |
67 Assert.IsNotNull(van); | |
68 | |
69 van.CambiarTitulo("TDD & Ejemplos"); | |
62
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
70 |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
71 var otroPonente = new Ponente("José"); |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
72 _ponenteRepository.Save(otroPonente); |
60 | 73 |
79
8df9db937434
Url de invitación en la UI: validación y persistencia
nelopauselli
parents:
75
diff
changeset
|
74 van.Actualizar(otroPonente, new DateTime(2010, 04, 17), null); |
62
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
75 |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
76 _eventoRepository.Update(van); |
60 | 77 } |
78 | |
79 using (_requestEmulator.Invoke()) | |
80 { | |
62
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
81 Evento van = _eventoRepository.Get(eventoId); |
60 | 82 |
83 Assert.IsNotNull(van); | |
84 Assert.IsNotNull(van.Ponente); | |
62
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
85 Assert.AreEqual("José", van.Ponente.Nombre); |
60 | 86 Assert.AreEqual("TDD & Ejemplos", van.Titulo); |
87 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
|
88 |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
89 var ponente1 = _ponenteRepository.GetByNombre("Carlos Blé"); |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
90 Assert.IsNotNull(ponente1); |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
91 Assert.AreEqual(0, ponente1.Eventos.Count()); |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
92 |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
93 var ponente2 = _ponenteRepository.GetByNombre("José"); |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
94 Assert.IsNotNull(ponente2); |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
95 Assert.AreEqual(1, ponente2.Eventos.Count()); |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
96 |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
97 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
|
98 Assert.AreEqual(1, van.Tracks.Where(t => t.Accion == Accion.Modificar).Count()); |
60 | 99 } |
100 } | |
101 | |
102 public void Delete() | |
103 { | |
104 Guid eventoId = Create(); | |
105 | |
106 using (_requestEmulator.Invoke()) | |
107 { | |
62
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
108 Evento van = _eventoRepository.Get(eventoId); |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
109 Assert.IsNotNull(van); |
60 | 110 |
62
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
111 _eventoRepository.Delete(van); |
60 | 112 } |
113 | |
114 using (_requestEmulator.Invoke()) | |
115 { | |
62
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
116 Evento van = _eventoRepository.Get(eventoId); |
60 | 117 |
118 Assert.IsNull(van); | |
62
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 var ponente = _ponenteRepository.GetByNombre("Carlos Blé"); |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
121 |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
122 Assert.IsNotNull(ponente); |
c40b97bbed01
Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents:
60
diff
changeset
|
123 Assert.AreEqual(0, ponente.Eventos.Count()); |
60 | 124 } |
125 } | |
126 } | |
127 } |