parent
d619b0df3b
commit
c1112fcaf1
13
Mvc.sln
13
Mvc.sln
|
|
@ -51,6 +51,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.Test",
|
|||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "CompositeViewEngine", "test\WebSites\CompositeViewEngine\CompositeViewEngine.kproj", "{A853B2BA-4449-4908-A416-5A3C027FC22B}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ValueProvidersSite", "test\WebSites\ValueProvidersSite\ValueProvidersSite.kproj", "{14F79E79-AE79-48FA-95DE-D794EF4EABB3}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
|
@ -261,6 +263,16 @@ Global
|
|||
{A853B2BA-4449-4908-A416-5A3C027FC22B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{A853B2BA-4449-4908-A416-5A3C027FC22B}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{A853B2BA-4449-4908-A416-5A3C027FC22B}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{14F79E79-AE79-48FA-95DE-D794EF4EABB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{14F79E79-AE79-48FA-95DE-D794EF4EABB3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{14F79E79-AE79-48FA-95DE-D794EF4EABB3}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{14F79E79-AE79-48FA-95DE-D794EF4EABB3}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{14F79E79-AE79-48FA-95DE-D794EF4EABB3}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{14F79E79-AE79-48FA-95DE-D794EF4EABB3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{14F79E79-AE79-48FA-95DE-D794EF4EABB3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{14F79E79-AE79-48FA-95DE-D794EF4EABB3}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{14F79E79-AE79-48FA-95DE-D794EF4EABB3}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{14F79E79-AE79-48FA-95DE-D794EF4EABB3}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
@ -287,5 +299,6 @@ Global
|
|||
{42CDBF4A-E238-4C0F-A416-44588363EB4C} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
|
||||
{5F945B82-FE5F-425C-956C-8BC2F2020254} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1}
|
||||
{A853B2BA-4449-4908-A416-5A3C027FC22B} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
|
||||
{14F79E79-AE79-48FA-95DE-D794EF4EABB3} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
ApplicationModelConventions = new List<IReflectedApplicationModelConvention>();
|
||||
ModelBinders = new List<ModelBinderDescriptor>();
|
||||
ViewEngines = new List<ViewEngineDescriptor>();
|
||||
ValueProviderFactories = new List<IValueProviderFactory>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -81,6 +82,11 @@ namespace Microsoft.AspNet.Mvc
|
|||
/// </summary>
|
||||
public List<ViewEngineDescriptor> ViewEngines { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of <see cref="IValueProviderFactory"/> used by this application.
|
||||
/// </summary>
|
||||
public List<IValueProviderFactory> ValueProviderFactories { get; private set; }
|
||||
|
||||
public List<IReflectedApplicationModelConvention> ApplicationModelConventions { get; private set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||
using Microsoft.Framework.OptionsModel;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
|
|
@ -20,13 +21,13 @@ namespace Microsoft.AspNet.Mvc
|
|||
|
||||
public DefaultActionBindingContextProvider(IModelMetadataProvider modelMetadataProvider,
|
||||
ICompositeModelBinder compositeModelBinder,
|
||||
IEnumerable<IValueProviderFactory> valueProviderFactories,
|
||||
IOptionsAccessor<MvcOptions> mvcOptionsAccessor,
|
||||
IInputFormatterProvider inputFormatterProvider,
|
||||
IEnumerable<IModelValidatorProvider> validatorProviders)
|
||||
{
|
||||
_modelMetadataProvider = modelMetadataProvider;
|
||||
_compositeModelBinder = compositeModelBinder;
|
||||
_valueProviderFactories = valueProviderFactories;
|
||||
_valueProviderFactories = mvcOptionsAccessor.Options.ValueProviderFactories;
|
||||
_inputFormatterProvider = inputFormatterProvider;
|
||||
_validatorProviders = validatorProviders;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,9 +13,10 @@ namespace Microsoft.AspNet.Mvc
|
|||
public class MvcOptionsSetup : IOptionsSetup<MvcOptions>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <remarks>Order is -1 to allow MvcOptionsSetup to run before a user call to SetupOptions.</remarks>
|
||||
public int Order
|
||||
{
|
||||
get { return 1; }
|
||||
get { return -1; }
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
@ -30,6 +31,11 @@ namespace Microsoft.AspNet.Mvc
|
|||
options.ModelBinders.Add(typeof(GenericModelBinder));
|
||||
options.ModelBinders.Add(new MutableObjectModelBinder());
|
||||
options.ModelBinders.Add(new ComplexModelDtoModelBinder());
|
||||
|
||||
// Set up ValueProviders
|
||||
options.ValueProviderFactories.Add(new RouteValueValueProviderFactory());
|
||||
options.ValueProviderFactories.Add(new QueryStringValueProviderFactory());
|
||||
options.ValueProviderFactories.Add(new FormValueProviderFactory());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -59,10 +59,6 @@ namespace Microsoft.AspNet.Mvc
|
|||
yield return describe.Transient<IModelMetadataProvider, DataAnnotationsModelMetadataProvider>();
|
||||
yield return describe.Scoped<IActionBindingContextProvider, DefaultActionBindingContextProvider>();
|
||||
|
||||
yield return describe.Transient<IValueProviderFactory, RouteValueValueProviderFactory>();
|
||||
yield return describe.Transient<IValueProviderFactory, QueryStringValueProviderFactory>();
|
||||
yield return describe.Transient<IValueProviderFactory, FormValueProviderFactory>();
|
||||
|
||||
yield return describe.Transient<IInputFormatter, JsonInputFormatter>();
|
||||
yield return describe.Transient<IInputFormatterProvider, TempInputFormatterProvider>();
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ActivatorTests.cs" />
|
||||
<Compile Include="ValueProviderTests.cs" />
|
||||
<Compile Include="CompositeViewEngineTests.cs" />
|
||||
<Compile Include="DependencyResolverTests.cs" />
|
||||
<Compile Include="InlineConstraintTests.cs" />
|
||||
|
|
|
|||
|
|
@ -0,0 +1,68 @@
|
|||
// 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 System;
|
||||
using System.Threading.Tasks;
|
||||
using ValueProvidersSite;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.TestHost;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.FunctionalTests
|
||||
{
|
||||
public class ValueProviderTest
|
||||
{
|
||||
private readonly IServiceProvider _services;
|
||||
private readonly Action<IBuilder> _app = new Startup().Configure;
|
||||
|
||||
public ValueProviderTest()
|
||||
{
|
||||
_services = TestHelper.CreateServices("ValueProvidersSite");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ValueProviderFactories_AreVisitedInSequentialOrder_ForValueProviders()
|
||||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
|
||||
// Act
|
||||
var response = await client.GetAsync("http://localhost/Home/TestValueProvider?test=not-test-value");
|
||||
|
||||
// Assert
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
Assert.Equal("custom-value-provider-value", body.Trim());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ValueProviderFactories_ReturnsValuesFromQueryValueProvider()
|
||||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
|
||||
// Act
|
||||
var response = await client.GetAsync("http://localhost/Home/DefaultValueProviders?test=query-value");
|
||||
|
||||
// Assert
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
Assert.Equal("query-value", body.Trim());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ValueProviderFactories_ReturnsValuesFromRouteValueProvider()
|
||||
{
|
||||
// Arrange
|
||||
var server = TestServer.Create(_services, _app);
|
||||
var client = server.Handler;
|
||||
|
||||
// Act
|
||||
var response = await client.GetAsync("http://localhost/RouteTest/route-value");
|
||||
|
||||
// Assert
|
||||
var body = await response.ReadBodyAsStringAsync();
|
||||
Assert.Equal("route-value", body.Trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -14,6 +14,7 @@
|
|||
"Microsoft.Framework.DependencyInjection": "1.0.0-*",
|
||||
"Microsoft.Framework.Runtime.Interfaces": "1.0.0-*",
|
||||
"RoutingWebSite": "",
|
||||
"ValueProvidersSite": "",
|
||||
"Xunit.KRunner": "1.0.0-*"
|
||||
},
|
||||
"commands": {
|
||||
|
|
|
|||
|
|
@ -42,5 +42,23 @@ namespace Microsoft.AspNet.Mvc
|
|||
Assert.Equal(typeof(MutableObjectModelBinder), mvcOptions.ModelBinders[3].ModelBinderType);
|
||||
Assert.Equal(typeof(ComplexModelDtoModelBinder), mvcOptions.ModelBinders[4].ModelBinderType);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Setup_SetsUpValueProviders()
|
||||
{
|
||||
// Arrange
|
||||
var mvcOptions = new MvcOptions();
|
||||
var setup = new MvcOptionsSetup();
|
||||
|
||||
// Act
|
||||
setup.Setup(mvcOptions);
|
||||
|
||||
// Assert
|
||||
var valueProviders = mvcOptions.ValueProviderFactories;
|
||||
Assert.Equal(3, valueProviders.Count);
|
||||
Assert.IsType<RouteValueValueProviderFactory>(valueProviders[0]);
|
||||
Assert.IsType<QueryStringValueProviderFactory>(valueProviders[1]);
|
||||
Assert.IsType<FormValueProviderFactory>(valueProviders[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
// 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 System;
|
||||
using System.Globalization;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||
|
||||
namespace ValueProvidersSite
|
||||
{
|
||||
public class CustomValueProviderFactory : IValueProviderFactory
|
||||
{
|
||||
public IValueProvider GetValueProvider(ValueProviderFactoryContext context)
|
||||
{
|
||||
if (context.HttpContext.Request.Path.Value.Contains("TestValueProvider"))
|
||||
{
|
||||
return new CustomValueProvider();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private class CustomValueProvider : IValueProvider
|
||||
{
|
||||
public Task<bool> ContainsPrefixAsync(string prefix)
|
||||
{
|
||||
var result = string.Equals(prefix, "test", StringComparison.OrdinalIgnoreCase);
|
||||
return Task.FromResult(result);
|
||||
}
|
||||
|
||||
public Task<ValueProviderResult> GetValueAsync(string key)
|
||||
{
|
||||
var value = "custom-value-provider-value";
|
||||
var result = new ValueProviderResult(value, value, CultureInfo.CurrentCulture);
|
||||
return Task.FromResult(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
// 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;
|
||||
|
||||
namespace ValueProvidersSite
|
||||
{
|
||||
public class HomeController
|
||||
{
|
||||
public string TestValueProvider(string test)
|
||||
{
|
||||
return test;
|
||||
}
|
||||
|
||||
public string DefaultValueProviders(string test)
|
||||
{
|
||||
return test;
|
||||
}
|
||||
|
||||
[HttpGet("/RouteTest/{test}")]
|
||||
public string RouteValueProviders(string test)
|
||||
{
|
||||
return test;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
// 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.Builder;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
|
||||
namespace ValueProvidersSite
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
public void Configure(IBuilder app)
|
||||
{
|
||||
var configuration = app.GetTestConfiguration();
|
||||
|
||||
// Set up application services
|
||||
app.UseServices(services =>
|
||||
{
|
||||
// Add MVC services to the services container
|
||||
services.AddMvc(configuration)
|
||||
.SetupOptions<MvcOptions>(options =>
|
||||
{
|
||||
options.ValueProviderFactories.Insert(1, new CustomValueProviderFactory());
|
||||
});
|
||||
});
|
||||
|
||||
// Add MVC to the request pipeline
|
||||
app.UseMvc();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
<?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>14f79e79-ae79-48fa-95de-d794ef4eabb3</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>
|
||||
<ItemGroup>
|
||||
<Compile Include="CustomValueProviderFactory.cs" />
|
||||
<Compile Include="HomeController.cs" />
|
||||
<Compile Include="Startup.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VSToolsPath)\AspNet\Microsoft.Web.AspNet.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"Microsoft.AspNet.Mvc": "",
|
||||
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
|
||||
"Microsoft.AspNet.Mvc.TestConfiguration": "",
|
||||
"Microsoft.Framework.ConfigurationModel": ""
|
||||
},
|
||||
"configurations": {
|
||||
"net45": { },
|
||||
"k10": { }
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue