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
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
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
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
32
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
33 return van.Id;
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
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
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
53 Assert.AreEqual("TDD - Diseño Basado en Ejemplos", van.Titulo);
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
54 }
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
55 }
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 public void Update()
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 Guid eventoId = Create();
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 using (_requestEmulator.Invoke())
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
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
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
64
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
65 Assert.IsNotNull(van);
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 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
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
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
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
75 }
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
76
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
77 using (_requestEmulator.Invoke())
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
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
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
80
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
81 Assert.IsNotNull(van);
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
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
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
84 Assert.AreEqual("TDD & Ejemplos", van.Titulo);
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
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
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
97 }
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
98 }
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 public void Delete()
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 Guid eventoId = Create();
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 using (_requestEmulator.Invoke())
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
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
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
108
62
c40b97bbed01 Verificando persistencia de Ponentes y Tracks en tests de CRUD
nelopauselli
parents: 60
diff changeset
109 _eventoRepository.Delete(van);
60
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
110 }
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
111
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
112 using (_requestEmulator.Invoke())
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
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
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
115
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
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
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
122 }
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
123 }
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 }