diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/InlineConstraintTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/InlineConstraintTests.cs index 5ccd88259a..a4500aa622 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/InlineConstraintTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/InlineConstraintTests.cs @@ -7,37 +7,24 @@ using System.Threading.Tasks; using InlineConstraints; using Microsoft.AspNet.Builder; using Microsoft.AspNet.TestHost; -using Microsoft.Framework.DependencyInjection; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests { public class InlineConstraintTests { - private readonly IServiceProvider _provider; + private readonly IServiceProvider _provider = TestHelper.CreateServices("InlineConstraintsWebSite"); private readonly Action _app = new Startup().Configure; - public InlineConstraintTests() - { - var services = new ServiceCollection() - .AddScoped(); - _provider = TestHelper.CreateServices("InlineConstraintsWebSite", services); - } - [Fact] public async Task RoutingToANonExistantArea_WithExistConstraint_RoutesToCorrectAction() { - var svc = _provider.GetRequiredService(); - svc.AddArgument("--TemplateCollection:areaRoute:TemplateValue=" + - "{area:exists}/{controller=Home}/{action=Index}"); - svc.AddArgument("--TemplateCollection:actionAsMethod:TemplateValue=" + - "{controller=Home}/{action=Index}"); - + // Arrange var server = TestServer.Create(_provider, _app); var client = server.CreateClient(); // Act - var response = await client.GetAsync("http://localhost/Users"); + var response = await client.GetAsync("http://localhost/area-exists/Users"); // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); @@ -49,17 +36,11 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public async Task RoutingToANonExistantArea_WithoutExistConstraint_RoutesToIncorrectAction() { // Arrange - var svc = _provider.GetRequiredService(); - 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.CreateClient(); // Act & Assert - var ex = await Assert.ThrowsAsync(() => client.GetAsync("http://localhost/Users")); + var ex = await Assert.ThrowsAsync(() => client.GetAsync("http://localhost/area-withoutexists/Users")); Assert.Equal("The view 'Index' was not found." + " The following locations were searched:\r\n/Areas/Users/Views/Home/Index.cshtml\r\n" + @@ -67,4 +48,4 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests ex.Message); } } -} \ No newline at end of file +} diff --git a/test/WebSites/InlineConstraintsWebSite/App_Data/config.json b/test/WebSites/InlineConstraintsWebSite/App_Data/config.json deleted file mode 100644 index bbf0028b59..0000000000 --- a/test/WebSites/InlineConstraintsWebSite/App_Data/config.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "TemplateCollection" : { - "areaRoute" : { - "TemplateValue" : "{area:exists}/{controller=Home}/{action=Index}" - }, - "actionRoute" : { - "TemplateValue" : "{controller=Home}/{action=Index}" - } - } -} \ No newline at end of file diff --git a/test/WebSites/InlineConstraintsWebSite/DefaultCommandLineArgumentBuilder.cs b/test/WebSites/InlineConstraintsWebSite/DefaultCommandLineArgumentBuilder.cs deleted file mode 100644 index 32efeaa454..0000000000 --- a/test/WebSites/InlineConstraintsWebSite/DefaultCommandLineArgumentBuilder.cs +++ /dev/null @@ -1,22 +0,0 @@ -// 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 class DefaultCommandLineArgumentBuilder : ICommandLineArgumentBuilder - { - private readonly List _args = new List(); - - public void AddArgument(string arg) - { - _args.Add(arg); - } - - public IEnumerable Build() - { - return _args; - } - } -} \ No newline at end of file diff --git a/test/WebSites/InlineConstraintsWebSite/ICommandLineArgumentProvider.cs b/test/WebSites/InlineConstraintsWebSite/ICommandLineArgumentProvider.cs deleted file mode 100644 index 88ea0c64bd..0000000000 --- a/test/WebSites/InlineConstraintsWebSite/ICommandLineArgumentProvider.cs +++ /dev/null @@ -1,14 +0,0 @@ -// 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 Build(); - } -} \ No newline at end of file diff --git a/test/WebSites/InlineConstraintsWebSite/Startup.cs b/test/WebSites/InlineConstraintsWebSite/Startup.cs index 4b6f27f70f..6b8a07e69a 100644 --- a/test/WebSites/InlineConstraintsWebSite/Startup.cs +++ b/test/WebSites/InlineConstraintsWebSite/Startup.cs @@ -2,14 +2,9 @@ // 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.Linq; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Routing; -using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Runtime; namespace InlineConstraints { @@ -21,59 +16,19 @@ namespace InlineConstraints { var configuration = app.GetTestConfiguration(); - configuration.AddEnvironmentVariables(); - - var commandLineBuilder = app.ApplicationServices.GetRequiredService(); - string appConfigPath; - if (configuration.TryGet("AppConfigPath", out appConfigPath)) - { - configuration.AddJsonFile(appConfigPath); - } - else if (commandLineBuilder != null) - { - var args = commandLineBuilder.Build(); - configuration.AddCommandLine(args.ToArray()); - } - else - { - var basePath = app.ApplicationServices.GetRequiredService().ApplicationBasePath; - configuration.AddJsonFile(Path.Combine(basePath, @"App_Data\config.json")); - } - - // Set up application services app.UseServices(services => { - // Add MVC services to the services container services.AddMvc(configuration); }); - // Add MVC to the request pipeline app.UseMvc(routes => - { - foreach (var item in GetDataFromConfig(configuration)) - { - routes.MapRoute(item.RouteName, item.RouteTemplateValue); - } - }); - } - - private IEnumerable GetDataFromConfig(IConfiguration config) - { - foreach (var template in config.GetSubKey("TemplateCollection").GetSubKeys()) { - yield return - new RouteConfigData() - { - RouteName = template.Key, - RouteTemplateValue = template.Value.Get("TemplateValue") - }; - } - } - - private class RouteConfigData - { - public string RouteName { get; set; } - public string RouteTemplateValue { get; set; } + // Used by tests for the 'exists' constraint. + routes.MapRoute("areaExists-area", "area-exists/{area:exists}/{controller=Home}/{action=Index}"); + routes.MapRoute("areaExists", "area-exists/{controller=Home}/{action=Index}"); + routes.MapRoute("areaWithoutExists-area", "area-withoutexists/{area}/{controller=Home}/{action=Index}"); + routes.MapRoute("areaWithoutExists", "area-withoutexists/{controller=Home}/{action=Index}"); + }); } } }