Mercurial > altnet-hispano
annotate Agendas/trunk/src/Agendas.Web.Tests/Controllers/PatrocinadorControllerTests.cs @ 302:11dddcc9a862 tip
Historico de Eventos, no muestra bien la Url del Patrocinador.
author | juanjose.montesdeocaarbos |
---|---|
date | Tue, 14 Aug 2012 21:54:30 -0300 |
parents | 48ab8788bd19 |
children |
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"}, | |
300
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
279
diff
changeset
|
33 {"WebSite", "http://apress.com/"}, |
278 | 34 {"Logo", @"images\apress.gif"} |
35 }; | |
36 var patrocinadorNew = BindModel<PatrocinadorNewModel>(patrocinadorController, form); | |
37 | |
38 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
39 { | |
40 var resultNuevo = patrocinadorController.Nuevo(patrocinadorNew); | |
41 } | |
42 } | |
43 | |
44 internal void RegisterBinders() | |
275
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
45 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
46 ModelBinders.Binders[typeof(HttpPostedFileBase)] = new HttpPostedFileBaseModelBinder(); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
47 } |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
48 |
278 | 49 [SetUp] |
50 public void SetUpTests() | |
51 { | |
52 NhHelperTest.CleanDb(); | |
53 RegisterBinders(); | |
54 } | |
55 | |
275
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
56 [Test] |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
57 public void PatrocinadorIndexGet() |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
58 { |
300
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
279
diff
changeset
|
59 CrearPatrocinadorApress(); |
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
279
diff
changeset
|
60 |
275
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
61 var patrocinadorController = new PatrocinadorController(new HttpServerStub()) |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
62 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
63 ControllerContext = ControllerCtx |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
64 }; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
65 using (new RequestEmulator(NhHelper.GetSessionFactory())) |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
66 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
67 var resultIndex = patrocinadorController.Index(); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
68 Assert.IsInstanceOf(typeof(ViewResult), resultIndex); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
69 Assert.AreEqual("", ((ViewResult)resultIndex).ViewName); |
300
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
279
diff
changeset
|
70 |
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
279
diff
changeset
|
71 var model = (PatrocinadorIndexModel)((ViewResult) resultIndex).Model; |
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
279
diff
changeset
|
72 Assert.AreEqual(1, model.Items.Count()); |
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
279
diff
changeset
|
73 |
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
279
diff
changeset
|
74 Assert.AreEqual("APRESS", model.Items.FirstOrDefault().Nombre); |
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
279
diff
changeset
|
75 Assert.AreEqual("http://apress.com/", model.Items.FirstOrDefault().WebSite); |
275
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 } |
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 [Test] |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
80 public void PatrocinadorNuevoGet() |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
81 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
82 var patrocinadorController = new PatrocinadorController(new HttpServerStub()) |
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 ControllerContext = ControllerCtx |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
85 }; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
86 using (new RequestEmulator(NhHelper.GetSessionFactory())) |
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 resultNuevo = patrocinadorController.Nuevo(); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
89 Assert.IsInstanceOf(typeof(ViewResult), resultNuevo); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
90 Assert.AreEqual("DefaultEditor", ((ViewResult)resultNuevo).ViewName); //UploadFileEditor |
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 } |
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 [Test] |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
95 public void PatrocinadorNuevoPostSatisfactorio() |
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 patrocinadorController = new PatrocinadorController(new HttpServerStub()) |
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 ControllerContext = ControllerCtx |
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 form = new FormCollection |
300
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
279
diff
changeset
|
102 { |
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
279
diff
changeset
|
103 {"Nombre", "APRESS"}, |
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
279
diff
changeset
|
104 {"WebSite", "http://apress.com/"}, |
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
279
diff
changeset
|
105 {"Logo", @"images\apress.gif"} |
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
279
diff
changeset
|
106 }; |
275
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
107 var patrocinadorNew = BindModel<PatrocinadorNewModel>(patrocinadorController, form); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
108 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
109 using (new RequestEmulator(NhHelper.GetSessionFactory())) |
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 resultNuevo = patrocinadorController.Nuevo(patrocinadorNew); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
112 Assert.IsInstanceOf(typeof(RedirectToRouteResult), resultNuevo); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
113 var viewResultNuevo = (RedirectToRouteResult)resultNuevo; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
114 Assert.AreEqual("Index", viewResultNuevo.RouteValues["action"]); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
115 } |
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 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
118 [Test] |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
119 public void PatrocinadorNuevoPostRequiredFields() |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
120 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
121 var patrocinadorController = new PatrocinadorController(new HttpServerStub()) |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
122 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
123 ControllerContext = ControllerCtx |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
124 }; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
125 var form = new FormCollection |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
126 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
127 {"Nombre", ""}, |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
128 {"Logo", "" } |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
129 }; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
130 var patrocinadorNew = BindModel<PatrocinadorNewModel>(patrocinadorController, form); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
131 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
132 using (new RequestEmulator(NhHelper.GetSessionFactory())) |
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 var resultNuevo = patrocinadorController.Nuevo(patrocinadorNew); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
135 Assert.IsInstanceOf(typeof(ViewResult), resultNuevo); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
136 var viewResultNuevo = (ViewResult)resultNuevo; |
278 | 137 Assert.AreEqual("DefaultEditor", viewResultNuevo.ViewName); |
275
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
138 Assert.AreEqual(1, viewResultNuevo.ViewData.ModelState["Nombre"].Errors.Count); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
139 Assert.AreEqual("El campo Nombre es obligatorio.", viewResultNuevo.ViewData.ModelState["Nombre"].Errors[0].ErrorMessage); |
300
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
279
diff
changeset
|
140 Assert.AreEqual(1, viewResultNuevo.ViewData.ModelState["Nombre"].Errors.Count); |
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
279
diff
changeset
|
141 Assert.AreEqual("El campo WebSite es obligatorio.", viewResultNuevo.ViewData.ModelState["WebSite"].Errors[0].ErrorMessage); |
275
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
142 Assert.AreEqual(1, viewResultNuevo.ViewData.ModelState["Logo"].Errors.Count); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
143 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
|
144 } |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
145 } |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
146 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
147 [Test] |
278 | 148 public void PatrocinadorNuevoPostExists() |
149 { | |
150 CrearPatrocinadorApress(); | |
151 | |
152 var patrocinadorController = new PatrocinadorController(new HttpServerStub()) | |
153 { | |
154 ControllerContext = ControllerCtx | |
155 }; | |
156 var form = new FormCollection | |
157 { | |
158 {"Nombre", "APRESS"}, | |
300
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
279
diff
changeset
|
159 {"WebSite", "http://apress.com/"}, |
278 | 160 {"Logo", @"images\apress.gif"} |
161 }; | |
162 var patrocinadorNew = BindModel<PatrocinadorNewModel>(patrocinadorController, form); | |
163 | |
164 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
165 { | |
166 var resultNuevo = patrocinadorController.Nuevo(patrocinadorNew); | |
167 Assert.IsInstanceOf(typeof (ViewResult), resultNuevo); | |
168 var viewResultNuevo = (ViewResult) resultNuevo; | |
169 | |
170 Assert.AreEqual("El patrocinador ya existe.", viewResultNuevo.TempData["error"]); | |
171 } | |
172 } | |
173 | |
174 [Test] | |
175 public void PatrocinadorModificarGetDontExists() | |
176 { | |
279 | 177 |
278 | 178 var patrocinadorController = new PatrocinadorController(new HttpServerStub()) |
179 { | |
180 ControllerContext = ControllerCtx | |
181 }; | |
182 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
183 { | |
279 | 184 var patrocinadorRepository = new PatrocinadorRepository(NhHelper.GetSessionFactory()); |
185 Assert.AreEqual(0, patrocinadorRepository.GetAll().Count()); | |
278 | 186 var resultModificar = patrocinadorController.Modificar("11111111-1111-1111-1111-111111111111"); |
187 Assert.IsInstanceOf(typeof(RedirectToRouteResult), resultModificar); | |
188 Assert.AreEqual("Index", ((RedirectToRouteResult)resultModificar).RouteValues["action"]); | |
189 Assert.AreEqual("No se encontró el patrocinador que intenta modificar", patrocinadorController.TempData["error"]); | |
279 | 190 Assert.AreEqual(0, patrocinadorRepository.GetAll().Count()); |
278 | 191 } |
192 } | |
193 | |
194 [Test] | |
195 public void PatrocinadorModificarGetExists() | |
275
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
196 { |
278 | 197 CrearPatrocinadorApress(); |
275
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
198 |
278 | 199 var patrocinadorController = new PatrocinadorController(new HttpServerStub()) |
200 { | |
201 ControllerContext = ControllerCtx | |
202 }; | |
203 | |
204 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
205 { | |
206 var patrocinadorRepository = new PatrocinadorRepository(NhHelper.GetSessionFactory()); | |
207 var resultModificar = patrocinadorController.Modificar(patrocinadorRepository.GetAll().FirstOrDefault().Id.ToString()); | |
208 Assert.IsInstanceOf(typeof(ViewResult), resultModificar); | |
209 Assert.AreEqual("DefaultEditor", ((ViewResult)resultModificar).ViewName); | |
210 } | |
211 } | |
212 | |
213 [Test] | |
214 public void PatrocinadorModificarPostSatisfactorio() | |
215 { | |
300
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
279
diff
changeset
|
216 var Id = Guid.Empty; |
279 | 217 PatrocinadorRepository patrocinadorRepository; |
278 | 218 PatrocinadorEditModel patrocinadorEdit; |
219 | |
220 CrearPatrocinadorApress(); | |
221 var patrocinadorController = new PatrocinadorController(new HttpServerStub()) | |
222 { | |
223 ControllerContext = ControllerCtx | |
224 }; | |
225 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
226 { | |
279 | 227 patrocinadorRepository = new PatrocinadorRepository(NhHelper.GetSessionFactory()); |
300
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
279
diff
changeset
|
228 Id = patrocinadorRepository.GetAll().FirstOrDefault().Id; |
278 | 229 var form = new FormCollection |
300
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
279
diff
changeset
|
230 { |
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
279
diff
changeset
|
231 {"Id", Id.ToString()}, |
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
279
diff
changeset
|
232 {"Nombre", "APRESS2"}, |
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
279
diff
changeset
|
233 {"WebSite", "http://apress.com/2"}, |
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
279
diff
changeset
|
234 {"Logo", @"images\apress.gif"} |
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
279
diff
changeset
|
235 }; |
278 | 236 patrocinadorEdit = BindModel<PatrocinadorEditModel>(patrocinadorController, form); |
237 } | |
238 | |
239 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
240 { | |
279 | 241 Assert.AreEqual(1, patrocinadorRepository.GetAll().Count()); |
278 | 242 var resultModificar = patrocinadorController.Modificar(patrocinadorEdit); |
243 Assert.IsInstanceOf(typeof(RedirectToRouteResult), resultModificar); | |
244 var viewResultEdit = (RedirectToRouteResult)resultModificar; | |
245 Assert.AreEqual("Index", viewResultEdit.RouteValues["action"]); | |
279 | 246 Assert.AreEqual(1, patrocinadorRepository.GetAll().Count()); |
278 | 247 } |
300
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
279
diff
changeset
|
248 using (new RequestEmulator(NhHelper.GetSessionFactory())) |
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
279
diff
changeset
|
249 { |
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
279
diff
changeset
|
250 var patrocinador = patrocinadorRepository.GetById(Id.ToString()); |
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
279
diff
changeset
|
251 |
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
279
diff
changeset
|
252 Assert.AreEqual("APRESS2", patrocinador.Nombre); |
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
279
diff
changeset
|
253 Assert.AreEqual("http://apress.com/2", patrocinador.WebSite); |
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
279
diff
changeset
|
254 } |
278 | 255 } |
256 | |
257 [Test] | |
258 public void PatrocinadorModificarPostRequiredFields() | |
259 { | |
260 CrearPatrocinadorApress(); | |
261 var patrocinadorController = new PatrocinadorController(new HttpServerStub()) | |
262 { | |
263 ControllerContext = ControllerCtx | |
264 }; | |
265 var form = new FormCollection | |
266 { | |
267 {"Id", ""}, | |
268 {"Nombre", ""}, | |
269 {"Logo", ""} | |
270 }; | |
271 var patrocinadorEdit = BindModel<PatrocinadorEditModel>(patrocinadorController, form); | |
272 | |
273 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
274 { | |
275 var resultModificar = patrocinadorController.Modificar(patrocinadorEdit); | |
276 Assert.IsInstanceOf(typeof(ViewResult), resultModificar); | |
277 var viewResultNuevo = (ViewResult)resultModificar; | |
278 Assert.AreEqual("DefaultEditor", viewResultNuevo.ViewName); | |
279 Assert.AreEqual(1, viewResultNuevo.ViewData.ModelState["Nombre"].Errors.Count); | |
280 Assert.AreEqual("El campo Nombre es obligatorio.", viewResultNuevo.ViewData.ModelState["Nombre"].Errors[0].ErrorMessage); | |
281 Assert.AreEqual(1, viewResultNuevo.ViewData.ModelState["Logo"].Errors.Count); | |
282 Assert.AreEqual("El campo Logo es obligatorio.", viewResultNuevo.ViewData.ModelState["Logo"].Errors[0].ErrorMessage); | |
283 } | |
275
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
284 } |
279 | 285 |
286 [Test] | |
287 public void PatrocinadorQuitarPostSatisfactorio() | |
288 { | |
289 var patrocinadorId = string.Empty; | |
290 PatrocinadorRepository patrocinadorRepository; | |
291 | |
292 CrearPatrocinadorApress(); | |
293 var patrocinadorController = new PatrocinadorController(new HttpServerStub()) | |
294 { | |
295 ControllerContext = ControllerCtx | |
296 }; | |
297 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
298 { | |
299 patrocinadorRepository = new PatrocinadorRepository(NhHelper.GetSessionFactory()); | |
300 patrocinadorId = patrocinadorRepository.GetByNombre("Apress").Id.ToString(); | |
301 } | |
302 | |
303 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
304 { | |
305 Assert.AreEqual(1, patrocinadorRepository.GetAll().Count()); | |
306 var resultQuitar = patrocinadorController.Eliminar(patrocinadorId); | |
307 Assert.IsInstanceOf(typeof(RedirectToRouteResult), resultQuitar); | |
308 var viewResult = (RedirectToRouteResult)resultQuitar; | |
309 Assert.AreEqual("Index", viewResult.RouteValues["action"]); | |
310 } | |
311 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
312 { | |
313 Assert.AreEqual(0, patrocinadorRepository.GetAll().Count()); | |
314 } | |
315 } | |
316 | |
317 [Test] | |
318 [Ignore] | |
319 public void PatrocinadorQuitarPostDontExists() | |
320 { | |
321 PatrocinadorRepository patrocinadorRepository; | |
322 PatrocinadorEditModel patrocinadorEdit; | |
323 | |
324 CrearPatrocinadorApress(); | |
325 var patrocinadorController = new PatrocinadorController(new HttpServerStub()) | |
326 { | |
327 ControllerContext = ControllerCtx | |
328 }; | |
329 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
330 { | |
331 patrocinadorRepository = new PatrocinadorRepository(NhHelper.GetSessionFactory()); | |
332 | |
333 var form = new FormCollection | |
334 { | |
335 {"Id", patrocinadorRepository.GetAll().FirstOrDefault().Id.ToString()}, | |
336 {"Nombre", "APRESS"}, | |
337 {"Logo", @"images\apress.gif"} | |
338 }; | |
339 patrocinadorEdit = BindModel<PatrocinadorEditModel>(patrocinadorController, form); | |
340 } | |
341 | |
342 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
343 { | |
344 Assert.AreEqual(1, patrocinadorRepository.GetAll().Count()); | |
345 var resultQuit = patrocinadorController.Modificar(patrocinadorEdit); | |
346 Assert.IsInstanceOf(typeof(RedirectToRouteResult), resultQuit); | |
347 var viewResult = (RedirectToRouteResult)resultQuit; | |
348 Assert.AreEqual("Index", viewResult.RouteValues["action"]); | |
349 Assert.AreEqual(1, patrocinadorRepository.GetAll().Count()); | |
350 } | |
351 } | |
275
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
352 } |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
353 } |