From 6596d9776a633bbd93d2204501c3b4bf43147e43 Mon Sep 17 00:00:00 2001 From: maliming Date: Wed, 15 Dec 2021 14:40:21 +0800 Subject: [PATCH] Fix unit tests. --- .../AbpMvcBuilderExtensions.cs | 23 ++++++++++++-- .../AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs | 9 ------ .../Volo.Abp.AspNetCore.Mvc.Tests.csproj | 30 ------------------- .../Mvc/AbpAspNetCoreMvcTestModule.cs | 6 ++++ 4 files changed, 26 insertions(+), 42 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Microsoft/Extensions/DependencyInjection/AbpMvcBuilderExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Microsoft/Extensions/DependencyInjection/AbpMvcBuilderExtensions.cs index c7f3777466..48e4f2716f 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Microsoft/Extensions/DependencyInjection/AbpMvcBuilderExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Microsoft/Extensions/DependencyInjection/AbpMvcBuilderExtensions.cs @@ -1,7 +1,11 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using System.Reflection; using Microsoft.AspNetCore.Mvc.ApplicationParts; +using Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation; +using Volo.Abp.AspNetCore.VirtualFileSystem; +using Volo.Abp.DependencyInjection; namespace Microsoft.Extensions.DependencyInjection { @@ -11,12 +15,12 @@ namespace Microsoft.Extensions.DependencyInjection { mvcBuilder.PartManager.ApplicationParts.AddIfNotContains(assembly); } - + public static void AddApplicationPartIfNotExists(this IMvcCoreBuilder mvcCoreBuilder, Assembly assembly) { mvcCoreBuilder.PartManager.ApplicationParts.AddIfNotContains(assembly); } - + public static void AddIfNotContains(this IList applicationParts, Assembly assembly) { if (applicationParts.Any( @@ -27,5 +31,18 @@ namespace Microsoft.Extensions.DependencyInjection applicationParts.Add(new AssemblyPart(assembly)); } + + public static void AddAbpRazorRuntimeCompilation(this IMvcBuilder mvcCoreBuilder) + { + mvcCoreBuilder.AddRazorRuntimeCompilation(); + mvcCoreBuilder.Services.Configure(options => + { + options.FileProviders.Add( + new RazorViewEngineVirtualFileProvider( + mvcCoreBuilder.Services.GetSingletonInstance>() + ) + ); + }); + } } } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs index cbc81f352b..b08406fcf0 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs @@ -140,15 +140,6 @@ namespace Volo.Abp.AspNetCore.Mvc mvcCoreBuilder.AddAbpHybridJson(); - Configure(options => - { - options.FileProviders.Add( - new RazorViewEngineVirtualFileProvider( - context.Services.GetSingletonInstance>() - ) - ); - }); - context.Services.ExecutePreConfiguredActions(mvcBuilder); //TODO: AddViewLocalization by default..? diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo.Abp.AspNetCore.Mvc.Tests.csproj b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo.Abp.AspNetCore.Mvc.Tests.csproj index 3a923ba799..4e1b5e1334 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo.Abp.AspNetCore.Mvc.Tests.csproj +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo.Abp.AspNetCore.Mvc.Tests.csproj @@ -40,36 +40,6 @@ PreserveNewest - - - true - PreserveNewest - - - true - PreserveNewest - - - true - PreserveNewest - - - true - PreserveNewest - - - true - PreserveNewest - - - true - PreserveNewest - - - true - PreserveNewest - - diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs index 0b84b00f7d..2c8ba3d8d1 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Security.Claims; using Localization.Resources.AbpUi; using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Mvc.Razor; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.Extensions.DependencyInjection; using Volo.Abp.AspNetCore.Mvc.Authorization; @@ -115,6 +116,11 @@ namespace Volo.Abp.AspNetCore.Mvc options.RootDirectory = "/Volo/Abp/AspNetCore/Mvc"; }); + Configure(options => + { + options.ViewLocationFormats.Add("/Volo/Abp/AspNetCore/App/Views/{1}/{0}.cshtml"); + }); + Configure(options => { options.Maps.Add("SerialNumber", () => ClaimTypes.SerialNumber);