Add a test that verifies strong name signing works for precompiled views

Fixes #16
This commit is contained in:
Pranav K 2016-09-12 14:56:09 -07:00
parent 755957b694
commit 3b45ea5c27
14 changed files with 202 additions and 28 deletions

View File

@ -21,6 +21,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ClassLibraryWithPrecompiled
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "PublishWIthEmbedViewSources", "testapps\PublishWIthEmbedViewSources\PublishWIthEmbedViewSources.xproj", "{E3462190-3068-40F0-9AA5-34779FE252AC}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "StrongNamedApp", "testapps\StrongNamedApp\StrongNamedApp.xproj", "{88903BE5-0676-4667-8160-B24646E0B76E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -51,6 +53,10 @@ Global
{E3462190-3068-40F0-9AA5-34779FE252AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E3462190-3068-40F0-9AA5-34779FE252AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E3462190-3068-40F0-9AA5-34779FE252AC}.Release|Any CPU.Build.0 = Release|Any CPU
{88903BE5-0676-4667-8160-B24646E0B76E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{88903BE5-0676-4667-8160-B24646E0B76E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{88903BE5-0676-4667-8160-B24646E0B76E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{88903BE5-0676-4667-8160-B24646E0B76E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -23,13 +23,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Precompilation
public ApplicationTestFixture Fixture { get; }
public static IEnumerable<object[]> SupportedFlavorsTheoryData
{
get
{
return RuntimeFlavors.SupportedFlavors.Select(f => new object[] { f });
}
}
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
[Theory]
[MemberData(nameof(SupportedFlavorsTheoryData))]

View File

@ -19,13 +19,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Precompilation
public ApplicationTestFixture Fixture { get; }
public static IEnumerable<object[]> SupportedFlavorsTheoryData
{
get
{
return RuntimeFlavors.SupportedFlavors.Select(f => new object[] { f });
}
}
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
[Theory]
[MemberData(nameof(SupportedFlavorsTheoryData))]

View File

@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Xunit;
namespace Microsoft.AspNetCore.Mvc.Razor.Precompilation
{
@ -20,5 +21,19 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Precompilation
}
}
}
public static TheoryData SupportedFlavorsTheoryData
{
get
{
var theory = new TheoryData<RuntimeFlavor>();
foreach (var item in SupportedFlavors)
{
theory.Add(item);
}
return theory;
}
}
}
}

View File

@ -23,13 +23,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Precompilation.FunctionalTests
public ApplicationTestFixture Fixture { get; }
public static IEnumerable<object[]> SupportedFlavorsTheoryData
{
get
{
return RuntimeFlavors.SupportedFlavors.Select(f => new object[] { f });
}
}
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
[Theory]
[MemberData(nameof(SupportedFlavorsTheoryData))]

View File

@ -0,0 +1 @@
Hello from view in AspNetCore.Views_Home_Index_cshtml, StrongNamedApp.PrecompiledViews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60

View File

@ -18,13 +18,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Precompilation
public ApplicationTestFixture Fixture { get; }
public static IEnumerable<object[]> SupportedFlavorsTheoryData
{
get
{
return RuntimeFlavors.SupportedFlavors.Select(f => new object[] { f });
}
}
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
[Theory]
[MemberData(nameof(SupportedFlavorsTheoryData))]

View File

@ -0,0 +1,50 @@
// 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.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Xunit;
namespace Microsoft.AspNetCore.Mvc.Razor.Precompilation
{
public class StrongNamedAppTest : IClassFixture<StrongNamedAppTest.StrongNamedAppFixture>
{
public StrongNamedAppTest(StrongNamedAppFixture fixture)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
[Theory]
[MemberData(nameof(SupportedFlavorsTheoryData))]
public async Task PrecompiledAssembliesUseSameStrongNameAsApplication(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("StrongNamedApp.Home.Index.txt", response);
}
}
public class StrongNamedAppFixture : ApplicationTestFixture
{
public StrongNamedAppFixture()
: base("StrongNamedApp")
{
}
}
}
}

View File

@ -0,0 +1,9 @@
using Microsoft.AspNetCore.Mvc;
namespace StrongNamedApp.Controllers
{
public class HomeController : Controller
{
public IActionResult Index() => View();
}
}

View File

@ -0,0 +1,26 @@
using System.IO;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
namespace StrongNamedApp
{
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<Startup>()
.Build();
host.Run();
}
}
}

View File

@ -0,0 +1,26 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace StrongNamedApp
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
}
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0.25420" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.25420</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>88903be5-0676-4667-8160-b24646e0b76e</ProjectGuid>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

View File

@ -0,0 +1 @@
Hello from view in @GetType().AssemblyQualifiedName

View File

@ -0,0 +1,46 @@
{
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true,
"keyFile": "../../tools/Key.snk",
},
"dependencies": {
"Microsoft.AspNetCore.Mvc": "1.1.0-*",
"Microsoft.AspNetCore.Mvc.Razor.Precompilation.Design": {
"version": "1.0.0-*",
"target": "package",
"type": "build"
},
"Microsoft.AspNetCore.Server.Kestrel": "1.1.0-*",
"Microsoft.Extensions.Configuration.CommandLine": "1.1.0-*",
"Microsoft.Extensions.Logging.Console": "1.1.0-*"
},
"tools": {
"Microsoft.AspNetCore.Mvc.Razor.Precompilation.Tools": "1.0.0-*"
},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
}
}
},
"net451": {}
},
"publishOptions": {
"include": [
"wwwroot",
"appsettings.json",
"web.config"
]
},
"scripts": {
"postpublish": "dotnet razor-precompile --configuration %publish:Configuration% --framework %publish:TargetFramework% --output-path %publish:OutputPath% %publish:ProjectPath%"
}
}