comparison Agendas/trunk/src/Agendas.Web.Tests/Controllers/PatrocinadorControllerTests.cs @ 278:6f5ab71614d4

#125: ABM de patrocinadores.
author juanjose.montesdeocaarbos
date Wed, 21 Dec 2011 08:47:05 -0300
parents bf993f99cee3
children 1e889a2e45c5
comparison
equal deleted inserted replaced
277:7439d7a5f8d0 278:6f5ab71614d4
7 using System.Web.Mvc; 7 using System.Web.Mvc;
8 using System.Web.Routing; 8 using System.Web.Routing;
9 using Agendas.NHibernate; 9 using Agendas.NHibernate;
10 using Agendas.Repositories.Tests.Infraestructure; 10 using Agendas.Repositories.Tests.Infraestructure;
11 using Agendas.Web.Tests.Helpers; 11 using Agendas.Web.Tests.Helpers;
12 using AltNetHispano.Agendas.Repositories.NHibernate;
12 using AltNetHispano.Agendas.Web.Controllers; 13 using AltNetHispano.Agendas.Web.Controllers;
13 using AltNetHispano.Agendas.Web.Models; 14 using AltNetHispano.Agendas.Web.Models;
14 using Moq; 15 using Moq;
15 using NUnit.Framework; 16 using NUnit.Framework;
16 using System.Drawing; 17 using System.Drawing;
18 namespace Agendas.Web.Tests.Controllers 19 namespace Agendas.Web.Tests.Controllers
19 { 20 {
20 [TestFixture] 21 [TestFixture]
21 public class PatrocinadorControllerTests : MvcControllerTestsBase 22 public class PatrocinadorControllerTests : MvcControllerTestsBase
22 { 23 {
24 internal void CrearPatrocinadorApress()
25 {
26 var patrocinadorController = new PatrocinadorController(new HttpServerStub())
27 {
28 ControllerContext = ControllerCtx
29 };
30 var form = new FormCollection
31 {
32 {"Nombre", "APRESS"},
33 {"Logo", @"images\apress.gif"}
34 };
35 var patrocinadorNew = BindModel<PatrocinadorNewModel>(patrocinadorController, form);
36
37 using (new RequestEmulator(NhHelper.GetSessionFactory()))
38 {
39 var resultNuevo = patrocinadorController.Nuevo(patrocinadorNew);
40 }
41 }
42
43 internal void RegisterBinders()
44 {
45 ModelBinders.Binders[typeof(HttpPostedFileBase)] = new HttpPostedFileBaseModelBinder();
46 }
47
23 [SetUp] 48 [SetUp]
24 public void RegisterBinders() 49 public void SetUpTests()
25 { 50 {
26 ModelBinders.Binders[typeof(HttpPostedFileBase)] = new HttpPostedFileBaseModelBinder(); 51 NhHelperTest.CleanDb();
52 RegisterBinders();
27 } 53 }
28 54
29 [Test] 55 [Test]
30 public void PatrocinadorIndexGet() 56 public void PatrocinadorIndexGet()
31 { 57 {
96 using (new RequestEmulator(NhHelper.GetSessionFactory())) 122 using (new RequestEmulator(NhHelper.GetSessionFactory()))
97 { 123 {
98 var resultNuevo = patrocinadorController.Nuevo(patrocinadorNew); 124 var resultNuevo = patrocinadorController.Nuevo(patrocinadorNew);
99 Assert.IsInstanceOf(typeof(ViewResult), resultNuevo); 125 Assert.IsInstanceOf(typeof(ViewResult), resultNuevo);
100 var viewResultNuevo = (ViewResult)resultNuevo; 126 var viewResultNuevo = (ViewResult)resultNuevo;
101 Assert.AreEqual("DefaultEditor", viewResultNuevo.ViewName); //UploadFileEditor 127 Assert.AreEqual("DefaultEditor", viewResultNuevo.ViewName);
102 Assert.AreEqual(1, viewResultNuevo.ViewData.ModelState["Nombre"].Errors.Count); 128 Assert.AreEqual(1, viewResultNuevo.ViewData.ModelState["Nombre"].Errors.Count);
103 Assert.AreEqual("El campo Nombre es obligatorio.", viewResultNuevo.ViewData.ModelState["Nombre"].Errors[0].ErrorMessage); 129 Assert.AreEqual("El campo Nombre es obligatorio.", viewResultNuevo.ViewData.ModelState["Nombre"].Errors[0].ErrorMessage);
104 Assert.AreEqual(1, viewResultNuevo.ViewData.ModelState["Logo"].Errors.Count); 130 Assert.AreEqual(1, viewResultNuevo.ViewData.ModelState["Logo"].Errors.Count);
105 Assert.AreEqual("El campo Logo es obligatorio.", viewResultNuevo.ViewData.ModelState["Logo"].Errors[0].ErrorMessage); 131 Assert.AreEqual("El campo Logo es obligatorio.", viewResultNuevo.ViewData.ModelState["Logo"].Errors[0].ErrorMessage);
106 } 132 }
107 } 133 }
108 134
109 [Test] 135 [Test]
110 [Ignore] 136 public void PatrocinadorNuevoPostExists()
111 public void PatrocinadorNuevoPostExistente() 137 {
112 { 138 CrearPatrocinadorApress();
113 139
140 var patrocinadorController = new PatrocinadorController(new HttpServerStub())
141 {
142 ControllerContext = ControllerCtx
143 };
144 var form = new FormCollection
145 {
146 {"Nombre", "APRESS"},
147 {"Logo", @"images\apress.gif"}
148 };
149 var patrocinadorNew = BindModel<PatrocinadorNewModel>(patrocinadorController, form);
150
151 using (new RequestEmulator(NhHelper.GetSessionFactory()))
152 {
153 var resultNuevo = patrocinadorController.Nuevo(patrocinadorNew);
154 Assert.IsInstanceOf(typeof (ViewResult), resultNuevo);
155 var viewResultNuevo = (ViewResult) resultNuevo;
156
157 Assert.AreEqual("El patrocinador ya existe.", viewResultNuevo.TempData["error"]);
158 }
159 }
160
161 [Test]
162 public void PatrocinadorModificarGetDontExists()
163 {
164 var patrocinadorController = new PatrocinadorController(new HttpServerStub())
165 {
166 ControllerContext = ControllerCtx
167 };
168 using (new RequestEmulator(NhHelper.GetSessionFactory()))
169 {
170 var resultModificar = patrocinadorController.Modificar("11111111-1111-1111-1111-111111111111");
171 Assert.IsInstanceOf(typeof(RedirectToRouteResult), resultModificar);
172 Assert.AreEqual("Index", ((RedirectToRouteResult)resultModificar).RouteValues["action"]);
173 Assert.AreEqual("No se encontrĂ³ el patrocinador que intenta modificar", patrocinadorController.TempData["error"]);
174 }
175 }
176
177 [Test]
178 public void PatrocinadorModificarGetExists()
179 {
180 CrearPatrocinadorApress();
181
182 var patrocinadorController = new PatrocinadorController(new HttpServerStub())
183 {
184 ControllerContext = ControllerCtx
185 };
186
187 using (new RequestEmulator(NhHelper.GetSessionFactory()))
188 {
189 var patrocinadorRepository = new PatrocinadorRepository(NhHelper.GetSessionFactory());
190 var resultModificar = patrocinadorController.Modificar(patrocinadorRepository.GetAll().FirstOrDefault().Id.ToString());
191 Assert.IsInstanceOf(typeof(ViewResult), resultModificar);
192 Assert.AreEqual("DefaultEditor", ((ViewResult)resultModificar).ViewName);
193 }
194 }
195
196 [Test]
197 public void PatrocinadorModificarPostSatisfactorio()
198 {
199 PatrocinadorEditModel patrocinadorEdit;
200
201 CrearPatrocinadorApress();
202 var patrocinadorController = new PatrocinadorController(new HttpServerStub())
203 {
204 ControllerContext = ControllerCtx
205 };
206 using (new RequestEmulator(NhHelper.GetSessionFactory()))
207 {
208 var patrocinadorRepository = new PatrocinadorRepository(NhHelper.GetSessionFactory());
209
210 var form = new FormCollection
211 {
212 {"Id", patrocinadorRepository.GetAll().FirstOrDefault().Id.ToString()},
213 {"Nombre", "APRESS"},
214 {"Logo", @"images\apress.gif"}
215 };
216 patrocinadorEdit = BindModel<PatrocinadorEditModel>(patrocinadorController, form);
217 }
218
219 using (new RequestEmulator(NhHelper.GetSessionFactory()))
220 {
221 var resultModificar = patrocinadorController.Modificar(patrocinadorEdit);
222 Assert.IsInstanceOf(typeof(RedirectToRouteResult), resultModificar);
223 var viewResultEdit = (RedirectToRouteResult)resultModificar;
224 Assert.AreEqual("Index", viewResultEdit.RouteValues["action"]);
225 }
226 }
227
228 [Test]
229 public void PatrocinadorModificarPostRequiredFields()
230 {
231 CrearPatrocinadorApress();
232 var patrocinadorController = new PatrocinadorController(new HttpServerStub())
233 {
234 ControllerContext = ControllerCtx
235 };
236 var form = new FormCollection
237 {
238 {"Id", ""},
239 {"Nombre", ""},
240 {"Logo", ""}
241 };
242 var patrocinadorEdit = BindModel<PatrocinadorEditModel>(patrocinadorController, form);
243
244 using (new RequestEmulator(NhHelper.GetSessionFactory()))
245 {
246 var resultModificar = patrocinadorController.Modificar(patrocinadorEdit);
247 Assert.IsInstanceOf(typeof(ViewResult), resultModificar);
248 var viewResultNuevo = (ViewResult)resultModificar;
249 Assert.AreEqual("DefaultEditor", viewResultNuevo.ViewName);
250 Assert.AreEqual(1, viewResultNuevo.ViewData.ModelState["Nombre"].Errors.Count);
251 Assert.AreEqual("El campo Nombre es obligatorio.", viewResultNuevo.ViewData.ModelState["Nombre"].Errors[0].ErrorMessage);
252 Assert.AreEqual(1, viewResultNuevo.ViewData.ModelState["Logo"].Errors.Count);
253 Assert.AreEqual("El campo Logo es obligatorio.", viewResultNuevo.ViewData.ModelState["Logo"].Errors[0].ErrorMessage);
254 }
114 } 255 }
115 } 256 }
116
117 } 257 }