Mercurial > altnet-hispano
comparison Agendas/trunk/src/Agendas.Web.Tests/Controllers/PersonaControllerTests.cs @ 270:3bb779434ae8
PersonaController: Coverage 100%
author | juanjose.montesdeocaarbos |
---|---|
date | Wed, 26 Oct 2011 09:31:17 -0300 |
parents | 17694f70cfb6 |
children |
comparison
equal
deleted
inserted
replaced
269:17694f70cfb6 | 270:3bb779434ae8 |
---|---|
19 var seguridad = new Mock<ISeguridad>(); | 19 var seguridad = new Mock<ISeguridad>(); |
20 seguridad.Setup(s => s.GetUserName()).Returns("neluz"); | 20 seguridad.Setup(s => s.GetUserName()).Returns("neluz"); |
21 IdentityContext.Init(seguridad.Object, new PersonaRepository(NhHelper.GetSessionFactory())); | 21 IdentityContext.Init(seguridad.Object, new PersonaRepository(NhHelper.GetSessionFactory())); |
22 } | 22 } |
23 | 23 |
24 private void PersonaNueva(PersonaController controller) | 24 private void PersonaNueva(ref PersonaController controller) |
25 { | 25 { |
26 var personaNew = new PersonaNewModel | 26 var personaNew = new PersonaNewModel |
27 { | 27 { |
28 Blog = "http://juanjose.montesdeocaarbos.com.ar/blog/", | 28 Blog = "http://juanjose.montesdeocaarbos.com.ar/blog/", |
29 EMail = "juanjose.montesdeocaarbos@gmail.com", | 29 EMail = "juanjose.montesdeocaarbos@gmail.com", |
33 }; | 33 }; |
34 | 34 |
35 using (new RequestEmulator(NhHelper.GetSessionFactory())) | 35 using (new RequestEmulator(NhHelper.GetSessionFactory())) |
36 { | 36 { |
37 controller.Nueva(personaNew); | 37 controller.Nueva(personaNew); |
38 } | 38 controller = new PersonaController { ControllerContext = ControllerCtx }; |
39 | 39 } |
40 | |
40 personaNew = new PersonaNewModel | 41 personaNew = new PersonaNewModel |
41 { | 42 { |
42 Blog = "http://nelopauselli.blogspot.com/", | 43 Blog = "http://nelopauselli.blogspot.com/", |
43 EMail = "nelo@gmail.com", | 44 EMail = "nelo@gmail.com", |
44 Nombre = "Nelo Mariano Pauselli", | 45 Nombre = "Nelo Mariano Pauselli", |
47 }; | 48 }; |
48 | 49 |
49 using (new RequestEmulator(NhHelper.GetSessionFactory())) | 50 using (new RequestEmulator(NhHelper.GetSessionFactory())) |
50 { | 51 { |
51 controller.Nueva(personaNew); | 52 controller.Nueva(personaNew); |
53 controller = new PersonaController { ControllerContext = ControllerCtx }; | |
52 } | 54 } |
53 } | 55 } |
54 | 56 |
55 [SetUp] | 57 [SetUp] |
56 public void Setup() | 58 public void Setup() |
57 { | 59 { |
58 NhHelperTest.CleanDb(); | 60 NhHelperTest.CleanDb(); |
59 SetearUsuario(); | 61 SetearUsuario(); |
62 ControllerCtx = new ControllerContext(); | |
60 } | 63 } |
61 | 64 |
62 [Test] | 65 [Test] |
63 public void PersonaNuevaGET() | 66 public void PersonaNuevaGET() |
64 { | 67 { |
73 | 76 |
74 [Test] | 77 [Test] |
75 public void PersonaModificarGET() | 78 public void PersonaModificarGET() |
76 { | 79 { |
77 var personaController = new PersonaController { ControllerContext = ControllerCtx }; | 80 var personaController = new PersonaController { ControllerContext = ControllerCtx }; |
78 PersonaNueva(personaController); | 81 PersonaNueva(ref personaController); |
79 | 82 |
80 using (new RequestEmulator(NhHelper.GetSessionFactory())) | 83 using (new RequestEmulator(NhHelper.GetSessionFactory())) |
81 { | 84 { |
82 var personaRepository = new PersonaRepository(NhHelper.GetSessionFactory()); | 85 var personaRepository = new PersonaRepository(NhHelper.GetSessionFactory()); |
83 | 86 |
92 { | 95 { |
93 var personaController = new PersonaController { ControllerContext = ControllerCtx }; | 96 var personaController = new PersonaController { ControllerContext = ControllerCtx }; |
94 | 97 |
95 using (new RequestEmulator(NhHelper.GetSessionFactory())) | 98 using (new RequestEmulator(NhHelper.GetSessionFactory())) |
96 { | 99 { |
97 var personaRepository = new PersonaRepository(NhHelper.GetSessionFactory()); | |
98 | |
99 var resultModificar = personaController.Modificar("11111111-1111-1111-1111-111111111111"); | 100 var resultModificar = personaController.Modificar("11111111-1111-1111-1111-111111111111"); |
100 Assert.IsInstanceOf(typeof(RedirectToRouteResult), resultModificar); | 101 Assert.IsInstanceOf(typeof(RedirectToRouteResult), resultModificar); |
101 Assert.AreEqual("Index", ((RedirectToRouteResult)resultModificar).RouteValues["action"]); | 102 Assert.AreEqual("Index", ((RedirectToRouteResult)resultModificar).RouteValues["action"]); |
102 Assert.AreEqual("No se encontrĂ³ la persona que intenta modificar", personaController.TempData["error"]); | 103 Assert.AreEqual("No se encontrĂ³ la persona que intenta modificar", personaController.TempData["error"]); |
103 } | 104 } |
167 | 168 |
168 [Test] | 169 [Test] |
169 public void PersonaNuevaPOST_PersonaExistente() | 170 public void PersonaNuevaPOST_PersonaExistente() |
170 { | 171 { |
171 var personaController = new PersonaController { ControllerContext = ControllerCtx }; | 172 var personaController = new PersonaController { ControllerContext = ControllerCtx }; |
172 PersonaNueva(personaController); | 173 PersonaNueva(ref personaController); |
173 | 174 |
174 var form = new FormCollection | 175 var form = new FormCollection |
175 { | 176 { |
176 {"Blog", "http://montesdeocaarbos.com.ar/blog/"}, | 177 {"Blog", "http://montesdeocaarbos.com.ar/blog/"}, |
177 {"EMail", "juanjose.montesdeocaarbos@gmail.com"}, | 178 {"EMail", "juanjose.montesdeocaarbos@gmail.com"}, |
194 | 195 |
195 [Test] | 196 [Test] |
196 public void PersonaModificarPOST_RequiredFields() | 197 public void PersonaModificarPOST_RequiredFields() |
197 { | 198 { |
198 var personaController = new PersonaController { ControllerContext = ControllerCtx }; | 199 var personaController = new PersonaController { ControllerContext = ControllerCtx }; |
199 PersonaNueva(personaController); | 200 PersonaNueva(ref personaController); |
200 | 201 |
201 PersonaEditModel personaEdit = null; | 202 PersonaEditModel personaEdit = null; |
202 using (new RequestEmulator(NhHelper.GetSessionFactory())) | 203 using (new RequestEmulator(NhHelper.GetSessionFactory())) |
203 { | 204 { |
204 var personaRepository = new PersonaRepository(NhHelper.GetSessionFactory()); | |
205 | |
206 var form = new FormCollection | 205 var form = new FormCollection |
207 { | 206 { |
208 {"Id", ""}, | 207 {"Id", ""}, |
209 {"Blog", ""}, | 208 {"Blog", ""}, |
210 {"EMail", ""}, | 209 {"EMail", ""}, |
235 | 234 |
236 [Test] | 235 [Test] |
237 public void PersonaModificarPOST_FormatFields() | 236 public void PersonaModificarPOST_FormatFields() |
238 { | 237 { |
239 var personaController = new PersonaController { ControllerContext = ControllerCtx }; | 238 var personaController = new PersonaController { ControllerContext = ControllerCtx }; |
240 PersonaNueva(personaController); | 239 PersonaNueva(ref personaController); |
241 | 240 |
242 PersonaEditModel personaEdit = null; | 241 PersonaEditModel personaEdit = null; |
243 using (new RequestEmulator(NhHelper.GetSessionFactory())) | 242 using (new RequestEmulator(NhHelper.GetSessionFactory())) |
244 { | 243 { |
245 var personaRepository = new PersonaRepository(NhHelper.GetSessionFactory()); | 244 var personaRepository = new PersonaRepository(NhHelper.GetSessionFactory()); |
274 | 273 |
275 [Test] | 274 [Test] |
276 public void PersonaModificarPOST_PersonaExistente() | 275 public void PersonaModificarPOST_PersonaExistente() |
277 { | 276 { |
278 var personaController = new PersonaController { ControllerContext = ControllerCtx }; | 277 var personaController = new PersonaController { ControllerContext = ControllerCtx }; |
279 PersonaNueva(personaController); | 278 PersonaNueva(ref personaController); |
280 | 279 |
281 PersonaEditModel personaEdit = null; | 280 PersonaEditModel personaEdit = null; |
282 using (new RequestEmulator(NhHelper.GetSessionFactory())) | 281 using (new RequestEmulator(NhHelper.GetSessionFactory())) |
283 { | 282 { |
284 var personaRepository = new PersonaRepository(NhHelper.GetSessionFactory()); | 283 var personaRepository = new PersonaRepository(NhHelper.GetSessionFactory()); |
308 | 307 |
309 [Test] | 308 [Test] |
310 public void PersonaModificarPOST_Successful() | 309 public void PersonaModificarPOST_Successful() |
311 { | 310 { |
312 var personaController = new PersonaController { ControllerContext = ControllerCtx }; | 311 var personaController = new PersonaController { ControllerContext = ControllerCtx }; |
313 PersonaNueva(personaController); | 312 PersonaNueva(ref personaController); |
314 | 313 |
315 PersonaEditModel personaEdit = null; | 314 PersonaEditModel personaEdit = null; |
316 using (new RequestEmulator(NhHelper.GetSessionFactory())) | 315 using (new RequestEmulator(NhHelper.GetSessionFactory())) |
317 { | 316 { |
318 var personaRepository = new PersonaRepository(NhHelper.GetSessionFactory()); | 317 var personaRepository = new PersonaRepository(NhHelper.GetSessionFactory()); |
335 var resultModificar = personaController.Modificar(personaEdit); | 334 var resultModificar = personaController.Modificar(personaEdit); |
336 Assert.IsInstanceOf(typeof(RedirectToRouteResult), resultModificar); | 335 Assert.IsInstanceOf(typeof(RedirectToRouteResult), resultModificar); |
337 Assert.AreEqual("Index", ((RedirectToRouteResult)resultModificar).RouteValues["action"]); | 336 Assert.AreEqual("Index", ((RedirectToRouteResult)resultModificar).RouteValues["action"]); |
338 } | 337 } |
339 } | 338 } |
339 | |
340 [Test] | |
341 public void PersonaQuitarGET() | |
342 { | |
343 var personaController = new PersonaController { ControllerContext = ControllerCtx }; | |
344 PersonaNueva(ref personaController); | |
345 | |
346 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
347 { | |
348 var personaRepository = new PersonaRepository(NhHelper.GetSessionFactory()); | |
349 | |
350 var resultQuitar = personaController.Quitar(personaRepository.GetAll().FirstOrDefault().Id.ToString()); | |
351 | |
352 Assert.IsInstanceOf(typeof(RedirectToRouteResult), resultQuitar); | |
353 var redirectResultQuitar = (RedirectToRouteResult)resultQuitar; | |
354 Assert.AreEqual("Index", redirectResultQuitar.RouteValues["action"]); | |
355 Assert.AreEqual(1, personaController.TempData.Count); | |
356 Assert.AreEqual("Se ha eliminado correctamente a la persona", personaController.TempData["notification"]); | |
357 Assert.IsNull(personaController.TempData["warning"]); | |
358 Assert.IsNull(personaController.TempData["error"]); | |
359 } | |
360 } | |
361 | |
362 [Test] | |
363 public void PersonaQuitarGET_PersonaInexistente() | |
364 { | |
365 var personaController = new PersonaController { ControllerContext = ControllerCtx }; | |
366 | |
367 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
368 { | |
369 const string personaId = "11111111-1111-1111-1111-111111111111"; | |
370 var resultVer = personaController.Quitar(personaId); | |
371 Assert.IsInstanceOf(typeof(RedirectToRouteResult), resultVer); | |
372 Assert.AreEqual("Index", ((RedirectToRouteResult)resultVer).RouteValues["action"]); | |
373 Assert.AreEqual(string.Format("No se pudo encontrar la persona cuyo Id sea {0}", personaId), personaController.TempData["error"]); | |
374 } | |
375 } | |
376 | |
377 [Test] | |
378 public void PersonaVerGET() | |
379 { | |
380 var personaController = new PersonaController { ControllerContext = ControllerCtx }; | |
381 PersonaNueva(ref personaController); | |
382 | |
383 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
384 { | |
385 var personaRepository = new PersonaRepository(NhHelper.GetSessionFactory()); | |
386 | |
387 var resultModificar = personaController.Ver(personaRepository.GetAll().FirstOrDefault().Id.ToString()); | |
388 Assert.IsInstanceOf(typeof(ViewResult), resultModificar); | |
389 Assert.AreEqual("DefaultViewer", ((ViewResult)resultModificar).ViewName); | |
390 } | |
391 } | |
392 | |
393 [Test] | |
394 public void PersonaVerGET_PersonaInexistente() | |
395 { | |
396 var personaController = new PersonaController { ControllerContext = ControllerCtx }; | |
397 | |
398 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
399 { | |
400 var resultVer = personaController.Ver("11111111-1111-1111-1111-111111111111"); | |
401 Assert.IsInstanceOf(typeof(RedirectToRouteResult), resultVer); | |
402 Assert.AreEqual("Index", ((RedirectToRouteResult)resultVer).RouteValues["action"]); | |
403 Assert.AreEqual("No se encontrĂ³ la persona que intenta visualizar", personaController.TempData["error"]); | |
404 } | |
405 } | |
340 } | 406 } |
341 } | 407 } |