From a187831b73a67c24f3526d194dd5d5f588b318f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 10 Sep 2019 18:02:56 +0300 Subject: [PATCH] Added VirtualFileSystem_Tests that is failing --- .../Mvc/AbpAspNetCoreMvcTestModule.cs | 1 + .../Volo.Abp.AspNetCore.Tests.csproj | 6 +++ .../Abp/AspNetCore/AbpAspNetCoreTestBase.cs | 5 ++ .../Abp/AspNetCore/AbpAspNetCoreTestModule.cs | 52 +++++++++++++++++++ .../Volo/Abp/AspNetCore/Startup.cs | 26 ++++++++++ .../VirtualFileSystem_Tests.cs | 19 +++++++ .../wwwroot/SampleFiles/test1.js | 1 + 7 files changed, 110 insertions(+) create mode 100644 framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/AbpAspNetCoreTestModule.cs create mode 100644 framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/Startup.cs create mode 100644 framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/VirtualFileSystem/VirtualFileSystem_Tests.cs create mode 100644 framework/test/Volo.Abp.AspNetCore.Tests/wwwroot/SampleFiles/test1.js 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 1a12f5d6f9..9f8a7fedfb 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 @@ -77,6 +77,7 @@ namespace Volo.Abp.AspNetCore.Mvc var app = context.GetApplicationBuilder(); app.UseCorrelationId(); + app.UseVirtualFiles(); app.UseRouting(); app.UseMiddleware(); app.UseAuthorization(); diff --git a/framework/test/Volo.Abp.AspNetCore.Tests/Volo.Abp.AspNetCore.Tests.csproj b/framework/test/Volo.Abp.AspNetCore.Tests/Volo.Abp.AspNetCore.Tests.csproj index 4050b40ea1..983e8fcb39 100644 --- a/framework/test/Volo.Abp.AspNetCore.Tests/Volo.Abp.AspNetCore.Tests.csproj +++ b/framework/test/Volo.Abp.AspNetCore.Tests/Volo.Abp.AspNetCore.Tests.csproj @@ -12,9 +12,15 @@ false + + + + + + diff --git a/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/AbpAspNetCoreTestBase.cs b/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/AbpAspNetCoreTestBase.cs index 33beb9d62c..40ce2d2a31 100644 --- a/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/AbpAspNetCoreTestBase.cs +++ b/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/AbpAspNetCoreTestBase.cs @@ -8,6 +8,11 @@ using Volo.Abp.AspNetCore.TestBase; namespace Volo.Abp.AspNetCore { + public class AbpAspNetCoreTestBase : AbpAspNetCoreTestBase + { + + } + public abstract class AbpAspNetCoreTestBase : AbpAspNetCoreIntegratedTestBase where TStartup : class { diff --git a/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/AbpAspNetCoreTestModule.cs b/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/AbpAspNetCoreTestModule.cs new file mode 100644 index 0000000000..2941afa087 --- /dev/null +++ b/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/AbpAspNetCoreTestModule.cs @@ -0,0 +1,52 @@ +using System; +using System.IO; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.AspNetCore.TestBase; +using Volo.Abp.Autofac; +using Volo.Abp.Modularity; +using Volo.Abp.VirtualFileSystem; + +namespace Volo.Abp.AspNetCore +{ + [DependsOn( + typeof(AbpAspNetCoreTestBaseModule), + typeof(AbpAspNetCoreModule), + typeof(AbpAutofacModule) + )] + public class AbpAspNetCoreTestModule : AbpModule + { + public override void ConfigureServices(ServiceConfigurationContext context) + { + var hostingEnvironment = context.Services.GetHostingEnvironment(); + + Configure(options => + { + options.FileSets.AddEmbedded(); + //options.FileSets.ReplaceEmbeddedByPhysical(FindProjectPath(hostingEnvironment)); + }); + } + + public override void OnApplicationInitialization(ApplicationInitializationContext context) + { + var app = context.GetApplicationBuilder(); + + app.UseCorrelationId(); + app.UseVirtualFiles(); + } + + private string FindProjectPath(IWebHostEnvironment hostEnvironment) + { + var directory = new DirectoryInfo(hostEnvironment.ContentRootPath); + + while (directory != null && directory.Name != "Volo.Abp.AspNetCore.Tests") + { + directory = directory.Parent; + } + + return directory?.FullName + ?? throw new Exception("Could not find the project path by beginning from " + hostEnvironment.ContentRootPath + ", going through to parents and looking for Volo.Abp.AspNetCore.Tests"); + } + } +} diff --git a/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/Startup.cs b/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/Startup.cs new file mode 100644 index 0000000000..7f95713274 --- /dev/null +++ b/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/Startup.cs @@ -0,0 +1,26 @@ +using System; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +namespace Volo.Abp.AspNetCore +{ + public class Startup + { + public IServiceProvider ConfigureServices(IServiceCollection services) + { + services.AddApplication(options => + { + options.UseAutofac(); + }); + + return services.BuildServiceProviderFromFactory(); + } + + public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) + { + app.InitializeApplication(); + } + } +} diff --git a/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/VirtualFileSystem/VirtualFileSystem_Tests.cs b/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/VirtualFileSystem/VirtualFileSystem_Tests.cs new file mode 100644 index 0000000000..142d44baec --- /dev/null +++ b/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/VirtualFileSystem/VirtualFileSystem_Tests.cs @@ -0,0 +1,19 @@ +using System.Threading.Tasks; +using Shouldly; +using Xunit; + +namespace Volo.Abp.AspNetCore.VirtualFileSystem +{ + public class VirtualFileSystem_Tests : AbpAspNetCoreTestBase + { + [Fact] + public async Task Get_Virtual_File() + { + var result = await GetResponseAsStringAsync( + "/SampleFiles/test1.js" + ); + + result.ShouldBe("test1.js-content"); + } + } +} diff --git a/framework/test/Volo.Abp.AspNetCore.Tests/wwwroot/SampleFiles/test1.js b/framework/test/Volo.Abp.AspNetCore.Tests/wwwroot/SampleFiles/test1.js new file mode 100644 index 0000000000..20a6856cb7 --- /dev/null +++ b/framework/test/Volo.Abp.AspNetCore.Tests/wwwroot/SampleFiles/test1.js @@ -0,0 +1 @@ +test1.js-content \ No newline at end of file