Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Commit

Permalink
Move setting up options to MvcOptionsSetup
Browse files Browse the repository at this point in the history
Fixes #760
  • Loading branch information
pranavkm committed Jul 9, 2014
1 parent 5194adf commit c0622d8
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 9 deletions.
10 changes: 1 addition & 9 deletions src/Microsoft.AspNet.Mvc.Core/MvcOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,7 @@ public class MvcOptions
public MvcOptions()
{
ApplicationModelConventions = new List<IReflectedApplicationModelConvention>();
ModelBinders = new List<ModelBinderDescriptor>
{
new ModelBinderDescriptor(new TypeConverterModelBinder()),
new ModelBinderDescriptor(new TypeMatchModelBinder()),
new ModelBinderDescriptor(typeof(GenericModelBinder)),
new ModelBinderDescriptor(new MutableObjectModelBinder()),
new ModelBinderDescriptor(new ComplexModelDtoModelBinder()),
};

ModelBinders = new List<ModelBinderDescriptor>();
ViewEngines = new List<ViewEngineDescriptor>();
}

Expand Down
9 changes: 9 additions & 0 deletions src/Microsoft.AspNet.Mvc/MvcOptionsSetup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Razor;
using Microsoft.Framework.OptionsModel;

Expand All @@ -20,7 +21,15 @@ public int Order
/// <inheritdoc />
public void Setup(MvcOptions options)
{
// Set up ViewEngines
options.ViewEngines.Add(typeof(RazorViewEngine));

// Set up ModelBinding
options.ModelBinders.Add(new TypeConverterModelBinder());
options.ModelBinders.Add(new TypeMatchModelBinder());
options.ModelBinders.Add(typeof(GenericModelBinder));
options.ModelBinders.Add(new MutableObjectModelBinder());
options.ModelBinders.Add(new ComplexModelDtoModelBinder());
}
}
}
31 changes: 31 additions & 0 deletions test/Microsoft.AspNet.Mvc.Test/Microsoft.AspNet.Mvc.Test.kproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="__ToolsVersion__" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">12.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\AspNet\Microsoft.Web.AspNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>5f945b82-fe5f-425c-956c-8bc2f2020254</ProjectGuid>
<OutputType>Library</OutputType>
</PropertyGroup>

<PropertyGroup Condition="$(OutputType) == 'Console'">
<DebuggerFlavor>ConsoleDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="$(OutputType) == 'Web'">
<DebuggerFlavor>WebDebugger</DebuggerFlavor>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'" Label="Configuration">
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'" Label="Configuration">
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<ItemGroup>
<Content Include="Project.json" />
</ItemGroup>
<Import Project="$(VSToolsPath)\AspNet\Microsoft.Web.AspNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
46 changes: 46 additions & 0 deletions test/Microsoft.AspNet.Mvc.Test/MvcOptionSetupTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Razor;
using Xunit;

namespace Microsoft.AspNet.Mvc
{
public class MvcOptionSetupTest
{
[Fact]
public void Setup_SetsUpViewEngines()
{
// Arrange
var mvcOptions = new MvcOptions();
var setup = new MvcOptionsSetup();

// Act
setup.Setup(mvcOptions);

// Assert
Assert.Equal(1, mvcOptions.ViewEngines.Count);
Assert.Equal(typeof(RazorViewEngine), mvcOptions.ViewEngines[0].ViewEngineType);
}

[Fact]
public void Setup_SetsUpModelBinders()
{
// Arrange
var mvcOptions = new MvcOptions();
var setup = new MvcOptionsSetup();

// Act
setup.Setup(mvcOptions);

// Assert
Assert.Equal(5, mvcOptions.ModelBinders.Count);
Assert.Equal(typeof(TypeConverterModelBinder), mvcOptions.ModelBinders[0].ModelBinderType);
Assert.Equal(typeof(TypeMatchModelBinder), mvcOptions.ModelBinders[1].ModelBinderType);
Assert.Equal(typeof(GenericModelBinder), mvcOptions.ModelBinders[2].ModelBinderType);
Assert.Equal(typeof(MutableObjectModelBinder), mvcOptions.ModelBinders[3].ModelBinderType);
Assert.Equal(typeof(ComplexModelDtoModelBinder), mvcOptions.ModelBinders[4].ModelBinderType);
}
}
}
15 changes: 15 additions & 0 deletions test/Microsoft.AspNet.Mvc.Test/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilationOptions": {
"warningsAsErrors": true
},
"dependencies": {
"Microsoft.AspNet.Mvc" : "",
"Xunit.KRunner": "1.0.0-*"
},
"commands": {
"test": "Xunit.KRunner"
},
"configurations": {
"net45": { }
}
}

0 comments on commit c0622d8

Please sign in to comment.