From 1325367e18ccd004cd9a6baad335fac02ed94307 Mon Sep 17 00:00:00 2001 From: Aaron Chong Date: Thu, 18 Feb 2021 22:16:38 +0800 Subject: [PATCH] Add tests for AbpServiceConvention new behaviour --- .../Conventions/AbpServiceConvention_Tests.cs | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Conventions/AbpServiceConvention_Tests.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Conventions/AbpServiceConvention_Tests.cs index f16e8a1df9..ae10a00654 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Conventions/AbpServiceConvention_Tests.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Conventions/AbpServiceConvention_Tests.cs @@ -48,6 +48,53 @@ namespace Volo.Abp.AspNetCore.Mvc.Conventions applicationModel.Controllers.ShouldContain(derivedControllerModel); } + [Fact] + public void Should_Remove_Exposed_Controller_If_Expose_Self() + { + // Arrange + var applicationModel = new ApplicationModel(); + var baseControllerModel = new ControllerModel(typeof(BaseController).GetTypeInfo(), Array.Empty()) + { + Application = applicationModel + }; + applicationModel.Controllers.Add(baseControllerModel); + + var derivedControllerModel = new ControllerModel(typeof(ExposeServiceIncludeSelfDerivedController).GetTypeInfo(), Array.Empty()) + { + Application = applicationModel + }; + applicationModel.Controllers.Add(derivedControllerModel); + + var abpServiceConvention = new AbpServiceConvention(_options, _conventionalRouteBuilder); + + // Act + abpServiceConvention.Apply(applicationModel); + + // Assert + applicationModel.Controllers.ShouldNotContain(baseControllerModel); + applicationModel.Controllers.ShouldContain(derivedControllerModel); + } + + [Fact] + public void Should_Not_Remove_Derived_Controller_If_No_Base_Controller_Model() + { + // Arrange + var applicationModel = new ApplicationModel(); + var derivedControllerModel = new ControllerModel(typeof(ExposeServiceDerivedController).GetTypeInfo(), Array.Empty()) + { + Application = applicationModel + }; + applicationModel.Controllers.Add(derivedControllerModel); + + var abpServiceConvention = new AbpServiceConvention(_options, _conventionalRouteBuilder); + + // Act + abpServiceConvention.Apply(applicationModel); + + // Assert + applicationModel.Controllers.ShouldContain(derivedControllerModel); + } + [Fact] public void Should_Remove_Derived_Controller_If_Expose_Service() { @@ -88,4 +135,9 @@ namespace Volo.Abp.AspNetCore.Mvc.Conventions public class ExposeServiceDerivedController : BaseController { } + + [ExposeServices(typeof(BaseController), IncludeSelf = true)] + public class ExposeServiceIncludeSelfDerivedController : BaseController + { + } }