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
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
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
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
3 using AltNetHispano.Agendas.Domain;
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
4 using AltNetHispano.Agendas.Domain.Repositories;
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
5 using NUnit.Framework;
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
6
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
7 namespace AltNetHispano.Agendas.Tests.Cruds
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
8 {
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
9 public class EventoCrud
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
10 {
62
c40b97bbed01 Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents: 60
diff changeset
11 private readonly IEventoRepository _eventoRepository;
60
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
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
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
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
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
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
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
20 _requestEmulator = requestEmulator;
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
21 }
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
22
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
23 public Guid Create()
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
24 {
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
25 using (_requestEmulator.Invoke())
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
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
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
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
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
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
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
34 }
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
35 }
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
36
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
37 public void Read()
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
38 {
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
39 Guid eventoId = Create();
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
40
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
41 using (_requestEmulator.Invoke())
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
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
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
44
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
45 Assert.IsNotNull(van);
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
46 Assert.IsNotNull(van.Ponente);
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
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
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
55 Assert.AreEqual("TDD - Diseño Basado en Ejemplos", van.Titulo);
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
56 }
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
57 }
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
58
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
59 public void Update()
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
60 {
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
61 Guid eventoId = Create();
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
62
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
63 using (_requestEmulator.Invoke())
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
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
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
66
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
67 Assert.IsNotNull(van);
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
68
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
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
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
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
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
77 }
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
78
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
79 using (_requestEmulator.Invoke())
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
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
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
82
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
83 Assert.IsNotNull(van);
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
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
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
86 Assert.AreEqual("TDD & Ejemplos", van.Titulo);
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
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
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
99 }
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
100 }
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
101
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
102 public void Delete()
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
103 {
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
104 Guid eventoId = Create();
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
105
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
106 using (_requestEmulator.Invoke())
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
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
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
110
62
c40b97bbed01 Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents: 60
diff changeset
111 _eventoRepository.Delete(van);
60
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
112 }
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
113
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
114 using (_requestEmulator.Invoke())
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
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
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
117
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
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
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
124 }
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
125 }
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
126 }
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
127 }