annotate Agendas/trunk/src/Agendas.Tests/Cruds/EventoCrud.cs @ 60:02e163f2ca38

Refactoring de test de crud del evento
author nelopauselli
date Mon, 16 May 2011 21:40:40 -0300
parents
children c40b97bbed01
rev   line source
60
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
1 using System;
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
2 using AltNetHispano.Agendas.Domain;
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
3 using AltNetHispano.Agendas.Domain.Repositories;
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
4 using NUnit.Framework;
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
5
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
6 namespace AltNetHispano.Agendas.Tests.Cruds
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
7 {
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
8 public class EventoCrud
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
9 {
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
10 private readonly Func<IEventoRepository> _createRepository;
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
11 private readonly Func<IDisposable> _requestEmulator;
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
12
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
13 public EventoCrud(Func<IEventoRepository> createRepository, Func<IDisposable> requestEmulator)
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
14 {
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
15 _createRepository = createRepository;
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
16 _requestEmulator = requestEmulator;
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
17 }
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
18
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
19 public Guid Create()
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
20 {
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
21 using (_requestEmulator.Invoke())
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 var van = Evento.Proponer("TDD - Diseño Basado en Ejemplos", new Ponente("Carlos Blé"));
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 IEventoRepository eventoRepository = _createRepository.Invoke();
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
26
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
27 eventoRepository.Save(van);
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
28
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
29 return van.Id;
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
30 }
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
31 }
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 public void Read()
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 Guid eventoId = Create();
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 using (_requestEmulator.Invoke())
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 IEventoRepository eventoRepository = _createRepository.Invoke();
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 Evento van = eventoRepository.Get(eventoId);
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
42
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
43 Assert.IsNotNull(van);
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
44 Assert.IsNotNull(van.Ponente);
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
45 Assert.AreEqual("Carlos Blé", van.Ponente.Nombre);
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
46 Assert.AreEqual("TDD - Diseño Basado en Ejemplos", van.Titulo);
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
47 }
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
48 }
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
49
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
50 public void Update()
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
51 {
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
52 Guid eventoId = Create();
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
53
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
54 using (_requestEmulator.Invoke())
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 IEventoRepository eventoRepository = _createRepository.Invoke();
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 Evento van = eventoRepository.Get(eventoId);
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
59
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
60 Assert.IsNotNull(van);
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
61
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
62 van.CambiarTitulo("TDD & Ejemplos");
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
63 van.Actualizar(van.Ponente, new DateTime(2010, 04, 17));
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 eventoRepository.Update(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
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
68 using (_requestEmulator.Invoke())
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
69 {
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
70 IEventoRepository eventoRepository = _createRepository.Invoke();
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
71
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
72 Evento van = eventoRepository.Get(eventoId);
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
73
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
74 Assert.IsNotNull(van);
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
75 Assert.IsNotNull(van.Ponente);
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
76 Assert.AreEqual("Carlos Blé", van.Ponente.Nombre);
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
77 Assert.AreEqual("TDD & Ejemplos", van.Titulo);
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
78 Assert.AreEqual(new DateTime(2010, 04, 17), van.Fecha);
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
79 }
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
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
82 public void Delete()
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
83 {
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
84 Guid eventoId = Create();
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
85
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
86 using (_requestEmulator.Invoke())
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
87 {
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
88 IEventoRepository eventoRepository = _createRepository.Invoke();
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
89
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
90 Evento van = eventoRepository.Get(eventoId);
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
91 Assert.IsNotNull(van);
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
92 eventoRepository.Delete(van);
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
93 }
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
94
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
95 using (_requestEmulator.Invoke())
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
96 {
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
97 IEventoRepository eventoRepository = _createRepository.Invoke();
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 Evento van = eventoRepository.Get(eventoId);
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 Assert.IsNull(van);
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
102 }
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 }
02e163f2ca38 Refactoring de test de crud del evento
nelopauselli
parents:
diff changeset
105 }