comparison Agendas/trunk/src/Agendas.Web.Tests/Controllers/EventoControllerTests.cs @ 283:2e17dfd1ba35

Cambiandos espacios por tabuladores, etc.
author juanjose.montesdeocaarbos
date Mon, 26 Dec 2011 14:34:46 -0300
parents d255b0621503
children 79942e030118
comparison
equal deleted inserted replaced
282:bc8dfbde0523 283:2e17dfd1ba35
12 using NUnit.Framework; 12 using NUnit.Framework;
13 13
14 namespace Agendas.Web.Tests.Controllers 14 namespace Agendas.Web.Tests.Controllers
15 { 15 {
16 [TestFixture] 16 [TestFixture]
17 public class EventoControllerTests: MvcControllerTestsBase 17 public class EventoControllerTests : MvcControllerTestsBase
18 { 18 {
19 private void PopulatePersona() 19 private void PopulatePersona()
20 { 20 {
21 using (new RequestEmulator(NhHelper.GetSessionFactory())) 21 using (new RequestEmulator(NhHelper.GetSessionFactory()))
22 { 22 {
23 var personaController = new PersonaController(); 23 var personaController = new PersonaController();
24 personaController.Nueva(new PersonaNewModel 24 personaController.Nueva(new PersonaNewModel
25 { 25 {
26 Nombre = "Persona 1", 26 Nombre = "Persona 1",
27 Blog = "http://blog.persona1.com", 27 Blog = "http://blog.persona1.com",
28 EMail = "info@persona1.com", 28 EMail = "info@persona1.com",
29 Roles = new string[] {"Administrador", "Usuario"}, 29 Roles = new string[] { "Administrador", "Usuario" },
30 Twitter = "persona1" 30 Twitter = "persona1"
31 }); 31 });
32 } 32 }
33 } 33 }
34 34
35 private Guid GetGuidPersona() 35 private Guid GetGuidPersona()
36 { 36 {
37 using (new RequestEmulator(NhHelper.GetSessionFactory())) 37 using (new RequestEmulator(NhHelper.GetSessionFactory()))
38 { 38 {
39 var personaController = new PersonaController(); 39 var personaController = new PersonaController();
40 var viewResult = (ViewResult) personaController.Index(); 40 var viewResult = (ViewResult)personaController.Index();
41 return ((PersonaIndexModel) viewResult.Model).Items.FirstOrDefault().Id; 41 return ((PersonaIndexModel)viewResult.Model).Items.FirstOrDefault().Id;
42 } 42 }
43 } 43 }
44 44
45 private void SetearUsuario() 45 private void SetearUsuario()
46 { 46 {
47 var seguridad = new Mock<ISeguridad>(); 47 var seguridad = new Mock<ISeguridad>();
48 seguridad.Setup(s => s.GetUserName()).Returns("neluz"); 48 seguridad.Setup(s => s.GetUserName()).Returns("neluz");
49 IdentityContext.Init(seguridad.Object, new PersonaRepository(NhHelper.GetSessionFactory())); 49 IdentityContext.Init(seguridad.Object, new PersonaRepository(NhHelper.GetSessionFactory()));
50 } 50 }
51 51
52 [SetUp] 52 [SetUp]
53 public void Setup() 53 public void Setup()
54 { 54 {
55 NhHelperTest.CleanDb(); 55 NhHelperTest.CleanDb();
56 PopulatePersona(); 56 PopulatePersona();
57 SetearUsuario(); 57 SetearUsuario();
58 } 58 }
59 59
60 [Test] 60 [Test]
61 public void Nuevo_Evento() 61 public void Nuevo_Evento()
62 { 62 {
63 //ViewResult viewResult = null; 63 //ViewResult viewResult = null;
64 //IEnumerable<EventoDto> eventosDto = null; 64 //IEnumerable<EventoDto> eventosDto = null;
65 //EventoPublicarModel eventoPublicar = null; 65 //EventoPublicarModel eventoPublicar = null;
66 var eventoController = new EventoController { ControllerContext = ControllerCtx }; 66 var eventoController = new EventoController { ControllerContext = ControllerCtx };
67 var form = new FormCollection 67 var form = new FormCollection
68 { 68 {
69 {"Duracion", (new TimeSpan(0, 0, 0)).ToString()}, 69 {"Duracion", (new TimeSpan(0, 0, 0)).ToString()},
70 {"Fecha", (DateTime.Today.AddDays(15)).ToString()}, 70 {"Fecha", (DateTime.Today.AddDays(15)).ToString()},
71 {"Hora", (new TimeSpan(18, 0, 0)).ToString()}, 71 {"Hora", (new TimeSpan(18, 0, 0)).ToString()},
72 {"Ponentes", GetGuidPersona().ToString()}, 72 {"Ponentes", GetGuidPersona().ToString()},
73 {"TipoEvento", ((int)TipoEvento.Van).ToString()}, 73 {"TipoEvento", ((int)TipoEvento.Van).ToString()},
74 {"Titulo", "Título"} 74 {"Titulo", "Título"}
75 }; 75 };
76 var eventoNew = BindModel<EventoNewModel>(eventoController, form); 76 var eventoNew = BindModel<EventoNewModel>(eventoController, form);
77 77
78 using (new RequestEmulator(NhHelper.GetSessionFactory())) 78 using (new RequestEmulator(NhHelper.GetSessionFactory()))
79 { 79 {
80 var resultNuevo = eventoController.Nuevo(eventoNew); 80 var resultNuevo = eventoController.Nuevo(eventoNew);
81 Assert.IsInstanceOf(typeof(RedirectToRouteResult), resultNuevo); 81 Assert.IsInstanceOf(typeof(RedirectToRouteResult), resultNuevo);
82 Assert.AreEqual("Index", ((RedirectToRouteResult) resultNuevo).RouteValues["action"]); 82 Assert.AreEqual("Index", ((RedirectToRouteResult)resultNuevo).RouteValues["action"]);
83 } 83 }
84 } 84 }
85 85
86 [Test] 86 [Test]
87 public void Nuevo_Evento_Erroneo_Sin_Ponente() 87 public void Nuevo_Evento_Erroneo_Sin_Ponente()
88 { 88 {
89 //ViewResult viewResult = null; 89 //ViewResult viewResult = null;
90 //IEnumerable<EventoDto> eventosDto = null; 90 //IEnumerable<EventoDto> eventosDto = null;
91 //EventoPublicarModel eventoPublicar = null; 91 //EventoPublicarModel eventoPublicar = null;
92 var eventoController = new EventoController { ControllerContext = ControllerCtx }; 92 var eventoController = new EventoController { ControllerContext = ControllerCtx };
93 var form = new FormCollection 93 var form = new FormCollection
94 { 94 {
95 {"Duracion", (new TimeSpan(0, 0, 0)).ToString()}, 95 {"Duracion", (new TimeSpan(0, 0, 0)).ToString()},
96 {"Fecha", (DateTime.Today.AddDays(15)).ToString()}, 96 {"Fecha", (DateTime.Today.AddDays(15)).ToString()},
97 {"Hora", (new TimeSpan(18, 0, 0)).ToString()}, 97 {"Hora", (new TimeSpan(18, 0, 0)).ToString()},
98 {"TipoEvento", ((int)TipoEvento.Van).ToString()}, 98 {"TipoEvento", ((int)TipoEvento.Van).ToString()},
99 {"Titulo", "Título"} 99 {"Titulo", "Título"}
100 }; 100 };
101 var eventoNew = BindModel<EventoNewModel>(eventoController, form); 101 var eventoNew = BindModel<EventoNewModel>(eventoController, form);
102 102
103 using (new RequestEmulator(NhHelper.GetSessionFactory())) 103 using (new RequestEmulator(NhHelper.GetSessionFactory()))
104 { 104 {
105 var resultNuevo = (ViewResult)eventoController.Nuevo(eventoNew); 105 var resultNuevo = (ViewResult)eventoController.Nuevo(eventoNew);
106 var modelState = resultNuevo.ViewData.ModelState; 106 var modelState = resultNuevo.ViewData.ModelState;
107 Assert.AreEqual(1, modelState[string.Empty].Errors.Count); 107 Assert.AreEqual(1, modelState[string.Empty].Errors.Count);
108 Assert.AreEqual("Debe indicar el ponente para este tipo de evento", modelState[string.Empty].Errors.FirstOrDefault().ErrorMessage); 108 Assert.AreEqual("Debe indicar el ponente para este tipo de evento", modelState[string.Empty].Errors.FirstOrDefault().ErrorMessage);
109 } 109 }
110 } 110 }
111 111
112 [Test] 112 [Test]
113 public void Publicar_Evento_Erroneo_Duracion_Fuera_Rango() 113 public void Publicar_Evento_Erroneo_Duracion_Fuera_Rango()
114 { 114 {
115 ViewResult viewResult = null; 115 ViewResult viewResult = null;
116 IEnumerable<EventoDto> eventosDto = null; 116 IEnumerable<EventoDto> eventosDto = null;
117 EventoPublicarModel eventoPublicar = null; 117 EventoPublicarModel eventoPublicar = null;
118 var eventoController = new EventoController { ControllerContext = ControllerCtx }; 118 var eventoController = new EventoController { ControllerContext = ControllerCtx };
119 var formEvento = new FormCollection 119 var formEvento = new FormCollection
120 { 120 {
121 {"Duracion", (new TimeSpan(0, 0, 0)).ToString()}, 121 {"Duracion", (new TimeSpan(0, 0, 0)).ToString()},
122 {"Fecha", (DateTime.Today.AddDays(15)).ToString()}, 122 {"Fecha", (DateTime.Today.AddDays(15)).ToString()},
123 {"Hora", (new TimeSpan(18, 0, 0)).ToString()}, 123 {"Hora", (new TimeSpan(18, 0, 0)).ToString()},
124 {"Ponentes", GetGuidPersona().ToString()}, 124 {"Ponentes", GetGuidPersona().ToString()},
125 {"TipoEvento", ((int)TipoEvento.Van).ToString()}, 125 {"TipoEvento", ((int)TipoEvento.Van).ToString()},
126 {"Titulo", "Título 2"} 126 {"Titulo", "Título 2"}
127 }; 127 };
128 var eventoNew = BindModel<EventoNewModel>(eventoController, formEvento); 128 var eventoNew = BindModel<EventoNewModel>(eventoController, formEvento);
129 129
130 using (new RequestEmulator(NhHelper.GetSessionFactory())) 130 using (new RequestEmulator(NhHelper.GetSessionFactory()))
131 { 131 {
132 eventoController.Nuevo(eventoNew); 132 eventoController.Nuevo(eventoNew);
133 } 133 }
134 using (new RequestEmulator(NhHelper.GetSessionFactory())) 134 using (new RequestEmulator(NhHelper.GetSessionFactory()))
135 { 135 {
136 viewResult = (ViewResult)eventoController.Index(); 136 viewResult = (ViewResult)eventoController.Index();
137 } 137 }
138 using (new RequestEmulator(NhHelper.GetSessionFactory())) 138 using (new RequestEmulator(NhHelper.GetSessionFactory()))
139 { 139 {
140 eventosDto = ((EventoIndexModel) viewResult.Model).ProximosEventos; 140 eventosDto = ((EventoIndexModel)viewResult.Model).ProximosEventos;
141 } 141 }
142 using (new RequestEmulator(NhHelper.GetSessionFactory())) 142 using (new RequestEmulator(NhHelper.GetSessionFactory()))
143 { 143 {
144 var firstEvent = eventosDto.LastOrDefault(); 144 var firstEvent = eventosDto.LastOrDefault();
145 var formPublicar = new FormCollection 145 var formPublicar = new FormCollection
146 { 146 {
147 {"Id", (firstEvent.Id).ToString()}, 147 {"Id", (firstEvent.Id).ToString()},
148 {"Titulo", "Título 2"}, 148 {"Titulo", "Título 2"},
149 {"NroOrden", "1"}, 149 {"NroOrden", "1"},
150 {"UrlWiki", "http://www.altnethistpano.org/vans/titulo-1.ashx"}, 150 {"UrlWiki", "http://www.altnethistpano.org/vans/titulo-1.ashx"},
151 {"DuracionReal", (new TimeSpan(0, 0, 0)).ToString()} 151 {"DuracionReal", (new TimeSpan(0, 0, 0)).ToString()}
152 }; 152 };
153 eventoPublicar = BindModel<EventoPublicarModel>(eventoController, formPublicar); 153 eventoPublicar = BindModel<EventoPublicarModel>(eventoController, formPublicar);
154 } 154 }
155 using (new RequestEmulator(NhHelper.GetSessionFactory())) 155 using (new RequestEmulator(NhHelper.GetSessionFactory()))
156 { 156 {
157 var resultPublicar = (ViewResult)eventoController.Publicar(eventoPublicar); 157 var resultPublicar = (ViewResult)eventoController.Publicar(eventoPublicar);
158 var modelState = resultPublicar.ViewData.ModelState; 158 var modelState = resultPublicar.ViewData.ModelState;
159 159
160 Assert.AreEqual(1, modelState[string.Empty].Errors.Count); 160 Assert.AreEqual(1, modelState[string.Empty].Errors.Count);
161 Assert.AreEqual("Duración fuera de rango", modelState[string.Empty].Errors.FirstOrDefault().ErrorMessage); 161 Assert.AreEqual("Duración fuera de rango", modelState[string.Empty].Errors.FirstOrDefault().ErrorMessage);
162 162
163 } 163 }
164 } 164 }
165 } 165 }
166 166
167 } 167 }