annotate Agendas/trunk/src/Agendas.Web.Tests/Controllers/PersonaControllerTests.cs @ 283:2e17dfd1ba35

Cambiandos espacios por tabuladores, etc.
author juanjose.montesdeocaarbos
date Mon, 26 Dec 2011 14:34:46 -0300
parents 3bb779434ae8
children
rev   line source
269
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
1 using System.Linq;
259
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
2 using System.Web.Mvc;
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
3 using Agendas.NHibernate;
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
4 using Agendas.Repositories.Tests.Infraestructure;
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
5 using AltNetHispano.Agendas.Domain;
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
6 using AltNetHispano.Agendas.Repositories.NHibernate;
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
7 using AltNetHispano.Agendas.Web.Controllers;
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
8 using AltNetHispano.Agendas.Web.Models;
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
9 using Moq;
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
10 using NUnit.Framework;
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
11
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
12 namespace Agendas.Web.Tests.Controllers
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
13 {
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
14 [TestFixture]
262
b87a4875b2b6 ControllerTests: Refactoring.
juanjose.montesdeocaarbos
parents: 261
diff changeset
15 public class PersonaControllerTests : MvcControllerTestsBase
259
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
16 {
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
17 private void SetearUsuario()
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
18 {
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
19 var seguridad = new Mock<ISeguridad>();
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
20 seguridad.Setup(s => s.GetUserName()).Returns("neluz");
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
21 IdentityContext.Init(seguridad.Object, new PersonaRepository(NhHelper.GetSessionFactory()));
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
22 }
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
23
270
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
24 private void PersonaNueva(ref PersonaController controller)
269
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
25 {
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
26 var personaNew = new PersonaNewModel
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
27 {
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
28 Blog = "http://juanjose.montesdeocaarbos.com.ar/blog/",
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
29 EMail = "juanjose.montesdeocaarbos@gmail.com",
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
30 Nombre = "Juan José Montes de Oca Arbós",
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
31 Roles = new string[] { "Administrador", "Usuario" },
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
32 Twitter = "jjmoa"
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
33 };
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
34
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
35 using (new RequestEmulator(NhHelper.GetSessionFactory()))
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
36 {
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
37 controller.Nueva(personaNew);
270
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
38 controller = new PersonaController { ControllerContext = ControllerCtx };
269
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
39 }
270
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
40
269
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
41 personaNew = new PersonaNewModel
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
42 {
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
43 Blog = "http://nelopauselli.blogspot.com/",
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
44 EMail = "nelo@gmail.com",
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
45 Nombre = "Nelo Mariano Pauselli",
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
46 Roles = new string[] { "Administrador", "Usuario" },
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
47 Twitter = "npauselli"
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
48 };
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
49
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
50 using (new RequestEmulator(NhHelper.GetSessionFactory()))
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
51 {
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
52 controller.Nueva(personaNew);
270
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
53 controller = new PersonaController { ControllerContext = ControllerCtx };
269
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
54 }
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
55 }
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
56
259
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
57 [SetUp]
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
58 public void Setup()
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
59 {
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
60 NhHelperTest.CleanDb();
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
61 SetearUsuario();
270
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
62 ControllerCtx = new ControllerContext();
259
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
63 }
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
64
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
65 [Test]
269
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
66 public void PersonaNuevaGET()
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
67 {
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
68 var personaController = new PersonaController { ControllerContext = ControllerCtx };
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
69 using (new RequestEmulator(NhHelper.GetSessionFactory()))
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
70 {
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
71 var resultNuevo = personaController.Nueva();
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
72 Assert.IsInstanceOf(typeof(ViewResult), resultNuevo);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
73 Assert.AreEqual("Defaulteditor", ((ViewResult)resultNuevo).ViewName);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
74 }
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
75 }
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
76
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
77 [Test]
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
78 public void PersonaModificarGET()
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
79 {
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
80 var personaController = new PersonaController { ControllerContext = ControllerCtx };
270
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
81 PersonaNueva(ref personaController);
269
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
82
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
83 using (new RequestEmulator(NhHelper.GetSessionFactory()))
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
84 {
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
85 var personaRepository = new PersonaRepository(NhHelper.GetSessionFactory());
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
86
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
87 var resultModificar = personaController.Modificar(personaRepository.GetAll().FirstOrDefault().Id.ToString());
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
88 Assert.IsInstanceOf(typeof(ViewResult), resultModificar);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
89 Assert.AreEqual("Defaulteditor", ((ViewResult)resultModificar).ViewName);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
90 }
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
91 }
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
92
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
93 [Test]
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
94 public void PersonaModificarGET_PersonaInexistente()
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
95 {
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
96 var personaController = new PersonaController { ControllerContext = ControllerCtx };
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
97
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
98 using (new RequestEmulator(NhHelper.GetSessionFactory()))
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
99 {
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
100 var resultModificar = personaController.Modificar("11111111-1111-1111-1111-111111111111");
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
101 Assert.IsInstanceOf(typeof(RedirectToRouteResult), resultModificar);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
102 Assert.AreEqual("Index", ((RedirectToRouteResult)resultModificar).RouteValues["action"]);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
103 Assert.AreEqual("No se encontró la persona que intenta modificar", personaController.TempData["error"]);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
104 }
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
105 }
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
106
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
107 [Test]
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
108 public void PersonaNuevaPOST_RequiredFields()
259
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
109 {
262
b87a4875b2b6 ControllerTests: Refactoring.
juanjose.montesdeocaarbos
parents: 261
diff changeset
110 var personaController = new PersonaController { ControllerContext = ControllerCtx };
259
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
111
261
d669e9b9e24e PersonaControllerTests: No se estaba pasando el HttpContext al test.
juanjose.montesdeocaarbos
parents: 259
diff changeset
112 var form = new FormCollection
d669e9b9e24e PersonaControllerTests: No se estaba pasando el HttpContext al test.
juanjose.montesdeocaarbos
parents: 259
diff changeset
113 {
269
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
114 {"Blog", ""},
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
115 {"EMail", ""},
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
116 {"Nombre", ""},
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
117 {"Roles", "Administrador"},
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
118 {"Roles", "Usuario"},
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
119 {"Twitter", ""}
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
120 };
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
121 var personaNew = BindModel<PersonaNewModel>(personaController, form);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
122
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
123 using (new RequestEmulator(NhHelper.GetSessionFactory()))
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
124 {
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
125 var resultNuevo = personaController.Nueva(personaNew);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
126 Assert.IsInstanceOf(typeof(ViewResult), resultNuevo);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
127 var viewResultNuevo = (ViewResult) resultNuevo;
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
128 Assert.AreEqual("Defaulteditor", viewResultNuevo.ViewName);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
129 Assert.AreEqual(1, viewResultNuevo.ViewData.ModelState["EMail"].Errors.Count);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
130 Assert.AreEqual("El campo EMail es obligatorio.", viewResultNuevo.ViewData.ModelState["EMail"].Errors[0].ErrorMessage);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
131 Assert.AreEqual(1, viewResultNuevo.ViewData.ModelState["Nombre"].Errors.Count);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
132 Assert.AreEqual("El campo Nombre es obligatorio.", viewResultNuevo.ViewData.ModelState["Nombre"].Errors[0].ErrorMessage);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
133 Assert.AreEqual(1, viewResultNuevo.ViewData.ModelState["Twitter"].Errors.Count);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
134 Assert.AreEqual("El campo Twitter es obligatorio.", viewResultNuevo.ViewData.ModelState["Twitter"].Errors[0].ErrorMessage);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
135 }
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
136 }
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
137
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
138 [Test]
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
139 public void PersonaNuevaPOST_FormatFields()
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
140 {
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
141 var personaController = new PersonaController { ControllerContext = ControllerCtx };
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
142
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
143 var form = new FormCollection
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
144 {
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
145 {"Blog", "montesdeocaarbos.com.ar/blog/"},
261
d669e9b9e24e PersonaControllerTests: No se estaba pasando el HttpContext al test.
juanjose.montesdeocaarbos
parents: 259
diff changeset
146 {"EMail", "juanjose.montesdeocaarbos gmail.com"},
d669e9b9e24e PersonaControllerTests: No se estaba pasando el HttpContext al test.
juanjose.montesdeocaarbos
parents: 259
diff changeset
147 {"Nombre", "Juan José Montes de Oca Arbós"},
d669e9b9e24e PersonaControllerTests: No se estaba pasando el HttpContext al test.
juanjose.montesdeocaarbos
parents: 259
diff changeset
148 {"Roles", "Administrador"},
d669e9b9e24e PersonaControllerTests: No se estaba pasando el HttpContext al test.
juanjose.montesdeocaarbos
parents: 259
diff changeset
149 {"Roles", "Usuario"},
d669e9b9e24e PersonaControllerTests: No se estaba pasando el HttpContext al test.
juanjose.montesdeocaarbos
parents: 259
diff changeset
150 {"Twitter", "@jjmoa"}
d669e9b9e24e PersonaControllerTests: No se estaba pasando el HttpContext al test.
juanjose.montesdeocaarbos
parents: 259
diff changeset
151 };
d669e9b9e24e PersonaControllerTests: No se estaba pasando el HttpContext al test.
juanjose.montesdeocaarbos
parents: 259
diff changeset
152 var personaNew = BindModel<PersonaNewModel>(personaController, form);
259
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
153
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
154 using (new RequestEmulator(NhHelper.GetSessionFactory()))
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
155 {
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
156 var resultNuevo = personaController.Nueva(personaNew);
269
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
157 Assert.IsInstanceOf(typeof(ViewResult), resultNuevo);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
158 var viewResultNuevo = (ViewResult)resultNuevo;
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
159 Assert.AreEqual("Defaulteditor", viewResultNuevo.ViewName);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
160 Assert.AreEqual(1, viewResultNuevo.ViewData.ModelState["Twitter"].Errors.Count);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
161 Assert.AreEqual("No debe ingresar el arroba al escribir la cuenta de twitter.", viewResultNuevo.ViewData.ModelState["Twitter"].Errors[0].ErrorMessage);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
162 Assert.AreEqual(1, viewResultNuevo.ViewData.ModelState["Blog"].Errors.Count);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
163 Assert.AreEqual("The Blog field is not a valid fully-qualified http, https, or ftp URL.", viewResultNuevo.ViewData.ModelState["Blog"].Errors[0].ErrorMessage);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
164 Assert.AreEqual(1, viewResultNuevo.ViewData.ModelState["EMail"].Errors.Count);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
165 Assert.AreEqual("The EMail field is not a valid e-mail address.", viewResultNuevo.ViewData.ModelState["EMail"].Errors[0].ErrorMessage);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
166 }
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
167 }
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
168
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
169 [Test]
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
170 public void PersonaNuevaPOST_PersonaExistente()
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
171 {
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
172 var personaController = new PersonaController { ControllerContext = ControllerCtx };
270
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
173 PersonaNueva(ref personaController);
269
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
174
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
175 var form = new FormCollection
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
176 {
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
177 {"Blog", "http://montesdeocaarbos.com.ar/blog/"},
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
178 {"EMail", "juanjose.montesdeocaarbos@gmail.com"},
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
179 {"Nombre", "Juan José Montes de Oca Arbós"},
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
180 {"Roles", "Administrador"},
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
181 {"Roles", "Usuario"},
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
182 {"Twitter", "jjmoa"}
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
183 };
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
184 var personaNew = BindModel<PersonaNewModel>(personaController, form);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
185
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
186 using (new RequestEmulator(NhHelper.GetSessionFactory()))
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
187 {
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
188 var resultNuevo = personaController.Nueva(personaNew);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
189 Assert.IsInstanceOf(typeof(ViewResult), resultNuevo);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
190 var viewResultNuevo = (ViewResult)resultNuevo;
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
191 Assert.AreEqual("Defaulteditor", viewResultNuevo.ViewName);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
192 Assert.AreEqual("Ya existe una persona con el nombre " + personaNew.Nombre, personaController.TempData["error"]);
259
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
193 }
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
194 }
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
195
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
196 [Test]
269
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
197 public void PersonaModificarPOST_RequiredFields()
259
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
198 {
269
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
199 var personaController = new PersonaController { ControllerContext = ControllerCtx };
270
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
200 PersonaNueva(ref personaController);
269
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
201
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
202 PersonaEditModel personaEdit = null;
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
203 using (new RequestEmulator(NhHelper.GetSessionFactory()))
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
204 {
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
205 var form = new FormCollection
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
206 {
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
207 {"Id", ""},
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
208 {"Blog", ""},
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
209 {"EMail", ""},
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
210 {"Nombre", ""},
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
211 {"Roles", "Administrador"},
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
212 {"Roles", "Usuario"},
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
213 {"Twitter", ""}
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
214 };
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
215 personaEdit = BindModel<PersonaEditModel>(personaController, form);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
216 }
259
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
217
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
218 using (new RequestEmulator(NhHelper.GetSessionFactory()))
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
219 {
269
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
220 var resultNuevo = personaController.Modificar(personaEdit);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
221 Assert.IsInstanceOf(typeof(ViewResult), resultNuevo);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
222 var viewResultNuevo = (ViewResult)resultNuevo;
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
223 Assert.AreEqual("Defaulteditor", viewResultNuevo.ViewName);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
224 Assert.AreEqual(1, viewResultNuevo.ViewData.ModelState["Id"].Errors.Count);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
225 Assert.AreEqual("El campo Id es obligatorio.", viewResultNuevo.ViewData.ModelState["Id"].Errors[0].ErrorMessage);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
226 Assert.AreEqual(1, viewResultNuevo.ViewData.ModelState["EMail"].Errors.Count);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
227 Assert.AreEqual("El campo EMail es obligatorio.", viewResultNuevo.ViewData.ModelState["EMail"].Errors[0].ErrorMessage);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
228 Assert.AreEqual(1, viewResultNuevo.ViewData.ModelState["Nombre"].Errors.Count);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
229 Assert.AreEqual("El campo Nombre es obligatorio.", viewResultNuevo.ViewData.ModelState["Nombre"].Errors[0].ErrorMessage);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
230 Assert.AreEqual(1, viewResultNuevo.ViewData.ModelState["Twitter"].Errors.Count);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
231 Assert.AreEqual("El campo Twitter es obligatorio.", viewResultNuevo.ViewData.ModelState["Twitter"].Errors[0].ErrorMessage);
259
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
232 }
269
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
233 }
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
234
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
235 [Test]
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
236 public void PersonaModificarPOST_FormatFields()
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
237 {
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
238 var personaController = new PersonaController { ControllerContext = ControllerCtx };
270
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
239 PersonaNueva(ref personaController);
259
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
240
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
241 PersonaEditModel personaEdit = null;
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
242 using (new RequestEmulator(NhHelper.GetSessionFactory()))
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
243 {
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
244 var personaRepository = new PersonaRepository(NhHelper.GetSessionFactory());
261
d669e9b9e24e PersonaControllerTests: No se estaba pasando el HttpContext al test.
juanjose.montesdeocaarbos
parents: 259
diff changeset
245
d669e9b9e24e PersonaControllerTests: No se estaba pasando el HttpContext al test.
juanjose.montesdeocaarbos
parents: 259
diff changeset
246 var form = new FormCollection
d669e9b9e24e PersonaControllerTests: No se estaba pasando el HttpContext al test.
juanjose.montesdeocaarbos
parents: 259
diff changeset
247 {
d669e9b9e24e PersonaControllerTests: No se estaba pasando el HttpContext al test.
juanjose.montesdeocaarbos
parents: 259
diff changeset
248 {"Id", personaRepository.GetAll().FirstOrDefault().Id.ToString()},
269
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
249 {"Blog", "montesdeocaarbos.com.ar/blog/"},
261
d669e9b9e24e PersonaControllerTests: No se estaba pasando el HttpContext al test.
juanjose.montesdeocaarbos
parents: 259
diff changeset
250 {"EMail", "juanjose.montesdeocaarbos gmail.com"},
d669e9b9e24e PersonaControllerTests: No se estaba pasando el HttpContext al test.
juanjose.montesdeocaarbos
parents: 259
diff changeset
251 {"Nombre", "Juan José Montes de Oca Arbós"},
d669e9b9e24e PersonaControllerTests: No se estaba pasando el HttpContext al test.
juanjose.montesdeocaarbos
parents: 259
diff changeset
252 {"Roles", "Administrador"},
d669e9b9e24e PersonaControllerTests: No se estaba pasando el HttpContext al test.
juanjose.montesdeocaarbos
parents: 259
diff changeset
253 {"Roles", "Usuario"},
d669e9b9e24e PersonaControllerTests: No se estaba pasando el HttpContext al test.
juanjose.montesdeocaarbos
parents: 259
diff changeset
254 {"Twitter", "@jjmoa"}
d669e9b9e24e PersonaControllerTests: No se estaba pasando el HttpContext al test.
juanjose.montesdeocaarbos
parents: 259
diff changeset
255 };
d669e9b9e24e PersonaControllerTests: No se estaba pasando el HttpContext al test.
juanjose.montesdeocaarbos
parents: 259
diff changeset
256 personaEdit = BindModel<PersonaEditModel>(personaController, form);
259
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
257 }
269
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
258
259
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
259 using (new RequestEmulator(NhHelper.GetSessionFactory()))
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
260 {
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
261 var resultModificar = personaController.Modificar(personaEdit);
269
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
262 Assert.IsInstanceOf(typeof(ViewResult), resultModificar);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
263 var viewResultModificar = (ViewResult)resultModificar;
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
264 Assert.AreEqual("Defaulteditor", viewResultModificar.ViewName);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
265 Assert.AreEqual(1, viewResultModificar.ViewData.ModelState["Twitter"].Errors.Count);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
266 Assert.AreEqual("No debe ingresar el arroba al escribir la cuenta de twitter.", viewResultModificar.ViewData.ModelState["Twitter"].Errors[0].ErrorMessage);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
267 Assert.AreEqual(1, viewResultModificar.ViewData.ModelState["Blog"].Errors.Count);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
268 Assert.AreEqual("The Blog field is not a valid fully-qualified http, https, or ftp URL.", viewResultModificar.ViewData.ModelState["Blog"].Errors[0].ErrorMessage);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
269 Assert.AreEqual(1, viewResultModificar.ViewData.ModelState["EMail"].Errors.Count);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
270 Assert.AreEqual("The EMail field is not a valid e-mail address.", viewResultModificar.ViewData.ModelState["EMail"].Errors[0].ErrorMessage);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
271 }
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
272 }
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
273
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
274 [Test]
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
275 public void PersonaModificarPOST_PersonaExistente()
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
276 {
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
277 var personaController = new PersonaController { ControllerContext = ControllerCtx };
270
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
278 PersonaNueva(ref personaController);
269
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
279
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
280 PersonaEditModel personaEdit = null;
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
281 using (new RequestEmulator(NhHelper.GetSessionFactory()))
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
282 {
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
283 var personaRepository = new PersonaRepository(NhHelper.GetSessionFactory());
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
284
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
285 var form = new FormCollection
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
286 {
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
287 {"Id", personaRepository.GetAll().FirstOrDefault().Id.ToString()},
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
288 {"Blog", "http://nelopauselli.blogspot.com/"},
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
289 {"EMail", "nelo@gmail.com"},
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
290 {"Nombre", "Nelo Mariano Pauselli"},
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
291 {"Roles", "Administrador"},
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
292 {"Roles", "Usuario"},
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
293 {"Twitter", "npauselli"}
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
294 };
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
295 personaEdit = BindModel<PersonaEditModel>(personaController, form);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
296 }
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
297
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
298 using (new RequestEmulator(NhHelper.GetSessionFactory()))
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
299 {
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
300 var resultEdit = personaController.Modificar(personaEdit);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
301 Assert.IsInstanceOf(typeof(ViewResult), resultEdit);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
302 var viewResultNuevo = (ViewResult)resultEdit;
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
303 Assert.AreEqual("Defaulteditor", viewResultNuevo.ViewName);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
304 Assert.AreEqual("Ya existe una persona con el twitter " + personaEdit.Twitter, personaController.TempData["error"]);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
305 }
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
306 }
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
307
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
308 [Test]
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
309 public void PersonaModificarPOST_Successful()
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
310 {
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
311 var personaController = new PersonaController { ControllerContext = ControllerCtx };
270
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
312 PersonaNueva(ref personaController);
269
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
313
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
314 PersonaEditModel personaEdit = null;
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
315 using (new RequestEmulator(NhHelper.GetSessionFactory()))
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
316 {
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
317 var personaRepository = new PersonaRepository(NhHelper.GetSessionFactory());
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
318
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
319 var form = new FormCollection
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
320 {
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
321 {"Id", personaRepository.GetAll().FirstOrDefault().Id.ToString()},
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
322 {"Blog", "http://montesdeocaarbos.com.ar/blog/"},
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
323 {"EMail", "juanjose.montesdeocaarbos@gmail.com"},
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
324 {"Nombre", "Juan José Montes de Oca Arbós"},
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
325 {"Roles", "Administrador"},
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
326 {"Roles", "Usuario"},
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
327 {"Twitter", "jjmoa"}
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
328 };
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
329 personaEdit = BindModel<PersonaEditModel>(personaController, form);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
330 }
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
331
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
332 using (new RequestEmulator(NhHelper.GetSessionFactory()))
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
333 {
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
334 var resultModificar = personaController.Modificar(personaEdit);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
335 Assert.IsInstanceOf(typeof(RedirectToRouteResult), resultModificar);
17694f70cfb6 Test de PersonaController.
juanjose.montesdeocaarbos
parents: 263
diff changeset
336 Assert.AreEqual("Index", ((RedirectToRouteResult)resultModificar).RouteValues["action"]);
259
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
337 }
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
338 }
270
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
339
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
340 [Test]
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
341 public void PersonaQuitarGET()
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
342 {
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
343 var personaController = new PersonaController { ControllerContext = ControllerCtx };
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
344 PersonaNueva(ref personaController);
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
345
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
346 using (new RequestEmulator(NhHelper.GetSessionFactory()))
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
347 {
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
348 var personaRepository = new PersonaRepository(NhHelper.GetSessionFactory());
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
349
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
350 var resultQuitar = personaController.Quitar(personaRepository.GetAll().FirstOrDefault().Id.ToString());
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
351
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
352 Assert.IsInstanceOf(typeof(RedirectToRouteResult), resultQuitar);
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
353 var redirectResultQuitar = (RedirectToRouteResult)resultQuitar;
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
354 Assert.AreEqual("Index", redirectResultQuitar.RouteValues["action"]);
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
355 Assert.AreEqual(1, personaController.TempData.Count);
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
356 Assert.AreEqual("Se ha eliminado correctamente a la persona", personaController.TempData["notification"]);
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
357 Assert.IsNull(personaController.TempData["warning"]);
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
358 Assert.IsNull(personaController.TempData["error"]);
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
359 }
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
360 }
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
361
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
362 [Test]
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
363 public void PersonaQuitarGET_PersonaInexistente()
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
364 {
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
365 var personaController = new PersonaController { ControllerContext = ControllerCtx };
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
366
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
367 using (new RequestEmulator(NhHelper.GetSessionFactory()))
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
368 {
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
369 const string personaId = "11111111-1111-1111-1111-111111111111";
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
370 var resultVer = personaController.Quitar(personaId);
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
371 Assert.IsInstanceOf(typeof(RedirectToRouteResult), resultVer);
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
372 Assert.AreEqual("Index", ((RedirectToRouteResult)resultVer).RouteValues["action"]);
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
373 Assert.AreEqual(string.Format("No se pudo encontrar la persona cuyo Id sea {0}", personaId), personaController.TempData["error"]);
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
374 }
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
375 }
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
376
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
377 [Test]
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
378 public void PersonaVerGET()
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
379 {
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
380 var personaController = new PersonaController { ControllerContext = ControllerCtx };
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
381 PersonaNueva(ref personaController);
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
382
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
383 using (new RequestEmulator(NhHelper.GetSessionFactory()))
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
384 {
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
385 var personaRepository = new PersonaRepository(NhHelper.GetSessionFactory());
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
386
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
387 var resultModificar = personaController.Ver(personaRepository.GetAll().FirstOrDefault().Id.ToString());
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
388 Assert.IsInstanceOf(typeof(ViewResult), resultModificar);
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
389 Assert.AreEqual("DefaultViewer", ((ViewResult)resultModificar).ViewName);
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
390 }
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
391 }
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
392
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
393 [Test]
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
394 public void PersonaVerGET_PersonaInexistente()
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
395 {
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
396 var personaController = new PersonaController { ControllerContext = ControllerCtx };
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
397
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
398 using (new RequestEmulator(NhHelper.GetSessionFactory()))
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
399 {
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
400 var resultVer = personaController.Ver("11111111-1111-1111-1111-111111111111");
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
401 Assert.IsInstanceOf(typeof(RedirectToRouteResult), resultVer);
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
402 Assert.AreEqual("Index", ((RedirectToRouteResult)resultVer).RouteValues["action"]);
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
403 Assert.AreEqual("No se encontró la persona que intenta visualizar", personaController.TempData["error"]);
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
404 }
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 269
diff changeset
405 }
259
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
406 }
e6c041d8e1bf Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
juanjose.montesdeocaarbos
parents:
diff changeset
407 }