U4-10822 - fix breaking change

This commit is contained in:
Stephan
2018-01-12 13:51:06 +01:00
parent 0bc4c7e2aa
commit 42959a1db5
3 changed files with 21 additions and 21 deletions

View File

@@ -41,14 +41,14 @@ namespace Umbraco.Tests.Web.Mvc
[Test]
public void BindModel_Null_Source_Returns_Null()
{
Assert.IsNull(RenderModelBinder.Instance.BindModel(null, typeof(MyContent), CultureInfo.CurrentCulture));
Assert.IsNull(RenderModelBinder.BindModel(null, typeof(MyContent), CultureInfo.CurrentCulture));
}
[Test]
public void BindModel_Returns_If_Same_Type()
{
var content = new MyContent(Mock.Of<IPublishedContent>());
var bound = RenderModelBinder.Instance.BindModel(content, typeof (IPublishedContent), CultureInfo.CurrentCulture);
var bound = RenderModelBinder.BindModel(content, typeof (IPublishedContent), CultureInfo.CurrentCulture);
Assert.AreSame(content, bound);
}
@@ -57,7 +57,7 @@ namespace Umbraco.Tests.Web.Mvc
{
var content = new MyContent(Mock.Of<IPublishedContent>());
var renderModel = new RenderModel(content, CultureInfo.CurrentCulture);
var bound = RenderModelBinder.Instance.BindModel(renderModel, typeof(IPublishedContent), CultureInfo.CurrentCulture);
var bound = RenderModelBinder.BindModel(renderModel, typeof(IPublishedContent), CultureInfo.CurrentCulture);
Assert.AreSame(content, bound);
}
@@ -65,7 +65,7 @@ namespace Umbraco.Tests.Web.Mvc
public void BindModel_IPublishedContent_To_RenderModel()
{
var content = new MyContent(Mock.Of<IPublishedContent>());
var bound = (IRenderModel)RenderModelBinder.Instance.BindModel(content, typeof(RenderModel), CultureInfo.CurrentCulture);
var bound = (IRenderModel)RenderModelBinder.BindModel(content, typeof(RenderModel), CultureInfo.CurrentCulture);
Assert.AreSame(content, bound.Content);
}
@@ -73,7 +73,7 @@ namespace Umbraco.Tests.Web.Mvc
public void BindModel_IPublishedContent_To_Generic_RenderModel()
{
var content = new MyContent(Mock.Of<IPublishedContent>());
var bound = (IRenderModel)RenderModelBinder.Instance.BindModel(content, typeof(RenderModel<MyContent>), CultureInfo.CurrentCulture);
var bound = (IRenderModel)RenderModelBinder.BindModel(content, typeof(RenderModel<MyContent>), CultureInfo.CurrentCulture);
Assert.AreSame(content, bound.Content);
}

View File

@@ -14,8 +14,8 @@ namespace Umbraco.Web.Mvc
/// </summary>
public class RenderModelBinder : DefaultModelBinder, IModelBinderProvider
{
public static RenderModelBinder Instance = new RenderModelBinder();
public static RenderModelBinder Instance = new RenderModelBinder();
/// <summary>
/// Binds the model to a value by using the specified controller context and binding context.
/// </summary>
@@ -67,7 +67,7 @@ namespace Umbraco.Web.Mvc
// to
// { RenderModel, RenderModel<TContent>, IPublishedContent }
//
public object BindModel(object source, Type modelType, CultureInfo culture)
public static object BindModel(object source, Type modelType, CultureInfo culture)
{
// null model, return
if (source == null) return null;
@@ -140,22 +140,22 @@ namespace Umbraco.Web.Mvc
SourceType = sourceType;
ModelType = modelType;
Message = message;
}
}
public bool SourceIsContent;
public bool ViewModelIsContent;
public Type SourceType { get; set; }
public Type ModelType { get; set; }
public StringBuilder Message { get; private set; }
public Type ModelType { get; set; }
public StringBuilder Message { get; private set; }
public bool Restart { get; set; }
}
public static event EventHandler<ModelBindingArgs> ModelBindingException;
}
private void ThrowModelBindingException(bool sourceContent, bool modelContent, Type sourceType, Type modelType)
public static event EventHandler<ModelBindingArgs> ModelBindingException;
private static void ThrowModelBindingException(bool sourceContent, bool modelContent, Type sourceType, Type modelType)
{
var msg = new StringBuilder();
// prepare message
msg.Append("Cannot bind source");
if (sourceContent) msg.Append(" content");
@@ -166,14 +166,14 @@ namespace Umbraco.Web.Mvc
msg.Append(" type ");
msg.Append(modelType.FullName);
msg.Append(".");
// raise event, to give model factories a chance at reporting
// the error with more details, and optionally request that
// raise event, to give model factories a chance at reporting
// the error with more details, and optionally request that
// the application restarts.
var args = new ModelBindingArgs(sourceType, modelType, msg);
if (ModelBindingException != null)
ModelBindingException(this, args);
ModelBindingException(Instance, args);
if (args.Restart)
{

View File

@@ -144,7 +144,7 @@ namespace Umbraco.Web.Mvc
// bind the model (use context culture as default, if available)
if (UmbracoContext.PublishedContentRequest != null && UmbracoContext.PublishedContentRequest.Culture != null)
culture = UmbracoContext.PublishedContentRequest.Culture;
viewData.Model = RenderModelBinder.Instance.BindModel(viewDataModel, typeof (TModel), culture);
viewData.Model = RenderModelBinder.BindModel(viewDataModel, typeof (TModel), culture);
// set the view data
base.SetViewData(viewData);