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 + { + } }