Mercurial > altnet-hispano
annotate Agendas/trunk/src/Agendas.Web.Tests/Controllers/PatrocinadorControllerTests.cs @ 298:9bc60d166c8a
Se corrigieron los tests por el cambio de Patrocinador, para que no persista el logo en disco.
Se comentó el código de PatrocinadorApiController, que no se utiliza.
author | juanjose.montesdeocaarbos |
---|---|
date | Sun, 19 Feb 2012 16:00:38 -0300 |
parents | 1e889a2e45c5 |
children | 48ab8788bd19 |
rev | line source |
---|---|
275
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
1 using System; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
2 using System.Collections.Generic; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
3 using System.IO; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
4 using System.Linq; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
5 using System.Text; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
6 using System.Web; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
7 using System.Web.Mvc; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
8 using System.Web.Routing; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
9 using Agendas.NHibernate; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
10 using Agendas.Repositories.Tests.Infraestructure; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
11 using Agendas.Web.Tests.Helpers; |
278 | 12 using AltNetHispano.Agendas.Repositories.NHibernate; |
275
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
13 using AltNetHispano.Agendas.Web.Controllers; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
14 using AltNetHispano.Agendas.Web.Models; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
15 using Moq; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
16 using NUnit.Framework; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
17 using System.Drawing; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
18 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
19 namespace Agendas.Web.Tests.Controllers |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
20 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
21 [TestFixture] |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
22 public class PatrocinadorControllerTests : MvcControllerTestsBase |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
23 { |
278 | 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() | |
275
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
44 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
45 ModelBinders.Binders[typeof(HttpPostedFileBase)] = new HttpPostedFileBaseModelBinder(); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
46 } |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
47 |
278 | 48 [SetUp] |
49 public void SetUpTests() | |
50 { | |
51 NhHelperTest.CleanDb(); | |
52 RegisterBinders(); | |
53 } | |
54 | |
275
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
55 [Test] |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
56 public void PatrocinadorIndexGet() |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
57 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
58 var patrocinadorController = new PatrocinadorController(new HttpServerStub()) |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
59 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
60 ControllerContext = ControllerCtx |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
61 }; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
62 using (new RequestEmulator(NhHelper.GetSessionFactory())) |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
63 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
64 var resultIndex = patrocinadorController.Index(); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
65 Assert.IsInstanceOf(typeof(ViewResult), resultIndex); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
66 Assert.AreEqual("", ((ViewResult)resultIndex).ViewName); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
67 } |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
68 } |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
69 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
70 [Test] |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
71 public void PatrocinadorNuevoGet() |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
72 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
73 var patrocinadorController = new PatrocinadorController(new HttpServerStub()) |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
74 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
75 ControllerContext = ControllerCtx |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
76 }; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
77 using (new RequestEmulator(NhHelper.GetSessionFactory())) |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
78 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
79 var resultNuevo = patrocinadorController.Nuevo(); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
80 Assert.IsInstanceOf(typeof(ViewResult), resultNuevo); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
81 Assert.AreEqual("DefaultEditor", ((ViewResult)resultNuevo).ViewName); //UploadFileEditor |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
82 } |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
83 } |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
84 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
85 [Test] |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
86 public void PatrocinadorNuevoPostSatisfactorio() |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
87 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
88 var patrocinadorController = new PatrocinadorController(new HttpServerStub()) |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
89 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
90 ControllerContext = ControllerCtx |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
91 }; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
92 var form = new FormCollection |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
93 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
94 {"Nombre", "APRESS"}, |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
95 {"Logo", @"images\apress.gif"} |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
96 }; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
97 var patrocinadorNew = BindModel<PatrocinadorNewModel>(patrocinadorController, form); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
98 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
99 using (new RequestEmulator(NhHelper.GetSessionFactory())) |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
100 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
101 var resultNuevo = patrocinadorController.Nuevo(patrocinadorNew); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
102 Assert.IsInstanceOf(typeof(RedirectToRouteResult), resultNuevo); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
103 var viewResultNuevo = (RedirectToRouteResult)resultNuevo; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
104 Assert.AreEqual("Index", viewResultNuevo.RouteValues["action"]); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
105 } |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
106 } |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
107 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
108 [Test] |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
109 public void PatrocinadorNuevoPostRequiredFields() |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
110 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
111 var patrocinadorController = new PatrocinadorController(new HttpServerStub()) |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
112 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
113 ControllerContext = ControllerCtx |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
114 }; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
115 var form = new FormCollection |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
116 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
117 {"Nombre", ""}, |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
118 {"Logo", "" } |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
119 }; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
120 var patrocinadorNew = BindModel<PatrocinadorNewModel>(patrocinadorController, form); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
121 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
122 using (new RequestEmulator(NhHelper.GetSessionFactory())) |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
123 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
124 var resultNuevo = patrocinadorController.Nuevo(patrocinadorNew); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
125 Assert.IsInstanceOf(typeof(ViewResult), resultNuevo); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
126 var viewResultNuevo = (ViewResult)resultNuevo; |
278 | 127 Assert.AreEqual("DefaultEditor", viewResultNuevo.ViewName); |
275
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
128 Assert.AreEqual(1, viewResultNuevo.ViewData.ModelState["Nombre"].Errors.Count); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
129 Assert.AreEqual("El campo Nombre es obligatorio.", viewResultNuevo.ViewData.ModelState["Nombre"].Errors[0].ErrorMessage); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
130 Assert.AreEqual(1, viewResultNuevo.ViewData.ModelState["Logo"].Errors.Count); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
131 Assert.AreEqual("El campo Logo es obligatorio.", viewResultNuevo.ViewData.ModelState["Logo"].Errors[0].ErrorMessage); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
132 } |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
133 } |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
134 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
135 [Test] |
278 | 136 public void PatrocinadorNuevoPostExists() |
137 { | |
138 CrearPatrocinadorApress(); | |
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 { | |
279 | 164 |
278 | 165 var patrocinadorController = new PatrocinadorController(new HttpServerStub()) |
166 { | |
167 ControllerContext = ControllerCtx | |
168 }; | |
169 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
170 { | |
279 | 171 var patrocinadorRepository = new PatrocinadorRepository(NhHelper.GetSessionFactory()); |
172 Assert.AreEqual(0, patrocinadorRepository.GetAll().Count()); | |
278 | 173 var resultModificar = patrocinadorController.Modificar("11111111-1111-1111-1111-111111111111"); |
174 Assert.IsInstanceOf(typeof(RedirectToRouteResult), resultModificar); | |
175 Assert.AreEqual("Index", ((RedirectToRouteResult)resultModificar).RouteValues["action"]); | |
176 Assert.AreEqual("No se encontró el patrocinador que intenta modificar", patrocinadorController.TempData["error"]); | |
279 | 177 Assert.AreEqual(0, patrocinadorRepository.GetAll().Count()); |
278 | 178 } |
179 } | |
180 | |
181 [Test] | |
182 public void PatrocinadorModificarGetExists() | |
275
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
183 { |
278 | 184 CrearPatrocinadorApress(); |
275
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
185 |
278 | 186 var patrocinadorController = new PatrocinadorController(new HttpServerStub()) |
187 { | |
188 ControllerContext = ControllerCtx | |
189 }; | |
190 | |
191 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
192 { | |
193 var patrocinadorRepository = new PatrocinadorRepository(NhHelper.GetSessionFactory()); | |
194 var resultModificar = patrocinadorController.Modificar(patrocinadorRepository.GetAll().FirstOrDefault().Id.ToString()); | |
195 Assert.IsInstanceOf(typeof(ViewResult), resultModificar); | |
196 Assert.AreEqual("DefaultEditor", ((ViewResult)resultModificar).ViewName); | |
197 } | |
198 } | |
199 | |
200 [Test] | |
201 public void PatrocinadorModificarPostSatisfactorio() | |
202 { | |
279 | 203 PatrocinadorRepository patrocinadorRepository; |
278 | 204 PatrocinadorEditModel patrocinadorEdit; |
205 | |
206 CrearPatrocinadorApress(); | |
207 var patrocinadorController = new PatrocinadorController(new HttpServerStub()) | |
208 { | |
209 ControllerContext = ControllerCtx | |
210 }; | |
211 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
212 { | |
279 | 213 patrocinadorRepository = new PatrocinadorRepository(NhHelper.GetSessionFactory()); |
278 | 214 |
215 var form = new FormCollection | |
216 { | |
217 {"Id", patrocinadorRepository.GetAll().FirstOrDefault().Id.ToString()}, | |
218 {"Nombre", "APRESS"}, | |
219 {"Logo", @"images\apress.gif"} | |
220 }; | |
221 patrocinadorEdit = BindModel<PatrocinadorEditModel>(patrocinadorController, form); | |
222 } | |
223 | |
224 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
225 { | |
279 | 226 Assert.AreEqual(1, patrocinadorRepository.GetAll().Count()); |
278 | 227 var resultModificar = patrocinadorController.Modificar(patrocinadorEdit); |
228 Assert.IsInstanceOf(typeof(RedirectToRouteResult), resultModificar); | |
229 var viewResultEdit = (RedirectToRouteResult)resultModificar; | |
230 Assert.AreEqual("Index", viewResultEdit.RouteValues["action"]); | |
279 | 231 Assert.AreEqual(1, patrocinadorRepository.GetAll().Count()); |
278 | 232 } |
233 } | |
234 | |
235 [Test] | |
236 public void PatrocinadorModificarPostRequiredFields() | |
237 { | |
238 CrearPatrocinadorApress(); | |
239 var patrocinadorController = new PatrocinadorController(new HttpServerStub()) | |
240 { | |
241 ControllerContext = ControllerCtx | |
242 }; | |
243 var form = new FormCollection | |
244 { | |
245 {"Id", ""}, | |
246 {"Nombre", ""}, | |
247 {"Logo", ""} | |
248 }; | |
249 var patrocinadorEdit = BindModel<PatrocinadorEditModel>(patrocinadorController, form); | |
250 | |
251 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
252 { | |
253 var resultModificar = patrocinadorController.Modificar(patrocinadorEdit); | |
254 Assert.IsInstanceOf(typeof(ViewResult), resultModificar); | |
255 var viewResultNuevo = (ViewResult)resultModificar; | |
256 Assert.AreEqual("DefaultEditor", viewResultNuevo.ViewName); | |
257 Assert.AreEqual(1, viewResultNuevo.ViewData.ModelState["Nombre"].Errors.Count); | |
258 Assert.AreEqual("El campo Nombre es obligatorio.", viewResultNuevo.ViewData.ModelState["Nombre"].Errors[0].ErrorMessage); | |
259 Assert.AreEqual(1, viewResultNuevo.ViewData.ModelState["Logo"].Errors.Count); | |
260 Assert.AreEqual("El campo Logo es obligatorio.", viewResultNuevo.ViewData.ModelState["Logo"].Errors[0].ErrorMessage); | |
261 } | |
275
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
262 } |
279 | 263 |
264 [Test] | |
265 public void PatrocinadorQuitarPostSatisfactorio() | |
266 { | |
267 var patrocinadorId = string.Empty; | |
268 PatrocinadorRepository patrocinadorRepository; | |
269 | |
270 CrearPatrocinadorApress(); | |
271 var patrocinadorController = new PatrocinadorController(new HttpServerStub()) | |
272 { | |
273 ControllerContext = ControllerCtx | |
274 }; | |
275 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
276 { | |
277 patrocinadorRepository = new PatrocinadorRepository(NhHelper.GetSessionFactory()); | |
278 patrocinadorId = patrocinadorRepository.GetByNombre("Apress").Id.ToString(); | |
279 } | |
280 | |
281 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
282 { | |
283 Assert.AreEqual(1, patrocinadorRepository.GetAll().Count()); | |
284 var resultQuitar = patrocinadorController.Eliminar(patrocinadorId); | |
285 Assert.IsInstanceOf(typeof(RedirectToRouteResult), resultQuitar); | |
286 var viewResult = (RedirectToRouteResult)resultQuitar; | |
287 Assert.AreEqual("Index", viewResult.RouteValues["action"]); | |
288 } | |
289 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
290 { | |
291 Assert.AreEqual(0, patrocinadorRepository.GetAll().Count()); | |
292 } | |
293 } | |
294 | |
295 [Test] | |
296 [Ignore] | |
297 public void PatrocinadorQuitarPostDontExists() | |
298 { | |
299 PatrocinadorRepository patrocinadorRepository; | |
300 PatrocinadorEditModel patrocinadorEdit; | |
301 | |
302 CrearPatrocinadorApress(); | |
303 var patrocinadorController = new PatrocinadorController(new HttpServerStub()) | |
304 { | |
305 ControllerContext = ControllerCtx | |
306 }; | |
307 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
308 { | |
309 patrocinadorRepository = new PatrocinadorRepository(NhHelper.GetSessionFactory()); | |
310 | |
311 var form = new FormCollection | |
312 { | |
313 {"Id", patrocinadorRepository.GetAll().FirstOrDefault().Id.ToString()}, | |
314 {"Nombre", "APRESS"}, | |
315 {"Logo", @"images\apress.gif"} | |
316 }; | |
317 patrocinadorEdit = BindModel<PatrocinadorEditModel>(patrocinadorController, form); | |
318 } | |
319 | |
320 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
321 { | |
322 Assert.AreEqual(1, patrocinadorRepository.GetAll().Count()); | |
323 var resultQuit = patrocinadorController.Modificar(patrocinadorEdit); | |
324 Assert.IsInstanceOf(typeof(RedirectToRouteResult), resultQuit); | |
325 var viewResult = (RedirectToRouteResult)resultQuit; | |
326 Assert.AreEqual("Index", viewResult.RouteValues["action"]); | |
327 Assert.AreEqual(1, patrocinadorRepository.GetAll().Count()); | |
328 } | |
329 } | |
275
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
330 } |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
331 } |