diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/ApplicationUsingRelativePathsTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/ApplicationUsingRelativePathsTest.cs new file mode 100644 index 0000000000..0f09ecb982 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/ApplicationUsingRelativePathsTest.cs @@ -0,0 +1,68 @@ +// 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.Threading.Tasks; +using Microsoft.AspNetCore.Server.IntegrationTesting; +using Xunit; + +namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation +{ + public class ApplicationUsingRelativePathsTest : + IClassFixture + { + public ApplicationUsingRelativePathsTest(ApplicationUsingRelativePathsTestFixture fixture) + { + Fixture = fixture; + } + + public ApplicationTestFixture Fixture { get; } + + public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData; + + [Theory] + [MemberData(nameof(SupportedFlavorsTheoryData))] + public async Task Precompilation_WorksForViewsUsingRelativePath(RuntimeFlavor flavor) + { + // Arrange + using (var deployer = Fixture.CreateDeployment(flavor)) + { + var deploymentResult = deployer.Deploy(); + + // Act + var response = await Fixture.HttpClient.GetStringWithRetryAsync( + deploymentResult.ApplicationBaseUri, + Fixture.Logger); + + // Assert + TestEmbeddedResource.AssertContent("ApplicationUsingRelativePaths.Home.Index.txt", response); + } + } + + [Theory] + [MemberData(nameof(SupportedFlavorsTheoryData))] + public async Task Precompilation_WorksForViewsUsingDirectoryTraversal(RuntimeFlavor flavor) + { + // Arrange + using (var deployer = Fixture.CreateDeployment(flavor)) + { + var deploymentResult = deployer.Deploy(); + + // Act + var response = await Fixture.HttpClient.GetStringWithRetryAsync( + deploymentResult.ApplicationBaseUri, + Fixture.Logger); + + // Assert + TestEmbeddedResource.AssertContent("ApplicationUsingRelativePaths.Home.About.txt", response); + } + } + + public class ApplicationUsingRelativePathsTestFixture : ApplicationTestFixture + { + public ApplicationUsingRelativePathsTestFixture() + : base("ApplicationUsingRelativePaths") + { + } + } + } +} diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/ApplicationUsingRelativePaths.Home.About.txt b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/ApplicationUsingRelativePaths.Home.About.txt new file mode 100644 index 0000000000..29277b2c98 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/ApplicationUsingRelativePaths.Home.About.txt @@ -0,0 +1,8 @@ + + + + +AspNetCore._Views_Home_Index_cshtml, ApplicationUsingRelativePaths.PrecompiledViews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null +Hello from Index! + + \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/ApplicationUsingRelativePaths.Home.Index.txt b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/ApplicationUsingRelativePaths.Home.Index.txt new file mode 100644 index 0000000000..29277b2c98 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/ApplicationUsingRelativePaths.Home.Index.txt @@ -0,0 +1,8 @@ + + + + +AspNetCore._Views_Home_Index_cshtml, ApplicationUsingRelativePaths.PrecompiledViews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null +Hello from Index! + + \ No newline at end of file diff --git a/testapps/ApplicationUsingRelativePaths/ApplicationUsingRelativePaths.csproj b/testapps/ApplicationUsingRelativePaths/ApplicationUsingRelativePaths.csproj new file mode 100644 index 0000000000..00372f0185 --- /dev/null +++ b/testapps/ApplicationUsingRelativePaths/ApplicationUsingRelativePaths.csproj @@ -0,0 +1,24 @@ + + + netcoreapp1.1;net451 + true + Exe + win7-x64 + true + + + + + 1.1.0-* + All + + + + + + + + + + + diff --git a/testapps/ApplicationUsingRelativePaths/Controllers/HomeController.cs b/testapps/ApplicationUsingRelativePaths/Controllers/HomeController.cs new file mode 100644 index 0000000000..33ac0b1682 --- /dev/null +++ b/testapps/ApplicationUsingRelativePaths/Controllers/HomeController.cs @@ -0,0 +1,19 @@ +using Microsoft.AspNetCore.Mvc; + +namespace ApplicationUsingRelativePaths.Controllers +{ + public class HomeController : Controller + { + public IActionResult Index() + { + return View("Views/Home/Index.cshtml"); + } + + public IActionResult About() + { + ViewData["Message"] = "Your application description page."; + + return View(); + } + } +} diff --git a/testapps/ApplicationUsingRelativePaths/Program.cs b/testapps/ApplicationUsingRelativePaths/Program.cs new file mode 100644 index 0000000000..5d496db40e --- /dev/null +++ b/testapps/ApplicationUsingRelativePaths/Program.cs @@ -0,0 +1,26 @@ +using System.IO; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; + +namespace ApplicationUsingRelativePaths +{ + public class Program + { + public static void Main(string[] args) + { + var config = new ConfigurationBuilder() + .AddCommandLine(args) + .AddEnvironmentVariables(prefix: "ASPNETCORE_") + .Build(); + + var host = new WebHostBuilder() + .UseConfiguration(config) + .UseKestrel() + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseStartup() + .Build(); + + host.Run(); + } + } +} diff --git a/testapps/ApplicationUsingRelativePaths/Startup.cs b/testapps/ApplicationUsingRelativePaths/Startup.cs new file mode 100644 index 0000000000..9f7dbdf562 --- /dev/null +++ b/testapps/ApplicationUsingRelativePaths/Startup.cs @@ -0,0 +1,21 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +namespace ApplicationUsingRelativePaths +{ + public class Startup + { + public void ConfigureServices(IServiceCollection services) + { + // Add framework services. + services.AddMvc(); + } + + public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) + { + loggerFactory.AddConsole(); + app.UseMvcWithDefaultRoute(); + } + } +} diff --git a/testapps/ApplicationUsingRelativePaths/Views/Home/About.cshtml b/testapps/ApplicationUsingRelativePaths/Views/Home/About.cshtml new file mode 100644 index 0000000000..bbc0672575 --- /dev/null +++ b/testapps/ApplicationUsingRelativePaths/Views/Home/About.cshtml @@ -0,0 +1,8 @@ +@{ + Layout = "../Shared/_Layout.cshtml"; + ViewData["Title"] = "About"; +} +

@ViewData["Title"].

+

@ViewData["Message"]

+ +

Use this area to provide additional information.

diff --git a/testapps/ApplicationUsingRelativePaths/Views/Home/Index.cshtml b/testapps/ApplicationUsingRelativePaths/Views/Home/Index.cshtml new file mode 100644 index 0000000000..d29ab9cb6e --- /dev/null +++ b/testapps/ApplicationUsingRelativePaths/Views/Home/Index.cshtml @@ -0,0 +1,6 @@ +@{ + ViewData["Title"] = "Home Page"; +} + +@GetType().AssemblyQualifiedName +Hello from Index! \ No newline at end of file diff --git a/testapps/ApplicationUsingRelativePaths/Views/Shared/_Layout.cshtml b/testapps/ApplicationUsingRelativePaths/Views/Shared/_Layout.cshtml new file mode 100644 index 0000000000..4c909415a4 --- /dev/null +++ b/testapps/ApplicationUsingRelativePaths/Views/Shared/_Layout.cshtml @@ -0,0 +1,6 @@ + + + + @RenderBody() + + \ No newline at end of file diff --git a/testapps/ApplicationUsingRelativePaths/Views/_ViewImports.cshtml b/testapps/ApplicationUsingRelativePaths/Views/_ViewImports.cshtml new file mode 100644 index 0000000000..64245a9c34 --- /dev/null +++ b/testapps/ApplicationUsingRelativePaths/Views/_ViewImports.cshtml @@ -0,0 +1,2 @@ +@using ApplicationUsingRelativePaths +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers diff --git a/testapps/ApplicationUsingRelativePaths/Views/_ViewStart.cshtml b/testapps/ApplicationUsingRelativePaths/Views/_ViewStart.cshtml new file mode 100644 index 0000000000..1b4f3a0748 --- /dev/null +++ b/testapps/ApplicationUsingRelativePaths/Views/_ViewStart.cshtml @@ -0,0 +1,3 @@ +@{ + Layout = "Shared/_Layout.cshtml"; +}