Mercurial > altnet-hispano
comparison 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 |
comparison
equal
deleted
inserted
replaced
59:4a4e12e32256 | 60:02e163f2ca38 |
---|---|
1 using System; | |
2 using AltNetHispano.Agendas.Domain; | |
3 using AltNetHispano.Agendas.Domain.Repositories; | |
4 using NUnit.Framework; | |
5 | |
6 namespace AltNetHispano.Agendas.Tests.Cruds | |
7 { | |
8 public class EventoCrud | |
9 { | |
10 private readonly Func<IEventoRepository> _createRepository; | |
11 private readonly Func<IDisposable> _requestEmulator; | |
12 | |
13 public EventoCrud(Func<IEventoRepository> createRepository, Func<IDisposable> requestEmulator) | |
14 { | |
15 _createRepository = createRepository; | |
16 _requestEmulator = requestEmulator; | |
17 } | |
18 | |
19 public Guid Create() | |
20 { | |
21 using (_requestEmulator.Invoke()) | |
22 { | |
23 var van = Evento.Proponer("TDD - Diseño Basado en Ejemplos", new Ponente("Carlos Blé")); | |
24 | |
25 IEventoRepository eventoRepository = _createRepository.Invoke(); | |
26 | |
27 eventoRepository.Save(van); | |
28 | |
29 return van.Id; | |
30 } | |
31 } | |
32 | |
33 public void Read() | |
34 { | |
35 Guid eventoId = Create(); | |
36 | |
37 using (_requestEmulator.Invoke()) | |
38 { | |
39 IEventoRepository eventoRepository = _createRepository.Invoke(); | |
40 | |
41 Evento van = eventoRepository.Get(eventoId); | |
42 | |
43 Assert.IsNotNull(van); | |
44 Assert.IsNotNull(van.Ponente); | |
45 Assert.AreEqual("Carlos Blé", van.Ponente.Nombre); | |
46 Assert.AreEqual("TDD - Diseño Basado en Ejemplos", van.Titulo); | |
47 } | |
48 } | |
49 | |
50 public void Update() | |
51 { | |
52 Guid eventoId = Create(); | |
53 | |
54 using (_requestEmulator.Invoke()) | |
55 { | |
56 IEventoRepository eventoRepository = _createRepository.Invoke(); | |
57 | |
58 Evento van = eventoRepository.Get(eventoId); | |
59 | |
60 Assert.IsNotNull(van); | |
61 | |
62 van.CambiarTitulo("TDD & Ejemplos"); | |
63 van.Actualizar(van.Ponente, new DateTime(2010, 04, 17)); | |
64 | |
65 eventoRepository.Update(van); | |
66 } | |
67 | |
68 using (_requestEmulator.Invoke()) | |
69 { | |
70 IEventoRepository eventoRepository = _createRepository.Invoke(); | |
71 | |
72 Evento van = eventoRepository.Get(eventoId); | |
73 | |
74 Assert.IsNotNull(van); | |
75 Assert.IsNotNull(van.Ponente); | |
76 Assert.AreEqual("Carlos Blé", van.Ponente.Nombre); | |
77 Assert.AreEqual("TDD & Ejemplos", van.Titulo); | |
78 Assert.AreEqual(new DateTime(2010, 04, 17), van.Fecha); | |
79 } | |
80 } | |
81 | |
82 public void Delete() | |
83 { | |
84 Guid eventoId = Create(); | |
85 | |
86 using (_requestEmulator.Invoke()) | |
87 { | |
88 IEventoRepository eventoRepository = _createRepository.Invoke(); | |
89 | |
90 Evento van = eventoRepository.Get(eventoId); | |
91 Assert.IsNotNull(van); | |
92 eventoRepository.Delete(van); | |
93 } | |
94 | |
95 using (_requestEmulator.Invoke()) | |
96 { | |
97 IEventoRepository eventoRepository = _createRepository.Invoke(); | |
98 | |
99 Evento van = eventoRepository.Get(eventoId); | |
100 | |
101 Assert.IsNull(van); | |
102 } | |
103 } | |
104 } | |
105 } |