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

Commit 08b64a2

Browse files
committed
InlineConstraint Functional Test, removing the dependency on a physical file.
1 parent 9e1deb7 commit 08b64a2

File tree

8 files changed

+65
-36
lines changed

8 files changed

+65
-36
lines changed

test/Microsoft.AspNet.Mvc.FunctionalTests/InlineConstraintTests.cs

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5+
using System.Collections.Generic;
56
using System.IO;
67
using System.Reflection;
8+
using System.Text;
79
using System.Threading.Tasks;
810
using InlineConstraints;
911
using Microsoft.AspNet.Builder;
@@ -22,31 +24,23 @@ public class InlineConstraintTests
2224
{
2325
private readonly IServiceProvider _provider;
2426
private readonly Action<IBuilder> _app = new Startup().Configure;
25-
private readonly string _jsonConfigFilePath;
26-
private readonly Configuration _config = new Configuration();
27+
2728
public InlineConstraintTests()
2829
{
2930
_provider = TestHelper.CreateServices("InlineConstraintsWebSite");
30-
31-
// TODO: Hardcoding the config file path for now. Update it to read it from args.
32-
_jsonConfigFilePath = @"config\InlineConstraintTestsConfig.json";
33-
_config.AddJsonFile(_jsonConfigFilePath);
34-
35-
Environment.SetEnvironmentVariable("AppConfigPath", _jsonConfigFilePath);
31+
_provider = new ServiceCollection()
32+
.AddScoped<ICommandLineArgumentBuilder, DefaultCommandLineArgumentBuilder>()
33+
.BuildServiceProvider(_provider);
3634
}
3735

3836
[Fact]
3937
public async Task RoutingToANonExistantArea_WithExistConstraint_RoutesToCorrectAction()
4038
{
41-
// Arrange
42-
var source = new JsonConfigurationSource(_jsonConfigFilePath);
43-
44-
// Add the exists inline constraint.
45-
_config.Set("TemplateCollection:areaRoute:TemplateValue",
46-
@"{area:exists}/{controller=Home}/{action=Index}");
47-
_config.Set("TemplateCollection:actionAsMethod:TemplateValue",
48-
@"{controller=Home}/{action=Index}");
49-
_config.Commit();
39+
var svc = _provider.GetService<ICommandLineArgumentBuilder>();
40+
svc.AddArgument("--TemplateCollection:areaRoute:TemplateValue="+
41+
"{area:exists}/{controller=Home}/{action=Index}");
42+
svc.AddArgument("--TemplateCollection:actionAsMethod:TemplateValue="+
43+
"{controller=Home}/{action=Index}");
5044

5145
var server = TestServer.Create(_provider, _app);
5246
var client = server.Handler;
@@ -64,12 +58,11 @@ public async Task RoutingToANonExistantArea_WithExistConstraint_RoutesToCorrectA
6458
public async Task RoutingToANonExistantArea_WithoutExistConstraint_RoutesToIncorrectAction()
6559
{
6660
// Arrange
67-
_config.Set("TemplateCollection:areaRoute:TemplateValue",
68-
@"{area}/{controller=Home}/{action=Index}");
69-
_config.Set("TemplateCollection:actionAsMethod:TemplateValue",
70-
@"{controller=Home}/{action=Index}");
71-
72-
_config.Commit();
61+
var svc = _provider.GetService<ICommandLineArgumentBuilder>();
62+
svc.AddArgument("--TemplateCollection:areaRoute:TemplateValue="+
63+
"{area}/{controller=Home}/{action=Index}");
64+
svc.AddArgument("--TemplateCollection:actionAsMethod:TemplateValue"+
65+
"={controller=Home}/{action=Index}");
7366

7467
var server = TestServer.Create(_provider, _app);
7568
var client = server.Handler;

test/Microsoft.AspNet.Mvc.FunctionalTests/Microsoft.AspNet.Mvc.FunctionalTests.kproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
<ItemGroup>
2828
<Content Include="compiler\resources\BasicWebSite.Home.Index.html" />
2929
<Content Include="compiler\resources\BasicWebSite.Home.PlainView.html" />
30-
<Content Include="config\InlineConstraintTestsConfig.json" />
3130
<Content Include="project.json" />
3231
</ItemGroup>
3332
<ItemGroup>

test/Microsoft.AspNet.Mvc.FunctionalTests/config/InlineConstraintTestsConfig.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

test/Microsoft.AspNet.Mvc.FunctionalTests/project.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"xunit.assert": "2.0.0-aspnet-*",
1313
"xunit.core": "2.0.0-aspnet-*",
1414
"Xunit.KRunner": "0.1-alpha-*",
15-
"Microsoft.Framework.ConfigurationModel.Json": "0.1-alpha-*"
15+
"Microsoft.Framework.ConfigurationModel.Json": "0.1-alpha-*",
16+
"Microsoft.Framework.DependencyInjection": "0.1-alpha-*"
1617
},
1718
"commands": {
1819
"test": "Xunit.KRunner"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
7+
namespace InlineConstraints
8+
{
9+
public class DefaultCommandLineArgumentBuilder : ICommandLineArgumentBuilder
10+
{
11+
private readonly List<string> _args = new List<string>();
12+
13+
public void AddArgument(string arg)
14+
{
15+
_args.Add(arg);
16+
}
17+
18+
public IEnumerable<string> Build()
19+
{
20+
return _args;
21+
}
22+
}
23+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System.Collections.Generic;
5+
6+
namespace InlineConstraints
7+
{
8+
public interface ICommandLineArgumentBuilder
9+
{
10+
void AddArgument(string arg);
11+
12+
IEnumerable<string> Build();
13+
}
14+
}

test/WebSites/InlineConstraintsWebSite/InlineConstraintsWebSite.kproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
<ItemGroup>
3434
<Compile Include="Controllers\HomeController.cs" />
3535
<Compile Include="Controllers\UsersController.cs" />
36+
<Compile Include="DefaultCommandLineArgumentBuilder.cs" />
37+
<Compile Include="ICommandLineArgumentProvider.cs" />
3638
<Compile Include="Startup.cs" />
3739
<Compile Include="TestControllerAssemblyProvider.cs" />
3840
</ItemGroup>

test/WebSites/InlineConstraintsWebSite/Startup.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4+
using System.Linq;
45
using Microsoft.AspNet.Builder;
56
using Microsoft.AspNet.Mvc;
67
using Microsoft.AspNet.Routing;
@@ -13,6 +14,7 @@ namespace InlineConstraints
1314
public class Startup
1415
{
1516
public Action<IRouteBuilder> RouteCollectionProvider { get; set; }
17+
1618
public void Configure(IBuilder app)
1719
{
1820
// Set up application services
@@ -28,12 +30,17 @@ public void Configure(IBuilder app)
2830

2931
var config = new Configuration();
3032
config.AddEnvironmentVariables();
31-
33+
var commandLineBuilder = app.ApplicationServices.GetService<ICommandLineArgumentBuilder>();
3234
string appConfigPath;
3335
if (config.TryGet("AppConfigPath", out appConfigPath))
3436
{
3537
config.AddJsonFile(appConfigPath);
3638
}
39+
else if (commandLineBuilder != null)
40+
{
41+
var args = commandLineBuilder.Build();
42+
config.AddCommandLine(args.ToArray());
43+
}
3744
else
3845
{
3946
var basePath = app.ApplicationServices.GetService<IApplicationEnvironment>().ApplicationBasePath;

0 commit comments

Comments
 (0)