Skip to content

Commit ab16a0f

Browse files
committed
Added built-in support for Razor runtime compilation (closes #377, closes #386)
1 parent a569575 commit ab16a0f

File tree

63 files changed

+376
-98
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+376
-98
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
MyTested.AspNetCore.Mvc
2-
Code by Ivaylo Kenov. Copyright (c) 2015-2019 Ivaylo Kenov.
2+
Code by Ivaylo Kenov. Copyright (c) 2015-2021 Ivaylo Kenov.
33
===============================================================================
44

55
This program is free software: you can redistribute it and/or modify it

MyTested.AspNetCore.Mvc.sln

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApplication", "samples\C
229229
EndProject
230230
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test.MultipleEntryPoints", "samples\Configuration\Test.MultipleEntryPoints\Test.MultipleEntryPoints.csproj", "{840C7C04-90CC-4F0F-BDF9-0D97D399BA3F}"
231231
EndProject
232-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common", "samples\Configuration\Common\Common.csproj", "{AC971EBF-48A1-47C1-B61F-CF97FCE4F48C}"
232+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AdditionalEntryPoint", "samples\Configuration\Common\AdditionalEntryPoint.csproj", "{AC971EBF-48A1-47C1-B61F-CF97FCE4F48C}"
233233
EndProject
234234
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyTested.AspNetCore.Mvc.Versioning", "plugins\MyTested.AspNetCore.Mvc.Versioning\MyTested.AspNetCore.Mvc.Versioning.csproj", "{3529E0FC-4D63-4828-A3DC-ACE7B6243A73}"
235235
EndProject
236236
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyTested.AspNetCore.Mvc.Versioning.Test", "test\MyTested.AspNetCore.Mvc.Versioning.Test\MyTested.AspNetCore.Mvc.Versioning.Test.csproj", "{6541FC98-C8B1-48CF-A3A5-7028B19455E8}"
237237
EndProject
238+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyTested.AspNetCore.Mvc.Razor.RuntimeCompilation", "plugins\MyTested.AspNetCore.Mvc.Razor.RuntimeCompilation\MyTested.AspNetCore.Mvc.Razor.RuntimeCompilation.csproj", "{A9353C8C-3EF6-4677-B4D3-8BEB350AC0B0}"
239+
EndProject
240+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyTested.AspNetCore.Mvc.Razor.RuntimeCompilation.Test", "test\MyTested.AspNetCore.Mvc.Razor.RuntimeCompilation.Test\MyTested.AspNetCore.Mvc.Razor.RuntimeCompilation.Test.csproj", "{A40A442E-E39B-4EA5-839A-3893AD66A700}"
241+
EndProject
238242
Global
239243
GlobalSection(SolutionConfigurationPlatforms) = preSolution
240244
Debug|Any CPU = Debug|Any CPU
@@ -657,6 +661,14 @@ Global
657661
{6541FC98-C8B1-48CF-A3A5-7028B19455E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
658662
{6541FC98-C8B1-48CF-A3A5-7028B19455E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
659663
{6541FC98-C8B1-48CF-A3A5-7028B19455E8}.Release|Any CPU.Build.0 = Release|Any CPU
664+
{A9353C8C-3EF6-4677-B4D3-8BEB350AC0B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
665+
{A9353C8C-3EF6-4677-B4D3-8BEB350AC0B0}.Debug|Any CPU.Build.0 = Debug|Any CPU
666+
{A9353C8C-3EF6-4677-B4D3-8BEB350AC0B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
667+
{A9353C8C-3EF6-4677-B4D3-8BEB350AC0B0}.Release|Any CPU.Build.0 = Release|Any CPU
668+
{A40A442E-E39B-4EA5-839A-3893AD66A700}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
669+
{A40A442E-E39B-4EA5-839A-3893AD66A700}.Debug|Any CPU.Build.0 = Debug|Any CPU
670+
{A40A442E-E39B-4EA5-839A-3893AD66A700}.Release|Any CPU.ActiveCfg = Release|Any CPU
671+
{A40A442E-E39B-4EA5-839A-3893AD66A700}.Release|Any CPU.Build.0 = Release|Any CPU
660672
EndGlobalSection
661673
GlobalSection(SolutionProperties) = preSolution
662674
HideSolutionNode = FALSE
@@ -774,6 +786,8 @@ Global
774786
{AC971EBF-48A1-47C1-B61F-CF97FCE4F48C} = {7BEC9808-8650-4322-BCC6-1D7D91B53678}
775787
{3529E0FC-4D63-4828-A3DC-ACE7B6243A73} = {EF386110-3D7B-4BDF-B403-8DC2AB8CF7BB}
776788
{6541FC98-C8B1-48CF-A3A5-7028B19455E8} = {D140FA14-A6C2-4279-8A41-35BC55279DA8}
789+
{A9353C8C-3EF6-4677-B4D3-8BEB350AC0B0} = {EF386110-3D7B-4BDF-B403-8DC2AB8CF7BB}
790+
{A40A442E-E39B-4EA5-839A-3893AD66A700} = {D140FA14-A6C2-4279-8A41-35BC55279DA8}
777791
EndGlobalSection
778792
GlobalSection(ExtensibilityGlobals) = postSolution
779793
SolutionGuid = {99A2DEDD-5195-4EE6-A546-B1CA54C5539F}

plugins/MyTested.AspNetCore.Mvc.NewtonsoftJson/MyTested.AspNetCore.Mvc.NewtonsoftJson.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<Description>My Tested ASP.NET Core MVC Newtonsoft JSON components.</Description>
5-
<Copyright>2015-2019 Ivaylo Kenov</Copyright>
5+
<Copyright>2015-2021 Ivaylo Kenov</Copyright>
66
<AssemblyTitle>MyTested.AspNetCore.Mvc.NewtonsoftJson</AssemblyTitle>
77
<VersionPrefix>5.0.0</VersionPrefix>
88
<Authors>Ivaylo Kenov</Authors>
@@ -29,7 +29,7 @@
2929
</PropertyGroup>
3030

3131
<ItemGroup>
32-
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.7" />
32+
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.8" />
3333
</ItemGroup>
3434

3535
<ItemGroup>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace MyTested.AspNetCore.Mvc.Internal.Razor
2+
{
3+
using Microsoft.Extensions.Primitives;
4+
using System;
5+
6+
public class ChangeTokenMock : IChangeToken
7+
{
8+
public static ChangeTokenMock Instance => new ChangeTokenMock();
9+
10+
public bool ActiveChangeCallbacks => false;
11+
12+
public bool HasChanged => false;
13+
14+
public IDisposable RegisterChangeCallback(Action<object> callback, object state) => DisposableMock.Instance;
15+
}
16+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace MyTested.AspNetCore.Mvc.Internal.Razor
2+
{
3+
using Microsoft.AspNetCore.Mvc.Infrastructure;
4+
using Microsoft.Extensions.Primitives;
5+
6+
public class TestActionDescriptorChangeProvider : IActionDescriptorChangeProvider
7+
{
8+
public IChangeToken GetChangeToken() => ChangeTokenMock.Instance;
9+
}
10+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<Description>My Tested ASP.NET Core MVC razor runtime compilation components.</Description>
5+
<Copyright>2015-2021 Ivaylo Kenov</Copyright>
6+
<AssemblyTitle>MyTested.AspNetCore.Mvc.Razor.RuntimeCompilation</AssemblyTitle>
7+
<VersionPrefix>5.0.0</VersionPrefix>
8+
<Authors>Ivaylo Kenov</Authors>
9+
<TargetFramework>net5.0</TargetFramework>
10+
<NoWarn>$(NoWarn);CS1591</NoWarn>
11+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
12+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
13+
<AssemblyName>MyTested.AspNetCore.Mvc.Razor.RuntimeCompilation</AssemblyName>
14+
<AssemblyOriginatorKeyFile>../../tools/Key.snk</AssemblyOriginatorKeyFile>
15+
<SignAssembly>true</SignAssembly>
16+
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
17+
<PackageId>MyTested.AspNetCore.Mvc.Razor.RuntimeCompilation</PackageId>
18+
<PackageTags>aspnetcore;aspnetcoremvc;testing;unit;tests;fluent;testing;framework;asp;net;core;mvc;test;mymvc;mytested</PackageTags>
19+
<PackageIcon>nuget-logo.png</PackageIcon>
20+
<PackageProjectUrl>https://mytestedasp.net/</PackageProjectUrl>
21+
<PackageLicenseFile>LICENSE</PackageLicenseFile>
22+
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
23+
<RepositoryType>git</RepositoryType>
24+
<RepositoryUrl>https://github.com/ivaylokenov/MyTested.AspNetCore.Mvc</RepositoryUrl>
25+
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
26+
<RootNamespace>MyTested.AspNetCore.Mvc</RootNamespace>
27+
<IncludeSymbols>true</IncludeSymbols>
28+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
29+
</PropertyGroup>
30+
31+
<ItemGroup>
32+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="5.0.8" />
33+
</ItemGroup>
34+
35+
<ItemGroup>
36+
<None Include="../../LICENSE" Pack="true" PackagePath="" />
37+
<None Include="../../tools/nuget-logo.png" Pack="true" PackagePath="" />
38+
</ItemGroup>
39+
40+
<ItemGroup>
41+
<ProjectReference Include="..\..\src\MyTested.AspNetCore.Mvc.ViewFeatures\MyTested.AspNetCore.Mvc.ViewFeatures.csproj" />
42+
</ItemGroup>
43+
44+
</Project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace MyTested.AspNetCore.Mvc.Plugins
2+
{
3+
using System;
4+
using Microsoft.AspNetCore.Mvc.Infrastructure;
5+
using Microsoft.Extensions.DependencyInjection;
6+
7+
public class RazorRuntimeCompilationTestPlugin : IServiceRegistrationPlugin
8+
{
9+
private readonly Type defaultActionDescriptorChangeProviderServiceType = typeof(IActionDescriptorChangeProvider);
10+
11+
public Func<ServiceDescriptor, bool> ServiceSelectorPredicate
12+
=> serviceDescriptor => serviceDescriptor.ServiceType == this.defaultActionDescriptorChangeProviderServiceType;
13+
14+
public Action<IServiceCollection> ServiceRegistrationDelegate
15+
=> serviceCollection => serviceCollection.ReplaceRazorRuntimeCompilation();
16+
}
17+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
namespace MyTested.AspNetCore.Mvc
2+
{
3+
using Microsoft.AspNetCore.Mvc.Abstractions;
4+
using Microsoft.AspNetCore.Mvc.Infrastructure;
5+
using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure;
6+
using Microsoft.Extensions.DependencyInjection;
7+
using MyTested.AspNetCore.Mvc.Internal.Razor;
8+
9+
/// <summary>
10+
/// Contains Razor runtime compilation extension methods for <see cref="IServiceCollection"/>.
11+
/// </summary>
12+
public static class ServiceCollectionRazorRuntimeCompilationExtensions
13+
{
14+
/// <summary>
15+
/// Replaces the default <see cref="IActionDescriptorChangeProvider"/> with a mocked implementation..
16+
/// </summary>
17+
/// <param name="serviceCollection">Instance of <see cref="IServiceCollection"/> type.</param>
18+
/// <returns>The same <see cref="IServiceCollection"/>.</returns>
19+
public static IServiceCollection ReplaceRazorRuntimeCompilation(this IServiceCollection serviceCollection)
20+
=> serviceCollection
21+
.Remove<IActionDescriptorProvider, PageActionDescriptorProvider>()
22+
.ReplaceSingleton<IActionDescriptorChangeProvider, TestActionDescriptorChangeProvider>();
23+
}
24+
}

plugins/MyTested.AspNetCore.Mvc.Versioning/MyTested.AspNetCore.Mvc.Versioning.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<Description>My Tested ASP.NET Core MVC versioning components.</Description>
5-
<Copyright>2015-2019 Ivaylo Kenov</Copyright>
5+
<Copyright>2015-2021 Ivaylo Kenov</Copyright>
66
<AssemblyTitle>MyTested.AspNetCore.Mvc.Versioning</AssemblyTitle>
77
<VersionPrefix>5.0.0</VersionPrefix>
88
<Authors>Ivaylo Kenov</Authors>

samples/ApplicationParts/ApplicationParts.Controllers/ApplicationParts.Controllers.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</ItemGroup>
1818

1919
<ItemGroup>
20-
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.7" />
20+
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.8" />
2121
</ItemGroup>
2222

2323
</Project>

0 commit comments

Comments
 (0)