InlineConstraint Functional Test, removing the dependency on a physical file.
This commit is contained in:
parent
9e1deb7982
commit
08b64a2a4a
|
|
@ -2,8 +2,10 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using InlineConstraints;
|
using InlineConstraints;
|
||||||
using Microsoft.AspNet.Builder;
|
using Microsoft.AspNet.Builder;
|
||||||
|
|
@ -22,31 +24,23 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
||||||
{
|
{
|
||||||
private readonly IServiceProvider _provider;
|
private readonly IServiceProvider _provider;
|
||||||
private readonly Action<IBuilder> _app = new Startup().Configure;
|
private readonly Action<IBuilder> _app = new Startup().Configure;
|
||||||
private readonly string _jsonConfigFilePath;
|
|
||||||
private readonly Configuration _config = new Configuration();
|
|
||||||
public InlineConstraintTests()
|
public InlineConstraintTests()
|
||||||
{
|
{
|
||||||
_provider = TestHelper.CreateServices("InlineConstraintsWebSite");
|
_provider = TestHelper.CreateServices("InlineConstraintsWebSite");
|
||||||
|
_provider = new ServiceCollection()
|
||||||
// TODO: Hardcoding the config file path for now. Update it to read it from args.
|
.AddScoped<ICommandLineArgumentBuilder, DefaultCommandLineArgumentBuilder>()
|
||||||
_jsonConfigFilePath = @"config\InlineConstraintTestsConfig.json";
|
.BuildServiceProvider(_provider);
|
||||||
_config.AddJsonFile(_jsonConfigFilePath);
|
|
||||||
|
|
||||||
Environment.SetEnvironmentVariable("AppConfigPath", _jsonConfigFilePath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task RoutingToANonExistantArea_WithExistConstraint_RoutesToCorrectAction()
|
public async Task RoutingToANonExistantArea_WithExistConstraint_RoutesToCorrectAction()
|
||||||
{
|
{
|
||||||
// Arrange
|
var svc = _provider.GetService<ICommandLineArgumentBuilder>();
|
||||||
var source = new JsonConfigurationSource(_jsonConfigFilePath);
|
svc.AddArgument("--TemplateCollection:areaRoute:TemplateValue="+
|
||||||
|
"{area:exists}/{controller=Home}/{action=Index}");
|
||||||
// Add the exists inline constraint.
|
svc.AddArgument("--TemplateCollection:actionAsMethod:TemplateValue="+
|
||||||
_config.Set("TemplateCollection:areaRoute:TemplateValue",
|
"{controller=Home}/{action=Index}");
|
||||||
@"{area:exists}/{controller=Home}/{action=Index}");
|
|
||||||
_config.Set("TemplateCollection:actionAsMethod:TemplateValue",
|
|
||||||
@"{controller=Home}/{action=Index}");
|
|
||||||
_config.Commit();
|
|
||||||
|
|
||||||
var server = TestServer.Create(_provider, _app);
|
var server = TestServer.Create(_provider, _app);
|
||||||
var client = server.Handler;
|
var client = server.Handler;
|
||||||
|
|
@ -64,12 +58,11 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
||||||
public async Task RoutingToANonExistantArea_WithoutExistConstraint_RoutesToIncorrectAction()
|
public async Task RoutingToANonExistantArea_WithoutExistConstraint_RoutesToIncorrectAction()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
_config.Set("TemplateCollection:areaRoute:TemplateValue",
|
var svc = _provider.GetService<ICommandLineArgumentBuilder>();
|
||||||
@"{area}/{controller=Home}/{action=Index}");
|
svc.AddArgument("--TemplateCollection:areaRoute:TemplateValue="+
|
||||||
_config.Set("TemplateCollection:actionAsMethod:TemplateValue",
|
"{area}/{controller=Home}/{action=Index}");
|
||||||
@"{controller=Home}/{action=Index}");
|
svc.AddArgument("--TemplateCollection:actionAsMethod:TemplateValue"+
|
||||||
|
"={controller=Home}/{action=Index}");
|
||||||
_config.Commit();
|
|
||||||
|
|
||||||
var server = TestServer.Create(_provider, _app);
|
var server = TestServer.Create(_provider, _app);
|
||||||
var client = server.Handler;
|
var client = server.Handler;
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="compiler\resources\BasicWebSite.Home.Index.html" />
|
<Content Include="compiler\resources\BasicWebSite.Home.Index.html" />
|
||||||
<Content Include="compiler\resources\BasicWebSite.Home.PlainView.html" />
|
<Content Include="compiler\resources\BasicWebSite.Home.PlainView.html" />
|
||||||
<Content Include="config\InlineConstraintTestsConfig.json" />
|
|
||||||
<Content Include="project.json" />
|
<Content Include="project.json" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
{
|
|
||||||
"TemplateCollection": {
|
|
||||||
"areaRoute": {
|
|
||||||
"TemplateValue": ""
|
|
||||||
},
|
|
||||||
"actionAsMethod": {
|
|
||||||
"TemplateValue": ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -12,7 +12,8 @@
|
||||||
"xunit.assert": "2.0.0-aspnet-*",
|
"xunit.assert": "2.0.0-aspnet-*",
|
||||||
"xunit.core": "2.0.0-aspnet-*",
|
"xunit.core": "2.0.0-aspnet-*",
|
||||||
"Xunit.KRunner": "0.1-alpha-*",
|
"Xunit.KRunner": "0.1-alpha-*",
|
||||||
"Microsoft.Framework.ConfigurationModel.Json": "0.1-alpha-*"
|
"Microsoft.Framework.ConfigurationModel.Json": "0.1-alpha-*",
|
||||||
|
"Microsoft.Framework.DependencyInjection": "0.1-alpha-*"
|
||||||
},
|
},
|
||||||
"commands": {
|
"commands": {
|
||||||
"test": "Xunit.KRunner"
|
"test": "Xunit.KRunner"
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
// 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.Collections.Generic;
|
||||||
|
|
||||||
|
namespace InlineConstraints
|
||||||
|
{
|
||||||
|
public class DefaultCommandLineArgumentBuilder : ICommandLineArgumentBuilder
|
||||||
|
{
|
||||||
|
private readonly List<string> _args = new List<string>();
|
||||||
|
|
||||||
|
public void AddArgument(string arg)
|
||||||
|
{
|
||||||
|
_args.Add(arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<string> Build()
|
||||||
|
{
|
||||||
|
return _args;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
// 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.Collections.Generic;
|
||||||
|
|
||||||
|
namespace InlineConstraints
|
||||||
|
{
|
||||||
|
public interface ICommandLineArgumentBuilder
|
||||||
|
{
|
||||||
|
void AddArgument(string arg);
|
||||||
|
|
||||||
|
IEnumerable<string> Build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -33,6 +33,8 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Controllers\HomeController.cs" />
|
<Compile Include="Controllers\HomeController.cs" />
|
||||||
<Compile Include="Controllers\UsersController.cs" />
|
<Compile Include="Controllers\UsersController.cs" />
|
||||||
|
<Compile Include="DefaultCommandLineArgumentBuilder.cs" />
|
||||||
|
<Compile Include="ICommandLineArgumentProvider.cs" />
|
||||||
<Compile Include="Startup.cs" />
|
<Compile Include="Startup.cs" />
|
||||||
<Compile Include="TestControllerAssemblyProvider.cs" />
|
<Compile Include="TestControllerAssemblyProvider.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using Microsoft.AspNet.Builder;
|
using Microsoft.AspNet.Builder;
|
||||||
using Microsoft.AspNet.Mvc;
|
using Microsoft.AspNet.Mvc;
|
||||||
using Microsoft.AspNet.Routing;
|
using Microsoft.AspNet.Routing;
|
||||||
|
|
@ -13,6 +14,7 @@ namespace InlineConstraints
|
||||||
public class Startup
|
public class Startup
|
||||||
{
|
{
|
||||||
public Action<IRouteBuilder> RouteCollectionProvider { get; set; }
|
public Action<IRouteBuilder> RouteCollectionProvider { get; set; }
|
||||||
|
|
||||||
public void Configure(IBuilder app)
|
public void Configure(IBuilder app)
|
||||||
{
|
{
|
||||||
// Set up application services
|
// Set up application services
|
||||||
|
|
@ -28,12 +30,17 @@ namespace InlineConstraints
|
||||||
|
|
||||||
var config = new Configuration();
|
var config = new Configuration();
|
||||||
config.AddEnvironmentVariables();
|
config.AddEnvironmentVariables();
|
||||||
|
var commandLineBuilder = app.ApplicationServices.GetService<ICommandLineArgumentBuilder>();
|
||||||
string appConfigPath;
|
string appConfigPath;
|
||||||
if (config.TryGet("AppConfigPath", out appConfigPath))
|
if (config.TryGet("AppConfigPath", out appConfigPath))
|
||||||
{
|
{
|
||||||
config.AddJsonFile(appConfigPath);
|
config.AddJsonFile(appConfigPath);
|
||||||
}
|
}
|
||||||
|
else if (commandLineBuilder != null)
|
||||||
|
{
|
||||||
|
var args = commandLineBuilder.Build();
|
||||||
|
config.AddCommandLine(args.ToArray());
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var basePath = app.ApplicationServices.GetService<IApplicationEnvironment>().ApplicationBasePath;
|
var basePath = app.ApplicationServices.GetService<IApplicationEnvironment>().ApplicationBasePath;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue