public void Invalid_DataToken_Model_Type_Returns_Null()
        {
            var binder    = new RenderModelBinder();
            var routeData = new RouteData();

            routeData.DataTokens[Core.Constants.Web.UmbracoDataToken] = "hello";

            //the value provider is the default implementation
            var valueProvider = new Mock <IValueProvider>();
            //also IUnvalidatedValueProvider
            var invalidatedValueProvider = valueProvider.As <IUnvalidatedValueProvider>();

            invalidatedValueProvider.Setup(x => x.GetValue(It.IsAny <string>(), It.IsAny <bool>())).Returns(() =>
                                                                                                            new ValueProviderResult(null, "", CultureInfo.CurrentCulture));

            var controllerCtx = new ControllerContext(
                Mock.Of <HttpContextBase>(http => http.Items == new Dictionary <object, object>()),
                routeData,
                Mock.Of <ControllerBase>());

            var result = binder.BindModel(controllerCtx,
                                          new ModelBindingContext
            {
                ValueProvider = valueProvider.Object,
                ModelMetadata = new ModelMetadata(new EmptyModelMetadataProvider(), null, () => null, typeof(IPublishedContent), "content")
            });

            Assert.IsNull(result);
        }
        public void BindModel_Returns_If_Same_Type()
        {
            var content = new MyContent(Mock.Of <IPublishedContent>());
            var bound   = RenderModelBinder.BindModel(content, typeof(IPublishedContent), CultureInfo.CurrentCulture);

            Assert.AreSame(content, bound);
        }
        public void BindModel_IPublishedContent_To_Generic_RenderModel()
        {
            var content = new MyContent(Mock.Of <IPublishedContent>());
            var bound   = (IRenderModel)RenderModelBinder.BindModel(content, typeof(RenderModel <MyContent>), CultureInfo.CurrentCulture);

            Assert.AreSame(content, bound.Content);
        }
        public void No_DataToken_Returns_Null()
        {
            var binder    = new RenderModelBinder();
            var routeData = new RouteData();
            var result    = binder.BindModel(new ControllerContext(Mock.Of <HttpContextBase>(), routeData, Mock.Of <ControllerBase>()),
                                             new ModelBindingContext());

            Assert.IsNull(result);
        }
 public void BindModel_Null_Source_Returns_Null()
 {
     Assert.IsNull(RenderModelBinder.BindModel(null, typeof(MyContent), CultureInfo.CurrentCulture));
 }