From 4f0ba26c7934d01cb195e2b26f7f913fbe2742be Mon Sep 17 00:00:00 2001 From: Mugdha Kulkarni Date: Thu, 19 Feb 2015 17:20:13 -0800 Subject: [PATCH] Adding the test cases for generating lower case URLs --- Mvc.sln | 32 ++++++------ .../RoutingLowercaseUrlTest.cs | 50 +++++++++++++++++++ .../project.json | 7 +-- .../Controllers/BlogController.cs | 27 ++++++++++ .../Controllers/EmployeeController.cs | 21 ++++++++ .../LowercaseUrlsWebSite.kproj | 19 +++++++ test/WebSites/LowercaseUrlsWebSite/Startup.cs | 33 ++++++++++++ .../LowercaseUrlsWebSite/project.json | 19 +++++++ test/WebSites/LowercaseUrlsWebSite/readme.md | 3 ++ .../wwwroot/HelloWorld.htm | 1 + 10 files changed, 194 insertions(+), 18 deletions(-) create mode 100644 test/Microsoft.AspNet.Mvc.FunctionalTests/RoutingLowercaseUrlTest.cs create mode 100644 test/WebSites/LowercaseUrlsWebSite/Controllers/BlogController.cs create mode 100644 test/WebSites/LowercaseUrlsWebSite/Controllers/EmployeeController.cs create mode 100644 test/WebSites/LowercaseUrlsWebSite/LowercaseUrlsWebSite.kproj create mode 100644 test/WebSites/LowercaseUrlsWebSite/Startup.cs create mode 100644 test/WebSites/LowercaseUrlsWebSite/project.json create mode 100644 test/WebSites/LowercaseUrlsWebSite/readme.md create mode 100644 test/WebSites/LowercaseUrlsWebSite/wwwroot/HelloWorld.htm diff --git a/Mvc.sln b/Mvc.sln index 244b4d4860..b4b3d90231 100644 --- a/Mvc.sln +++ b/Mvc.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.22609.0 +VisualStudioVersion = 14.0.22602.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{DAAE4C74-D06F-4874-A166-33305D2643CE}" EndProject @@ -143,8 +143,11 @@ EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "UserClassLibrary", "test\WebSites\UserClassLibrary\UserClassLibrary.kproj", "{C651F432-4EBE-41A6-BAD2-3E07CCBA209C}" EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ControllerDiscoveryConventionsWebSite", "test\WebSites\ControllerDiscoveryConventionsWebSite\ControllerDiscoveryConventionsWebSite.kproj", "{A19022EF-9BA3-4349-94E4-F48E13E1C8AE}" +EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "BestEffortLinkGenerationWebSite", "test\WebSites\BestEffortLinkGenerationWebSite\BestEffortLinkGenerationWebSite.kproj", "{B11C99C9-E577-4CA2-AC53-4F20EA71AD34}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "LowercaseUrlsWebSite", "test\WebSites\LowercaseUrlsWebSite\LowercaseUrlsWebSite.kproj", "{BCDB13A6-7D6E-485E-8424-A156432B71AC}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -803,7 +806,6 @@ Global {42C5D417-4060-48F4-BB28-E9E179007779}.Release|Mixed Platforms.Build.0 = Release|Any CPU {42C5D417-4060-48F4-BB28-E9E179007779}.Release|x86.ActiveCfg = Release|Any CPU {42C5D417-4060-48F4-BB28-E9E179007779}.Release|x86.Build.0 = Release|Any CPU -<<<<<<< HEAD {4DA2D7C1-A7B6-4C01-B57D-89E6EA4609DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {4DA2D7C1-A7B6-4C01-B57D-89E6EA4609DE}.Debug|Any CPU.Build.0 = Debug|Any CPU {4DA2D7C1-A7B6-4C01-B57D-89E6EA4609DE}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU @@ -828,18 +830,6 @@ Global {C651F432-4EBE-41A6-BAD2-3E07CCBA209C}.Release|Mixed Platforms.Build.0 = Release|Any CPU {C651F432-4EBE-41A6-BAD2-3E07CCBA209C}.Release|x86.ActiveCfg = Release|Any CPU {C651F432-4EBE-41A6-BAD2-3E07CCBA209C}.Release|x86.Build.0 = Release|Any CPU - {22019146-BDFA-442E-8C8E-345FB9644578}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {22019146-BDFA-442E-8C8E-345FB9644578}.Debug|Any CPU.Build.0 = Debug|Any CPU - {22019146-BDFA-442E-8C8E-345FB9644578}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {22019146-BDFA-442E-8C8E-345FB9644578}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {22019146-BDFA-442E-8C8E-345FB9644578}.Debug|x86.ActiveCfg = Debug|Any CPU - {22019146-BDFA-442E-8C8E-345FB9644578}.Debug|x86.Build.0 = Debug|Any CPU - {22019146-BDFA-442E-8C8E-345FB9644578}.Release|Any CPU.ActiveCfg = Release|Any CPU - {22019146-BDFA-442E-8C8E-345FB9644578}.Release|Any CPU.Build.0 = Release|Any CPU - {22019146-BDFA-442E-8C8E-345FB9644578}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {22019146-BDFA-442E-8C8E-345FB9644578}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {22019146-BDFA-442E-8C8E-345FB9644578}.Release|x86.ActiveCfg = Release|Any CPU - {22019146-BDFA-442E-8C8E-345FB9644578}.Release|x86.Build.0 = Release|Any CPU {A19022EF-9BA3-4349-94E4-F48E13E1C8AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {A19022EF-9BA3-4349-94E4-F48E13E1C8AE}.Debug|Any CPU.Build.0 = Debug|Any CPU {A19022EF-9BA3-4349-94E4-F48E13E1C8AE}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU @@ -864,6 +854,18 @@ Global {B11C99C9-E577-4CA2-AC53-4F20EA71AD34}.Release|Mixed Platforms.Build.0 = Release|Any CPU {B11C99C9-E577-4CA2-AC53-4F20EA71AD34}.Release|x86.ActiveCfg = Release|Any CPU {B11C99C9-E577-4CA2-AC53-4F20EA71AD34}.Release|x86.Build.0 = Release|Any CPU + {BCDB13A6-7D6E-485E-8424-A156432B71AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BCDB13A6-7D6E-485E-8424-A156432B71AC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BCDB13A6-7D6E-485E-8424-A156432B71AC}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {BCDB13A6-7D6E-485E-8424-A156432B71AC}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {BCDB13A6-7D6E-485E-8424-A156432B71AC}.Debug|x86.ActiveCfg = Debug|Any CPU + {BCDB13A6-7D6E-485E-8424-A156432B71AC}.Debug|x86.Build.0 = Debug|Any CPU + {BCDB13A6-7D6E-485E-8424-A156432B71AC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BCDB13A6-7D6E-485E-8424-A156432B71AC}.Release|Any CPU.Build.0 = Release|Any CPU + {BCDB13A6-7D6E-485E-8424-A156432B71AC}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {BCDB13A6-7D6E-485E-8424-A156432B71AC}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {BCDB13A6-7D6E-485E-8424-A156432B71AC}.Release|x86.ActiveCfg = Release|Any CPU + {BCDB13A6-7D6E-485E-8424-A156432B71AC}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -931,10 +933,10 @@ Global {983741B2-4424-4ED1-9B03-7675A67230C8} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C} {551DC89E-2A13-4CF2-83D7-1ADD802443D5} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C} {42C5D417-4060-48F4-BB28-E9E179007779} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C} -<<<<<<< HEAD {4DA2D7C1-A7B6-4C01-B57D-89E6EA4609DE} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E} {C651F432-4EBE-41A6-BAD2-3E07CCBA209C} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C} {A19022EF-9BA3-4349-94E4-F48E13E1C8AE} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C} {B11C99C9-E577-4CA2-AC53-4F20EA71AD34} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C} + {BCDB13A6-7D6E-485E-8424-A156432B71AC} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C} EndGlobalSection EndGlobal diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/RoutingLowercaseUrlTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/RoutingLowercaseUrlTest.cs new file mode 100644 index 0000000000..a3e8e14f20 --- /dev/null +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/RoutingLowercaseUrlTest.cs @@ -0,0 +1,50 @@ +// 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.Net; +using System.Threading.Tasks; +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.TestHost; +using Xunit; + +namespace Microsoft.AspNet.Mvc.FunctionalTests +{ + public class RoutingLowercaseUrlTest + { + // This website sets the generation of lowercase URLs to true + private readonly IServiceProvider _services = TestHelper.CreateServices("LowercaseUrlsWebSite"); + private readonly Action _app = new LowercaseUrlsWebSite.Startup().Configure; + + [Theory] + // Generating lower case URL doesnt lowercase the query parameters + [InlineData("LowercaseUrls_Blog/Generatelink", "/api/employee/getemployee/marykae?LastName=McDonald")] + + // Lowercasing controller and action for conventional route + [InlineData("LowercaseUrls_Blog/ShowPosts", "/lowercaseurls_blog/showposts")] + + // Lowercasing controller, action and other route data for conventional route + [InlineData("LowercaseUrls_Blog/edit/BlogPost", "/lowercaseurls_blog/edit/blogpost")] + + // Lowercasing controller and action for attribute route + [InlineData("Api/Employee/List", "/api/employee/list")] + + // Lowercasing controller, action and other route data for attribute route + [InlineData("Api/Employee/GetEmployee/JohnDoe", "/api/employee/getemployee/johndoe")] + public async Task GenerateLowerCaseUrlsTests(string path, string expectedUrl) + { + // Arrange + var server = TestServer.Create(_services, _app); + var client = server.CreateClient(); + + // Act + var response = await client.GetAsync("http://localhost/" + path); + + // Assert + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + + var body = await response.Content.ReadAsStringAsync(); + Assert.Equal(expectedUrl, body); + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/project.json b/test/Microsoft.AspNet.Mvc.FunctionalTests/project.json index 37fb738ad0..d4658367df 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/project.json +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/project.json @@ -27,7 +27,8 @@ "FormatFilterWebSite": "1.0.0-*", "FormatterWebSite": "1.0.0", "InlineConstraintsWebSite": "1.0.0", - "LoggingWebSite": "1.0.0", + "LoggingWebSite": "1.0.0", + "LowercaseUrlsWebSite": "1.0.0-*", "ModelBindingWebSite": "1.0.0", "MvcSample.Web": "1.0.0", "PrecompilationWebSite": "1.0.0", @@ -51,10 +52,10 @@ "Microsoft.AspNet.Mvc": "6.0.0-*", "Microsoft.AspNet.Mvc.Xml": "6.0.0-*", "Microsoft.AspNet.Mvc.TestConfiguration": "1.0.0", + "Microsoft.AspNet.WebUtilities": "1.0.0-*", "MvcTagHelpersWebSite": "1.0.0", "Microsoft.Framework.ConfigurationModel.Json": "1.0.0-*", - "xunit.runner.kre": "1.0.0-*", - "Microsoft.AspNet.WebUtilities": "1.0.0-*" + "xunit.runner.kre": "1.0.0-*" }, "commands": { "test": "xunit.runner.kre" diff --git a/test/WebSites/LowercaseUrlsWebSite/Controllers/BlogController.cs b/test/WebSites/LowercaseUrlsWebSite/Controllers/BlogController.cs new file mode 100644 index 0000000000..d2ebed7c56 --- /dev/null +++ b/test/WebSites/LowercaseUrlsWebSite/Controllers/BlogController.cs @@ -0,0 +1,27 @@ +// 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 LowercaseUrlsWebSite +{ + public class LowercaseUrls_BlogController : Controller + { + public string ShowPosts() + { + return Url.Action(); + } + + public string Edit(string postName) + { + return Url.Action(); + } + + // Adding extra values than needed to generate the link creates query parameters. The query parameters are not + // lowercased when the URL is + public string GenerateLink() + { + return Url.Action("GetEmployee", "LowercaseUrls_Employee", new { Name = "MaryKae" , LastName = "McDonald"}); + } + } +} \ No newline at end of file diff --git a/test/WebSites/LowercaseUrlsWebSite/Controllers/EmployeeController.cs b/test/WebSites/LowercaseUrlsWebSite/Controllers/EmployeeController.cs new file mode 100644 index 0000000000..03b639c613 --- /dev/null +++ b/test/WebSites/LowercaseUrlsWebSite/Controllers/EmployeeController.cs @@ -0,0 +1,21 @@ +// 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 LowercaseUrlsWebSite +{ + [Route("api/Employee/[action]/{name?}")] + public class LowercaseUrls_EmployeeController : Controller + { + public string List() + { + return Url.Action(); + } + + public string GetEmployee(string name) + { + return Url.Action(); + } + } +} \ No newline at end of file diff --git a/test/WebSites/LowercaseUrlsWebSite/LowercaseUrlsWebSite.kproj b/test/WebSites/LowercaseUrlsWebSite/LowercaseUrlsWebSite.kproj new file mode 100644 index 0000000000..2f369ebc79 --- /dev/null +++ b/test/WebSites/LowercaseUrlsWebSite/LowercaseUrlsWebSite.kproj @@ -0,0 +1,19 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + bcdb13a6-7d6e-485e-8424-a156432b71ac + LowercaseUrlsWebSite + ..\..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\..\artifacts\bin\$(MSBuildProjectName)\ + + + 2.0 + 10331 + + + \ No newline at end of file diff --git a/test/WebSites/LowercaseUrlsWebSite/Startup.cs b/test/WebSites/LowercaseUrlsWebSite/Startup.cs new file mode 100644 index 0000000000..78f2aee725 --- /dev/null +++ b/test/WebSites/LowercaseUrlsWebSite/Startup.cs @@ -0,0 +1,33 @@ +using System; +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Http; +using Microsoft.AspNet.Routing; +using Microsoft.Framework.DependencyInjection; + +namespace LowercaseUrlsWebSite +{ + public class Startup + { + public void ConfigureServices(IServiceCollection services) + { + } + + public void Configure(IApplicationBuilder app) + { + var configuration = app.GetTestConfiguration(); + + app.UseServices(services => + { + services.AddMvc(configuration); + + services.Configure(routeOptions => routeOptions.LowercaseUrls = true); + }); + + app.UseMvc(routes => + { + routes.MapRoute("Default", "{controller}/{action}/{id?}", + defaults: new { controller = "Home", action = "Index" }); + }); + } + } +} diff --git a/test/WebSites/LowercaseUrlsWebSite/project.json b/test/WebSites/LowercaseUrlsWebSite/project.json new file mode 100644 index 0000000000..01696e38f0 --- /dev/null +++ b/test/WebSites/LowercaseUrlsWebSite/project.json @@ -0,0 +1,19 @@ +{ + "commands": { + "web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001", + "kestrel": "Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5000" + }, + "dependencies": { + "Kestrel": "1.0.0-*", + "Microsoft.AspNet.Mvc": "6.0.0-*", + "Microsoft.AspNet.Mvc.TestConfiguration": "1.0.0", + "Microsoft.AspNet.Server.IIS": "1.0.0-*", + "Microsoft.AspNet.Server.WebListener": "1.0.0-*", + "Microsoft.AspNet.StaticFiles": "1.0.0-*" + }, + "frameworks": { + "aspnet50": { }, + "aspnetcore50": { } + }, + "webroot": "wwwroot" +} diff --git a/test/WebSites/LowercaseUrlsWebSite/readme.md b/test/WebSites/LowercaseUrlsWebSite/readme.md new file mode 100644 index 0000000000..cd432755d6 --- /dev/null +++ b/test/WebSites/LowercaseUrlsWebSite/readme.md @@ -0,0 +1,3 @@ +LowercaseUrlsWebSite +=== +This website illustrates how to set option for lower case URL generation \ No newline at end of file diff --git a/test/WebSites/LowercaseUrlsWebSite/wwwroot/HelloWorld.htm b/test/WebSites/LowercaseUrlsWebSite/wwwroot/HelloWorld.htm new file mode 100644 index 0000000000..8970971f19 --- /dev/null +++ b/test/WebSites/LowercaseUrlsWebSite/wwwroot/HelloWorld.htm @@ -0,0 +1 @@ +HelloWorld \ No newline at end of file