Fix test broken by PR #1027

This commit is contained in:
Stephan
2016-01-19 12:52:26 +01:00
parent 0621019918
commit 9f360c2b9b
4 changed files with 24 additions and 9 deletions

View File

@@ -90,7 +90,7 @@ namespace Umbraco.Tests.Mvc
view.ViewContext = GetViewContext();
Assert.Throws<InvalidCastException>(() => view.SetViewDataX(viewData));
Assert.Throws<ModelBindingException>(() => view.SetViewDataX(viewData));
}
[Test]
@@ -133,7 +133,7 @@ namespace Umbraco.Tests.Mvc
view.ViewContext = GetViewContext();
Assert.Throws<InvalidCastException>(() => view.SetViewDataX(viewData));
Assert.Throws<ModelBindingException>(() => view.SetViewDataX(viewData));
}
#endregion
@@ -191,7 +191,7 @@ namespace Umbraco.Tests.Mvc
var viewData = new ViewDataDictionary(model);
view.ViewContext = GetViewContext();
Assert.Throws<InvalidCastException>(() => view.SetViewDataX(viewData));
Assert.Throws<ModelBindingException>(() => view.SetViewDataX(viewData));
}
[Test]
@@ -233,7 +233,7 @@ namespace Umbraco.Tests.Mvc
var viewData = new ViewDataDictionary(model);
view.ViewContext = GetViewContext();
Assert.Throws<InvalidCastException>(() => view.SetViewDataX(viewData));
Assert.Throws<ModelBindingException>(() => view.SetViewDataX(viewData));
}
#endregion
@@ -289,7 +289,7 @@ namespace Umbraco.Tests.Mvc
var viewData = new ViewDataDictionary(content);
view.ViewContext = GetViewContext();
Assert.Throws<InvalidCastException>(() =>view.SetViewDataX(viewData));
Assert.Throws<ModelBindingException>(() =>view.SetViewDataX(viewData));
}
[Test]
@@ -313,7 +313,7 @@ namespace Umbraco.Tests.Mvc
var viewData = new ViewDataDictionary(content);
view.ViewContext = GetViewContext();
Assert.Throws<InvalidCastException>(() => view.SetViewDataX(viewData));
Assert.Throws<ModelBindingException>(() => view.SetViewDataX(viewData));
}
[Test]

View File

@@ -0,0 +1,14 @@
using System;
namespace Umbraco.Web.Mvc
{
public class ModelBindingException : Exception
{
public ModelBindingException()
{ }
public ModelBindingException(string message)
: base(message)
{ }
}
}

View File

@@ -73,7 +73,7 @@ namespace Umbraco.Web.Mvc
if (modelType.Implements<IPublishedContent>())
{
if ((sourceContent.GetType().Inherits(modelType)) == false)
throw new Exception(string.Format("Cannot bind source content type {0} to model type {1}.",
throw new ModelBindingException(string.Format("Cannot bind source content type {0} to model type {1}.",
sourceContent.GetType(), modelType));
return sourceContent;
}
@@ -89,7 +89,7 @@ namespace Umbraco.Web.Mvc
{
var targetContentType = modelType.GetGenericArguments()[0];
if ((sourceContent.GetType().Inherits(targetContentType)) == false)
throw new Exception(string.Format("Cannot bind source content type {0} to model content type {1}.",
throw new ModelBindingException(string.Format("Cannot bind source content type {0} to model content type {1}.",
sourceContent.GetType(), targetContentType));
return Activator.CreateInstance(modelType, sourceContent, culture);
}
@@ -100,7 +100,7 @@ namespace Umbraco.Web.Mvc
if (attempt2.Success) return attempt2.Result;
// fail
throw new Exception(string.Format("Cannot bind source type {0} to model type {1}.",
throw new ModelBindingException(string.Format("Cannot bind source type {0} to model type {1}.",
sourceType, modelType));
}
}

View File

@@ -316,6 +316,7 @@
<Compile Include="Models\Mapping\LockedCompositionsResolver.cs" />
<Compile Include="Models\PublishedContentWithKeyBase.cs" />
<Compile Include="Mvc\IRenderController.cs" />
<Compile Include="Mvc\ModelBindingException.cs" />
<Compile Include="Mvc\RenderIndexActionSelectorAttribute.cs" />
<Compile Include="Mvc\ValidateMvcAngularAntiForgeryTokenAttribute.cs" />
<Compile Include="PropertyEditors\DatePreValueEditor.cs" />