diff Agendas/trunk/src/Agendas.Web.Tests/Controllers/PatrocinadorControllerTests.cs @ 275:bf993f99cee3

Ticket #123: Patrocinadores de las vans.
author juanjose.montesdeocaarbos
date Wed, 14 Dec 2011 08:15:44 -0300
parents
children 6f5ab71614d4
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Agendas/trunk/src/Agendas.Web.Tests/Controllers/PatrocinadorControllerTests.cs	Wed Dec 14 08:15:44 2011 -0300
@@ -0,0 +1,117 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Web;
+using System.Web.Mvc;
+using System.Web.Routing;
+using Agendas.NHibernate;
+using Agendas.Repositories.Tests.Infraestructure;
+using Agendas.Web.Tests.Helpers;
+using AltNetHispano.Agendas.Web.Controllers;
+using AltNetHispano.Agendas.Web.Models;
+using Moq;
+using NUnit.Framework;
+using System.Drawing;
+
+namespace Agendas.Web.Tests.Controllers
+{
+	[TestFixture]
+	public class PatrocinadorControllerTests : MvcControllerTestsBase
+	{
+		[SetUp]
+		public void RegisterBinders()
+		{
+			ModelBinders.Binders[typeof(HttpPostedFileBase)] = new HttpPostedFileBaseModelBinder();
+		}
+
+		[Test]
+		public void PatrocinadorIndexGet()
+		{
+			var patrocinadorController = new PatrocinadorController(new HttpServerStub())
+			                             	{
+			                             		ControllerContext = ControllerCtx
+			                             	};
+			using (new RequestEmulator(NhHelper.GetSessionFactory()))
+			{
+				var resultIndex = patrocinadorController.Index();
+				Assert.IsInstanceOf(typeof(ViewResult), resultIndex);
+				Assert.AreEqual("", ((ViewResult)resultIndex).ViewName);
+			}
+		}
+
+		[Test]
+		public void PatrocinadorNuevoGet()
+		{
+			var patrocinadorController = new PatrocinadorController(new HttpServerStub())
+			                             	{
+			                             		ControllerContext = ControllerCtx
+			                             	};
+			using (new RequestEmulator(NhHelper.GetSessionFactory()))
+			{
+				var resultNuevo = patrocinadorController.Nuevo();
+				Assert.IsInstanceOf(typeof(ViewResult), resultNuevo);
+				Assert.AreEqual("DefaultEditor", ((ViewResult)resultNuevo).ViewName); //UploadFileEditor
+			}
+		}
+
+		[Test]
+		public void PatrocinadorNuevoPostSatisfactorio()
+		{
+			var patrocinadorController = new PatrocinadorController(new HttpServerStub())
+			                             	{
+			                             		ControllerContext = ControllerCtx
+			                             	};
+			var form = new FormCollection
+                           {
+                               {"Nombre", "APRESS"},
+							   {"Logo", @"images\apress.gif"}
+                           };
+			var patrocinadorNew = BindModel<PatrocinadorNewModel>(patrocinadorController, form);
+
+			using (new RequestEmulator(NhHelper.GetSessionFactory()))
+			{
+				var resultNuevo = patrocinadorController.Nuevo(patrocinadorNew);
+				Assert.IsInstanceOf(typeof(RedirectToRouteResult), resultNuevo);
+				var viewResultNuevo = (RedirectToRouteResult)resultNuevo;
+				Assert.AreEqual("Index", viewResultNuevo.RouteValues["action"]);
+			}
+		}
+
+		[Test]
+		public void PatrocinadorNuevoPostRequiredFields()
+		{
+			var patrocinadorController = new PatrocinadorController(new HttpServerStub())
+			                             	{
+			                             		ControllerContext = ControllerCtx
+			                             	};
+			var form = new FormCollection
+                           {
+                               {"Nombre", ""},
+                               {"Logo", "" }
+                           };
+			var patrocinadorNew = BindModel<PatrocinadorNewModel>(patrocinadorController, form);
+
+			using (new RequestEmulator(NhHelper.GetSessionFactory()))
+			{
+				var resultNuevo = patrocinadorController.Nuevo(patrocinadorNew);
+				Assert.IsInstanceOf(typeof(ViewResult), resultNuevo);
+				var viewResultNuevo = (ViewResult)resultNuevo;
+				Assert.AreEqual("DefaultEditor", viewResultNuevo.ViewName); //UploadFileEditor
+				Assert.AreEqual(1, viewResultNuevo.ViewData.ModelState["Nombre"].Errors.Count);
+				Assert.AreEqual("El campo Nombre es obligatorio.", viewResultNuevo.ViewData.ModelState["Nombre"].Errors[0].ErrorMessage);
+				Assert.AreEqual(1, viewResultNuevo.ViewData.ModelState["Logo"].Errors.Count);
+				Assert.AreEqual("El campo Logo es obligatorio.", viewResultNuevo.ViewData.ModelState["Logo"].Errors[0].ErrorMessage);
+			}
+		}
+
+		[Test]
+		[Ignore]
+		public void PatrocinadorNuevoPostExistente()
+		{
+
+		}
+	}
+
+}