Mercurial > altnet-hispano
comparison Agendas/trunk/src/Agendas.Repositories.Tests/PersonaCrud.cs @ 222:68b09c30b0d2
Separando los test de persistencia en un proyecto aparte
author | nelopauselli |
---|---|
date | Mon, 19 Sep 2011 18:18:17 -0300 |
parents | Agendas/trunk/src/Agendas.Tests/Cruds/PersonaCrud.cs@b9850b647a4e |
children | 50442a103281 |
comparison
equal
deleted
inserted
replaced
221:37ddf81333d3 | 222:68b09c30b0d2 |
---|---|
1 using System; | |
2 using System.Collections.Generic; | |
3 using System.Linq; | |
4 using Agendas.Repositories.Tests.Infraestructure; | |
5 using AltNetHispano.Agendas.Domain; | |
6 using AltNetHispano.Agendas.Domain.Repositories; | |
7 using AltNetHispano.Agendas.Domain.Services; | |
8 using NUnit.Framework; | |
9 | |
10 namespace Agendas.Repositories.Tests | |
11 { | |
12 public abstract class PersonaCrud<T> where T : IInfraestrutureFactory, new() | |
13 { | |
14 private readonly IPersonaRepository _personaRepository; | |
15 private readonly Func<IDisposable> _requestEmulator; | |
16 private readonly PersonaService _personaService; | |
17 private readonly IEventoRepository _eventoRepository; | |
18 | |
19 protected PersonaCrud() | |
20 { | |
21 var infraestrutureFactory = new T(); | |
22 | |
23 _eventoRepository = infraestrutureFactory.GetEventoRepository(); | |
24 _personaRepository = infraestrutureFactory.GetPonenteRepository(); | |
25 _requestEmulator = infraestrutureFactory.GetRequestEmulator(); | |
26 | |
27 _personaService = new PersonaService(_personaRepository, _eventoRepository); | |
28 } | |
29 | |
30 [Test] | |
31 public void CreateAdministrador() | |
32 { | |
33 Guid id; | |
34 using (_requestEmulator.Invoke()) | |
35 { | |
36 var r = CreatePersona("Nelo Pauselli", "nelopauselli", "nelopauselli@gmail.com", "http://nelopauselli.blogspot.com", | |
37 null); | |
38 Assert.AreEqual("Nelo Pauselli", r.Nombre); | |
39 Assert.AreNotEqual(Guid.Empty, r.Id); | |
40 | |
41 id = r.Id; | |
42 } | |
43 | |
44 using (_requestEmulator.Invoke()) | |
45 { | |
46 var persona = _personaRepository.GetByNombre("Nelo Pauselli"); | |
47 Assert.IsNotNull(persona); | |
48 Assert.AreEqual(id, persona.Id); | |
49 } | |
50 } | |
51 | |
52 private ResultadoAdd CreatePersona(string nombre, string twitter, string mail, string blog, IEnumerable<string> roles) | |
53 { | |
54 return _personaService.Add(nombre, twitter, mail, blog, roles); | |
55 } | |
56 | |
57 [Test] | |
58 public void ReadAdministrador() | |
59 { | |
60 Guid personaId; | |
61 using (_requestEmulator.Invoke()) | |
62 { | |
63 var r = CreatePersona("Nelo Pauselli", "nelopauselli", "nelopauselli@gmail.com", "http://nelopauselli.blogspot.com", | |
64 null); | |
65 personaId = r.Id; | |
66 } | |
67 | |
68 using (_requestEmulator.Invoke()) | |
69 { | |
70 var persona = _personaRepository.Get(personaId); | |
71 | |
72 Assert.IsNotNull(persona); | |
73 Assert.AreEqual("Nelo Pauselli", persona.Nombre); | |
74 Assert.AreEqual("nelopauselli", persona.Twitter); | |
75 Assert.AreEqual("nelopauselli@gmail.com", persona.Mail); | |
76 Assert.AreEqual("http://nelopauselli.blogspot.com", persona.Blog); | |
77 | |
78 Assert.IsTrue(persona.Cuentas.Any()); | |
79 Assert.AreEqual("nelopauselli", persona.Cuentas.First().LogonName); | |
80 Assert.AreEqual(IdentityProviderEnum.Twitter, persona.Cuentas.First().IdentityProvider); | |
81 | |
82 Assert.IsTrue(persona.Roles.Any()); | |
83 Assert.IsTrue(persona.Roles.Contains(Roles.Usuario)); | |
84 Assert.IsTrue(persona.Roles.Contains(Roles.Administrador)); | |
85 } | |
86 } | |
87 | |
88 [Test] | |
89 public void CreateUsuario() | |
90 { | |
91 using (_requestEmulator.Invoke()) | |
92 { | |
93 CreatePersona("Pablo Morales", "pablomorales", "pablomorales@gmail.com", "http://pablomorales.blogspot.com", | |
94 new[] {Roles.Usuario}); | |
95 } | |
96 | |
97 using (_requestEmulator.Invoke()) | |
98 { | |
99 var persona = _personaRepository.GetByNombre("Pablo Morales"); | |
100 Assert.IsNotNull(persona); | |
101 } | |
102 } | |
103 | |
104 [Test] | |
105 public void ReadUsuario() | |
106 { | |
107 Guid personaId; | |
108 using (_requestEmulator.Invoke()) | |
109 { | |
110 var r = CreatePersona("Pablo Morales", "pablomorales", "pablomorales@gmail.com", "http://pablomorales.blogspot.com", | |
111 new[] {Roles.Usuario}); | |
112 personaId = r.Id; | |
113 } | |
114 | |
115 using (_requestEmulator.Invoke()) | |
116 { | |
117 var persona = _personaRepository.Get(personaId); | |
118 | |
119 Assert.IsNotNull(persona); | |
120 Assert.AreEqual("Pablo Morales", persona.Nombre); | |
121 Assert.AreEqual("pablomorales", persona.Twitter); | |
122 Assert.AreEqual("pablomorales@gmail.com", persona.Mail); | |
123 Assert.AreEqual("http://pablomorales.blogspot.com", persona.Blog); | |
124 | |
125 Assert.IsTrue(persona.Cuentas.Any()); | |
126 Assert.AreEqual("pablomorales", persona.Cuentas.First().LogonName); | |
127 Assert.AreEqual(IdentityProviderEnum.Twitter, persona.Cuentas.First().IdentityProvider); | |
128 | |
129 Assert.IsTrue(persona.Roles.Any()); | |
130 Assert.IsTrue(persona.Roles.Contains(Roles.Usuario)); | |
131 Assert.IsFalse(persona.Roles.Contains(Roles.Administrador)); | |
132 } | |
133 } | |
134 | |
135 [Test] | |
136 public void Update() | |
137 { | |
138 Guid personaId; | |
139 using (_requestEmulator.Invoke()) | |
140 { | |
141 var r = CreatePersona("Nelo Pauselli", "nelopauselli", "nelopauselli@gmail.com", "http://nelopauselli.blogspot.com", | |
142 null); | |
143 personaId = r.Id; | |
144 } | |
145 | |
146 using (_requestEmulator.Invoke()) | |
147 { | |
148 var persona = _personaRepository.Get(personaId); | |
149 Assert.IsNotNull(persona); | |
150 | |
151 persona.Nombre = "Nelo Mariano Pauselli"; | |
152 } | |
153 | |
154 using (_requestEmulator.Invoke()) | |
155 { | |
156 var persona = _personaRepository.Get(personaId); | |
157 | |
158 Assert.IsNotNull(persona); | |
159 Assert.AreEqual("Nelo Mariano Pauselli", persona.Nombre); | |
160 } | |
161 } | |
162 | |
163 [Test] | |
164 public void Delete() | |
165 { | |
166 Guid personaId; | |
167 using (_requestEmulator.Invoke()) | |
168 { | |
169 var r = CreatePersona("Nelo Pauselli", "nelopauselli", "nelopauselli@gmail.com", | |
170 "http://nelopauselli.blogspot.com", null); | |
171 personaId = r.Id; | |
172 } | |
173 | |
174 using (_requestEmulator.Invoke()) | |
175 { | |
176 var persona = _personaRepository.Get(personaId); | |
177 Assert.IsNotNull(persona); | |
178 _personaService.Delete(personaId); | |
179 } | |
180 using (_requestEmulator.Invoke()) | |
181 { | |
182 var persona = _personaRepository.Get(personaId); | |
183 Assert.IsNull(persona); | |
184 } | |
185 } | |
186 } | |
187 } |