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