From 5ad5a6859cbc1f0f2a81873bf949d114db0961ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Wed, 30 Aug 2017 14:36:17 +0300 Subject: [PATCH] Revised basic ASP.NETCore-integrated tests. --- ...o.Abp.AspNetCore.MultiTenancy.Tests.csproj | 3 +-- .../Volo/Abp/AspNetCore/App/AppModule.cs | 8 ++++++ .../Volo/Abp/AspNetCore/App/Startup.cs | 6 ----- .../AspNetCoreMultiTenancyTestBase.cs | 9 +++++++ .../AspNetCoreMultiTenancy_Tests.cs | 3 +-- .../Volo.Abp.AspNetCore.Mvc.Tests.csproj | 6 +---- .../Volo/Abp/AspNetCore/App/AppModule.cs | 25 +++++++++++++++++++ .../Abp/AspNetCore/App/SimpleController.cs | 13 ++++++++++ .../Volo/Abp/AspNetCore/App/Startup.cs | 20 +++++++++++++++ .../Mvc/AspNetCoreMultiTenancyTestBase.cs | 9 +++++++ .../AspNetCore/Mvc/SimpleController_Tests.cs | 20 +++++++++++++++ .../Volo.Abp.AspNetCore.Tests.csproj | 2 +- .../Volo/Abp/AspNetCore}/AppTestBase.cs | 3 ++- 13 files changed, 110 insertions(+), 17 deletions(-) create mode 100644 test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/MultiTenancy/AspNetCoreMultiTenancyTestBase.cs create mode 100644 test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/AppModule.cs create mode 100644 test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/SimpleController.cs create mode 100644 test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/Startup.cs create mode 100644 test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AspNetCoreMultiTenancyTestBase.cs create mode 100644 test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/SimpleController_Tests.cs rename test/{Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/App => Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore}/AppTestBase.cs (90%) diff --git a/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo.Abp.AspNetCore.MultiTenancy.Tests.csproj b/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo.Abp.AspNetCore.MultiTenancy.Tests.csproj index 3550f2047d..5340dc86c9 100644 --- a/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo.Abp.AspNetCore.MultiTenancy.Tests.csproj +++ b/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo.Abp.AspNetCore.MultiTenancy.Tests.csproj @@ -12,9 +12,8 @@ - - + diff --git a/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/App/AppModule.cs b/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/App/AppModule.cs index 5d47bc4d80..85b1c31efe 100644 --- a/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/App/AppModule.cs +++ b/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/App/AppModule.cs @@ -17,6 +17,14 @@ namespace Volo.Abp.AspNetCore.App )] public class AppModule : AbpModule { + public override void ConfigureServices(IServiceCollection services) + { + services.Configure(options => + { + options.AddDomainTenantResolver("{0}.abp.io"); + }); + } + public override void OnApplicationInitialization(ApplicationInitializationContext context) { var app = context.GetApplicationBuilder(); diff --git a/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/App/Startup.cs b/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/App/Startup.cs index 18e9dc26d7..1af71d75e8 100644 --- a/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/App/Startup.cs +++ b/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/App/Startup.cs @@ -2,7 +2,6 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using Volo.Abp.MultiTenancy; namespace Volo.Abp.AspNetCore.App { @@ -11,11 +10,6 @@ namespace Volo.Abp.AspNetCore.App public void ConfigureServices(IServiceCollection services) { services.AddApplication(); - - services.Configure(options => - { - options.AddDomainTenantResolver("{0}.abp.io"); - }); } public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) diff --git a/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/MultiTenancy/AspNetCoreMultiTenancyTestBase.cs b/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/MultiTenancy/AspNetCoreMultiTenancyTestBase.cs new file mode 100644 index 0000000000..9dc083b3f1 --- /dev/null +++ b/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/MultiTenancy/AspNetCoreMultiTenancyTestBase.cs @@ -0,0 +1,9 @@ +using Volo.Abp.AspNetCore.App; + +namespace Volo.Abp.AspNetCore.MultiTenancy +{ + public abstract class AspNetCoreMultiTenancyTestBase : AbpAspNetCoreTestBase + { + + } +} \ No newline at end of file diff --git a/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/MultiTenancy/AspNetCoreMultiTenancy_Tests.cs b/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/MultiTenancy/AspNetCoreMultiTenancy_Tests.cs index 6c617b9f66..953887fbf1 100644 --- a/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/MultiTenancy/AspNetCoreMultiTenancy_Tests.cs +++ b/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/MultiTenancy/AspNetCoreMultiTenancy_Tests.cs @@ -6,14 +6,13 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Microsoft.Net.Http.Headers; using Shouldly; -using Volo.Abp.AspNetCore.App; using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy.ConfigurationStore; using Xunit; namespace Volo.Abp.AspNetCore.MultiTenancy { - public class AspNetCoreMultiTenancy_Tests : AppTestBase + public class AspNetCoreMultiTenancy_Tests : AspNetCoreMultiTenancyTestBase { private readonly Guid _testTenantId = Guid.NewGuid(); private readonly string _testTenantName = "acme"; diff --git a/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo.Abp.AspNetCore.Mvc.Tests.csproj b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo.Abp.AspNetCore.Mvc.Tests.csproj index 7cc2dadedc..1be938a154 100644 --- a/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo.Abp.AspNetCore.Mvc.Tests.csproj +++ b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo.Abp.AspNetCore.Mvc.Tests.csproj @@ -16,12 +16,8 @@ - - - - - + diff --git a/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/AppModule.cs b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/AppModule.cs new file mode 100644 index 0000000000..e249dae4b2 --- /dev/null +++ b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/AppModule.cs @@ -0,0 +1,25 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.AspNetCore.Modularity; +using Volo.Abp.AspNetCore.TestBase; +using Volo.Abp.Modularity; + +namespace Volo.Abp.AspNetCore.App +{ + [DependsOn( + typeof(AbpAspNetCoreTestBaseModule) + )] + public class AppModule : AbpModule + { + public override void ConfigureServices(IServiceCollection services) + { + services.AddMvc(); + } + + public override void OnApplicationInitialization(ApplicationInitializationContext context) + { + var app = context.GetApplicationBuilder(); + app.UseMvcWithDefaultRoute(); + } + } +} diff --git a/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/SimpleController.cs b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/SimpleController.cs new file mode 100644 index 0000000000..a1250001ad --- /dev/null +++ b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/SimpleController.cs @@ -0,0 +1,13 @@ +using Microsoft.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Mvc; + +namespace Volo.Abp.AspNetCore.App +{ + public class SimpleController : AbpController + { + public ActionResult Index() + { + return Content("Index-Result"); + } + } +} diff --git a/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/Startup.cs b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/Startup.cs new file mode 100644 index 0000000000..1af71d75e8 --- /dev/null +++ b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/Startup.cs @@ -0,0 +1,20 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +namespace Volo.Abp.AspNetCore.App +{ + public class Startup + { + public void ConfigureServices(IServiceCollection services) + { + services.AddApplication(); + } + + public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) + { + app.InitializeApplication(); + } + } +} diff --git a/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AspNetCoreMultiTenancyTestBase.cs b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AspNetCoreMultiTenancyTestBase.cs new file mode 100644 index 0000000000..53b113b644 --- /dev/null +++ b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AspNetCoreMultiTenancyTestBase.cs @@ -0,0 +1,9 @@ +using Volo.Abp.AspNetCore.App; + +namespace Volo.Abp.AspNetCore.Mvc +{ + public abstract class AspNetCoreMvcTestBase : AbpAspNetCoreTestBase + { + + } +} \ No newline at end of file diff --git a/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/SimpleController_Tests.cs b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/SimpleController_Tests.cs new file mode 100644 index 0000000000..0847655db6 --- /dev/null +++ b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/SimpleController_Tests.cs @@ -0,0 +1,20 @@ +using System.Threading.Tasks; +using Shouldly; +using Volo.Abp.AspNetCore.App; +using Xunit; + +namespace Volo.Abp.AspNetCore.Mvc +{ + public class SimpleController_Tests : AspNetCoreMvcTestBase + { + [Fact] + public async Task ActionResult_Return_Type_ContentResult_Return_Value() + { + var result = await GetResponseAsStringAsync( + GetUrl(nameof(SimpleController.Index)) + ); + + result.ShouldBe("Index-Result"); + } + } +} diff --git a/test/Volo.Abp.AspNetCore.Tests/Volo.Abp.AspNetCore.Tests.csproj b/test/Volo.Abp.AspNetCore.Tests/Volo.Abp.AspNetCore.Tests.csproj index 0a49c65777..92b81ea2fd 100644 --- a/test/Volo.Abp.AspNetCore.Tests/Volo.Abp.AspNetCore.Tests.csproj +++ b/test/Volo.Abp.AspNetCore.Tests/Volo.Abp.AspNetCore.Tests.csproj @@ -16,8 +16,8 @@ + - diff --git a/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/App/AppTestBase.cs b/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/AppTestBase.cs similarity index 90% rename from test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/App/AppTestBase.cs rename to test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/AppTestBase.cs index 3f45334e3e..d13cb810bf 100644 --- a/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/App/AppTestBase.cs +++ b/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/AppTestBase.cs @@ -8,7 +8,8 @@ using Volo.Abp.AspNetCore.TestBase; namespace Volo.Abp.AspNetCore.App { - public abstract class AppTestBase : AbpAspNetCoreIntegratedTestBase + public abstract class AbpAspNetCoreTestBase : AbpAspNetCoreIntegratedTestBase + where TStartup : class { protected virtual async Task GetResponseAsObjectAsync(string url, HttpStatusCode expectedStatusCode = HttpStatusCode.OK) {