view Agendas/trunk/src/Agendas.Web.Tests/Controllers/MvcControllerTestsBase.cs @ 263:3339d1da6a63

ControllerTests: Refactoring. Limpieza de cosas que no son necesarias.
author juanjose.montesdeocaarbos
date Sat, 22 Oct 2011 14:56:14 -0300
parents b87a4875b2b6
children 3bb779434ae8
line wrap: on
line source

using System.Web;
using System.Web.Mvc;
using Moq;

namespace Agendas.Web.Tests.Controllers
{
    public class MvcControllerTestsBase
    {
        protected readonly ControllerContext ControllerCtx = new ControllerContext();

        protected static TModel BindModel<TModel>(Controller controller, IValueProvider valueProvider) where TModel : class
        {
            var binder = ModelBinders.Binders.GetBinder(typeof(TModel));
            var bindingContext = new ModelBindingContext()
            {
                FallbackToEmptyPrefix = true,
                ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(null, typeof(TModel)),
                ModelName = "NotUsedButNotNull",
                ModelState = controller.ModelState,
                PropertyFilter = (name => true),
                ValueProvider = valueProvider
            };

            return (TModel)binder.BindModel(controller.ControllerContext, bindingContext);
        }
    }
}