From c8c0c5303eac4ef5c333d7fc35c6ea1d332f8992 Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Tue, 27 Oct 2015 16:26:08 -0700 Subject: [PATCH] Remove more `TestHelper` functional tests - remove tests already thoroughly covered in unit tests - #3139 part 2 of 3 - make checks of `
` tag helper more consistent with others - use a tag helper initializer but testing every variant; covered in unit tests - remove `MvcStartupTest` and associated web site - scenario covered elsewhere - remove `PrecompilationTest.PrecompiledView_RendersCorrectly()` - scenario covered elsewhere and shouldn't do I/O on checked-in files --- Mvc.sln | 13 ---- .../HtmlGenerationTest.cs | 62 +--------------- .../MvcStartupTests.cs | 29 -------- .../PrecompilationTest.cs | 74 ------------------- ...on_Home.Form.Options.Antiforgery.True.html | 15 ---- ...on_Home.Form.Options.Antiforgery.null.html | 15 ---- ...tionWebSite.HtmlGeneration_Home.Form.html} | 0 .../project.json | 1 - .../AddServicesWebSite.xproj | 18 ----- test/WebSites/AddServicesWebSite/Startup.cs | 31 -------- test/WebSites/AddServicesWebSite/project.json | 18 ----- test/WebSites/AddServicesWebSite/readme.md | 4 - .../AddServicesWebSite/wwwroot/HelloWorld.htm | 1 - .../WebSites/HtmlGenerationWebSite/Startup.cs | 7 +- .../Views/Shared/Customer.cshtml | 2 +- 15 files changed, 7 insertions(+), 283 deletions(-) delete mode 100644 test/Microsoft.AspNet.Mvc.FunctionalTests/MvcStartupTests.cs delete mode 100644 test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Form.Options.Antiforgery.True.html delete mode 100644 test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Form.Options.Antiforgery.null.html rename test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/{HtmlGenerationWebSite.HtmlGeneration_Home.Form.Options.Antiforgery.False.html => HtmlGenerationWebSite.HtmlGeneration_Home.Form.html} (100%) delete mode 100644 test/WebSites/AddServicesWebSite/AddServicesWebSite.xproj delete mode 100644 test/WebSites/AddServicesWebSite/Startup.cs delete mode 100644 test/WebSites/AddServicesWebSite/project.json delete mode 100644 test/WebSites/AddServicesWebSite/readme.md delete mode 100644 test/WebSites/AddServicesWebSite/wwwroot/HelloWorld.htm diff --git a/Mvc.sln b/Mvc.sln index 41a917fef3..8e7fa86b91 100644 --- a/Mvc.sln +++ b/Mvc.sln @@ -54,8 +54,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ContentNegotiationWebSite", "test\WebSites\ContentNegotiationWebSite\ContentNegotiationWebSite.xproj", "{C6E5AFFA-890A-448F-8DE3-878B1D3C9FC7}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "AddServicesWebSite", "test\WebSites\AddServicesWebSite\AddServicesWebSite.xproj", "{6A0B65CE-6B01-40D0-840D-EFF3680D1547}" -EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "FiltersWebSite", "test\WebSites\FiltersWebSite\FiltersWebSite.xproj", "{1976AC4A-FEA4-4587-A158-D9F79736D2B6}" EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "UrlHelperWebSite", "test\WebSites\UrlHelperWebSite\UrlHelperWebSite.xproj", "{A192E504-2881-41DC-90D1-B7F1DD1134E8}" @@ -382,16 +380,6 @@ Global {C6E5AFFA-890A-448F-8DE3-878B1D3C9FC7}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {C6E5AFFA-890A-448F-8DE3-878B1D3C9FC7}.Release|Mixed Platforms.Build.0 = Release|Any CPU {C6E5AFFA-890A-448F-8DE3-878B1D3C9FC7}.Release|x86.ActiveCfg = Release|Any CPU - {6A0B65CE-6B01-40D0-840D-EFF3680D1547}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6A0B65CE-6B01-40D0-840D-EFF3680D1547}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6A0B65CE-6B01-40D0-840D-EFF3680D1547}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {6A0B65CE-6B01-40D0-840D-EFF3680D1547}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {6A0B65CE-6B01-40D0-840D-EFF3680D1547}.Debug|x86.ActiveCfg = Debug|Any CPU - {6A0B65CE-6B01-40D0-840D-EFF3680D1547}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6A0B65CE-6B01-40D0-840D-EFF3680D1547}.Release|Any CPU.Build.0 = Release|Any CPU - {6A0B65CE-6B01-40D0-840D-EFF3680D1547}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {6A0B65CE-6B01-40D0-840D-EFF3680D1547}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {6A0B65CE-6B01-40D0-840D-EFF3680D1547}.Release|x86.ActiveCfg = Release|Any CPU {1976AC4A-FEA4-4587-A158-D9F79736D2B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {1976AC4A-FEA4-4587-A158-D9F79736D2B6}.Debug|Any CPU.Build.0 = Debug|Any CPU {1976AC4A-FEA4-4587-A158-D9F79736D2B6}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU @@ -1138,7 +1126,6 @@ Global {62735776-46FF-4170-9392-02E128A69B89} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C} {EE1AB716-F102-4CA3-AD2C-214A44B459A0} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C} {C6E5AFFA-890A-448F-8DE3-878B1D3C9FC7} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C} - {6A0B65CE-6B01-40D0-840D-EFF3680D1547} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C} {1976AC4A-FEA4-4587-A158-D9F79736D2B6} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C} {A192E504-2881-41DC-90D1-B7F1DD1134E8} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C} {61061528-071E-424E-965A-07BCC2F02672} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C} diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/HtmlGenerationTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/HtmlGenerationTest.cs index f73eb6a31a..3d7da9b686 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/HtmlGenerationTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/HtmlGenerationTest.cs @@ -9,11 +9,6 @@ using System.Net.Http; using System.Net.Http.Headers; using System.Reflection; using System.Threading.Tasks; -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Mvc.Internal; -using Microsoft.AspNet.Mvc.TagHelpers; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.DependencyInjection.Extensions; using Xunit; namespace Microsoft.AspNet.Mvc.FunctionalTests @@ -22,13 +17,8 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests IClassFixture>, IClassFixture> { - private const string SiteName = nameof(HtmlGenerationWebSite); private static readonly Assembly _resourcesAssembly = typeof(HtmlGenerationTest).GetTypeInfo().Assembly; - private readonly Action _app = new HtmlGenerationWebSite.Startup().Configure; - private readonly Action _configureServices = - new HtmlGenerationWebSite.Startup().ConfigureServices; - public HtmlGenerationTest( MvcTestFixture fixture, MvcEncodedTestFixture encodedFixture) @@ -56,6 +46,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { "CreateWarehouse", null }, // Testing the HTML helpers with FormTagHelper { "EditWarehouse", null }, + { "Form", "/HtmlGeneration_Home/Form" }, // Testing MVC tag helpers invoked in the editor templates from HTML helpers { "EmployeeList", null }, // Testing the EnvironmentTagHelper @@ -474,57 +465,6 @@ Products: Laptops (3)"; Assert.Equal("Deal percentage is 30", response3.Trim()); } - [Theory] - [InlineData(null)] - [InlineData(true)] - [InlineData(false)] - public async Task FormTagHelper_GeneratesExpectedContent(bool? optionsAntiforgery) - { - // Arrange - var newServices = new ServiceCollection(); - var builder = new MvcCoreBuilder(newServices); - builder.InitializeTagHelper((helper, _) => helper.Antiforgery = optionsAntiforgery); - var server = TestHelper.CreateServer(_app, SiteName, - services => - { - services.Add(newServices); - _configureServices(services); - }); - var client = server.CreateClient(); - var expectedMediaType = MediaTypeHeaderValue.Parse("text/html; charset=utf-8"); - - var outputFile = string.Format( - "compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Form.Options.Antiforgery.{0}.html", - optionsAntiforgery?.ToString() ?? "null"); - var expectedContent = - await ResourceFile.ReadResourceAsync(_resourcesAssembly, outputFile, sourceFile: false); - - // Act - // The host is not important as everything runs in memory and tests are isolated from each other. - var response = await client.GetAsync("http://localhost/HtmlGeneration_Home/Form"); - var responseContent = await response.Content.ReadAsStringAsync(); - - // Assert - Assert.Equal(HttpStatusCode.OK, response.StatusCode); - Assert.Equal(expectedMediaType, response.Content.Headers.ContentType); - - responseContent = responseContent.Trim(); - var forgeryTokens = AntiforgeryTestHelper.RetrieveAntiforgeryTokens(responseContent).ToArray(); - -#if GENERATE_BASELINES - // Reverse usual substitutions and insert format items into the new file content. - for (var index = 0; index < forgeryTokens.Length; index++) - { - responseContent = responseContent.Replace(forgeryTokens[index], $"{{{ index }}}"); - } - - ResourceFile.UpdateFile(_resourcesAssembly, outputFile, expectedContent, responseContent); -#else - expectedContent = string.Format(expectedContent, forgeryTokens); - Assert.Equal(expectedContent.Trim(), responseContent, ignoreLineEndingDifferences: true); -#endif - } - [Fact] public async Task EditorTemplateWithNoModel_RendersWithCorrectMetadata() { diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/MvcStartupTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/MvcStartupTests.cs deleted file mode 100644 index 0fad7c26a3..0000000000 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/MvcStartupTests.cs +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using Microsoft.AspNet.Builder; -using Microsoft.Extensions.DependencyInjection; -using Xunit; - -namespace Microsoft.AspNet.Mvc.FunctionalTests -{ - public class MvcStartupTests - { - private const string SiteName = nameof(AddServicesWebSite); - private readonly Action _app = new AddServicesWebSite.Startup().Configure; - - [Fact] - public void MvcThrowsWhenRequiredServicesAreNotAdded() - { - // Arrange - var expectedMessage = "Unable to find the required services. Please add all the required " + - "services by calling 'IServiceCollection.AddMvc()' inside the call to 'IApplicationBuilder.ConfigureServices(...)' " + - "or 'IApplicationBuilder.UseMvc(...)' in the application startup code."; - - // Act & Assert - var ex = Assert.Throws(() => TestHelper.CreateServer(_app, SiteName)); - Assert.Equal(expectedMessage, ex.Message); - } - } -} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/PrecompilationTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/PrecompilationTest.cs index 74b541ff85..0f5a9e14f1 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/PrecompilationTest.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/PrecompilationTest.cs @@ -2,17 +2,12 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO; using System.Linq; -using System.Net; using System.Net.Http; using System.Reflection; using System.Threading.Tasks; -using Microsoft.AspNet.Builder; using Microsoft.AspNet.Mvc.Razor.Precompilation; using Microsoft.AspNet.Testing.xunit; -using Microsoft.Extensions.PlatformAbstractions; -using Microsoft.Extensions.DependencyInjection; using PrecompilationWebSite; using Xunit; @@ -20,11 +15,6 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests { public class PrecompilationTest : IClassFixture> { - private const string SiteName = nameof(PrecompilationWebSite); - private static readonly TimeSpan _cacheDelayInterval = TimeSpan.FromSeconds(1); - private readonly Action _app = new Startup().Configure; - private readonly Action _configureServices = new Startup().ConfigureServices; - public PrecompilationTest(MvcTestFixture fixture) { Client = fixture.Client; @@ -32,59 +22,6 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests public HttpClient Client { get; } - [ConditionalFact] - [FrameworkSkipCondition(RuntimeFrameworks.Mono)] - public async Task PrecompiledView_RendersCorrectly() - { - // Arrange - IServiceCollection serviceCollection = null; - var server = TestHelper.CreateServer(_app, SiteName, services => - { - _configureServices(services); - serviceCollection = services; - }); - var client = server.CreateClient(); - - var serviceProvider = serviceCollection.BuildServiceProvider(); - var applicationEnvironment = serviceProvider.GetRequiredService(); - - var viewsDirectory = Path.Combine(applicationEnvironment.ApplicationBasePath, "Views", "Home"); - var indexContent = File.ReadAllText(Path.Combine(viewsDirectory, "Index.cshtml")); - - // We will render a view that writes the fully qualified name of the Assembly containing the type of - // the view. If the view is precompiled, this assembly will be PrecompilationWebsite. - var assemblyNamePrefix = GetAssemblyNamePrefix(); - - try - { - // Act - 1 - var response = await client.GetAsync("http://localhost/Home/Index"); - var responseContent = await response.Content.ReadAsStringAsync(); - - // Assert - 1 - Assert.Equal(HttpStatusCode.OK, response.StatusCode); - var parsedResponse1 = new ParsedResponse(responseContent); - Assert.StartsWith(assemblyNamePrefix, parsedResponse1.ViewStart); - Assert.StartsWith(assemblyNamePrefix, parsedResponse1.Layout); - Assert.StartsWith(assemblyNamePrefix, parsedResponse1.Index); - - // Act - 2 - // Touch the Index file and verify it remains unaffected. - await TouchFile(viewsDirectory, "Index.cshtml"); - responseContent = await client.GetStringAsync("http://localhost/Home/Index"); - - // Assert - 2 - var response2 = new ParsedResponse(responseContent); - Assert.StartsWith(assemblyNamePrefix, response2.ViewStart); - Assert.StartsWith(assemblyNamePrefix, response2.Index); - Assert.StartsWith(assemblyNamePrefix, response2.Layout); - } - finally - { - File.WriteAllText(Path.Combine(viewsDirectory, "Index.cshtml"), indexContent.TrimEnd(' ')); - } - } - [Fact] public async Task PrecompiledView_UsesCompilationOptionsFromApplication() { @@ -149,17 +86,6 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests return typeof(Startup).GetTypeInfo().Assembly.GetName().Name + "." + nameof(RazorPreCompiler) + "."; } - private static async Task TouchFile(string viewsDir, string file) - { - var path = Path.Combine(viewsDir, file); - File.AppendAllText(path, " "); - - // Delay to allow the file system watcher to catch up. - await Task.Delay(_cacheDelayInterval); - - return path; - } - private sealed class ParsedResponse { public ParsedResponse(string responseContent) diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Form.Options.Antiforgery.True.html b/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Form.Options.Antiforgery.True.html deleted file mode 100644 index 8b87eec8f0..0000000000 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Form.Options.Antiforgery.True.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - Form - - - -

Form Tag Helper Test

- - -
-
-
- - \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Form.Options.Antiforgery.null.html b/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Form.Options.Antiforgery.null.html deleted file mode 100644 index 8b87eec8f0..0000000000 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Form.Options.Antiforgery.null.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - Form - - - -

Form Tag Helper Test

- -
-
-
-
- - \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Form.Options.Antiforgery.False.html b/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Form.html similarity index 100% rename from test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Form.Options.Antiforgery.False.html rename to test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Form.html diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/project.json b/test/Microsoft.AspNet.Mvc.FunctionalTests/project.json index 4285c2ef3d..4f6f77c263 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/project.json +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/project.json @@ -10,7 +10,6 @@ "ActionConstraintsWebSite": "1.0.0", "ActionResultsWebSite": "1.0.0", "ActivatorWebSite": "1.0.0", - "AddServicesWebSite": "1.0.0", "AntiforgeryTokenWebSite": "1.0.0", "ApiExplorerWebSite": "1.0.0", "ApplicationModelWebSite": "1.0.0", diff --git a/test/WebSites/AddServicesWebSite/AddServicesWebSite.xproj b/test/WebSites/AddServicesWebSite/AddServicesWebSite.xproj deleted file mode 100644 index 782f70a090..0000000000 --- a/test/WebSites/AddServicesWebSite/AddServicesWebSite.xproj +++ /dev/null @@ -1,18 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 6a0b65ce-6b01-40d0-840d-eff3680d1547 - ..\..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\..\artifacts\bin\$(MSBuildProjectName)\ - - - 2.0 - 49640 - - - \ No newline at end of file diff --git a/test/WebSites/AddServicesWebSite/Startup.cs b/test/WebSites/AddServicesWebSite/Startup.cs deleted file mode 100644 index 70f1dfa49b..0000000000 --- a/test/WebSites/AddServicesWebSite/Startup.cs +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.AspNet.Builder; - -namespace AddServicesWebSite -{ - public class Startup - { - public void Configure(IApplicationBuilder app) - { - app.UseCultureReplacer(); - - // Not calling AddMvc() here. - // The purpose of the Website is to demonstrate that it throws - // when AddMvc() is not called. - - // Add MVC to the request pipeline - app.UseMvc(routes => - { - routes.MapRoute("areaRoute", - "{area:exists}/{controller}/{action}", - new { controller = "Home", action = "Index" }); - - routes.MapRoute("ActionAsMethod", "{controller}/{action}", - defaults: new { controller = "Home", action = "Index" }); - - }); - } - } -} diff --git a/test/WebSites/AddServicesWebSite/project.json b/test/WebSites/AddServicesWebSite/project.json deleted file mode 100644 index 14c1cb9408..0000000000 --- a/test/WebSites/AddServicesWebSite/project.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "commands": { - "web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001", - "kestrel": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://localhost:5000" - }, - "dependencies": { - "Microsoft.AspNet.Server.Kestrel": "1.0.0-*", - "Microsoft.AspNet.Mvc": "6.0.0-*", - "Microsoft.AspNet.Mvc.TestConfiguration": "1.0.0", - "Microsoft.AspNet.Server.WebListener": "1.0.0-*", - "Microsoft.AspNet.StaticFiles": "1.0.0-*" - }, - "frameworks": { - "dnx451": { }, - "dnxcore50": { } - }, - "webroot": "wwwroot" -} diff --git a/test/WebSites/AddServicesWebSite/readme.md b/test/WebSites/AddServicesWebSite/readme.md deleted file mode 100644 index 5d85807c0c..0000000000 --- a/test/WebSites/AddServicesWebSite/readme.md +++ /dev/null @@ -1,4 +0,0 @@ -AddServicesWebSite -=== - -This web site throws since the startup does not call AddMvc(). diff --git a/test/WebSites/AddServicesWebSite/wwwroot/HelloWorld.htm b/test/WebSites/AddServicesWebSite/wwwroot/HelloWorld.htm deleted file mode 100644 index 3da1ec26e9..0000000000 --- a/test/WebSites/AddServicesWebSite/wwwroot/HelloWorld.htm +++ /dev/null @@ -1 +0,0 @@ -HelloWorld diff --git a/test/WebSites/HtmlGenerationWebSite/Startup.cs b/test/WebSites/HtmlGenerationWebSite/Startup.cs index 500a904e2e..12c56332d5 100644 --- a/test/WebSites/HtmlGenerationWebSite/Startup.cs +++ b/test/WebSites/HtmlGenerationWebSite/Startup.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Mvc.TagHelpers; using Microsoft.Extensions.DependencyInjection; namespace HtmlGenerationWebSite @@ -11,8 +12,10 @@ namespace HtmlGenerationWebSite // Set up application services public void ConfigureServices(IServiceCollection services) { - // Add MVC services to the services container - services.AddMvc(); + // Add MVC services to the services container. Change default FormTagHelper.AntiForgery to false. Usually + // null which is interpreted as true unless element includes an action attribute. + services.AddMvc().InitializeTagHelper((helper, _) => helper.Antiforgery = false); + services.AddSingleton(); } diff --git a/test/WebSites/HtmlGenerationWebSite/Views/Shared/Customer.cshtml b/test/WebSites/HtmlGenerationWebSite/Views/Shared/Customer.cshtml index c757d592d0..a8f9b8e12f 100644 --- a/test/WebSites/HtmlGenerationWebSite/Views/Shared/Customer.cshtml +++ b/test/WebSites/HtmlGenerationWebSite/Views/Shared/Customer.cshtml @@ -8,7 +8,7 @@ -
+