Browse Source

Add tests for AbpServiceConvention new behaviour

pull/7766/head
Aaron Chong 6 years ago
parent
commit
1325367e18
  1. 52
      framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Conventions/AbpServiceConvention_Tests.cs

52
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<object>())
{
Application = applicationModel
};
applicationModel.Controllers.Add(baseControllerModel);
var derivedControllerModel = new ControllerModel(typeof(ExposeServiceIncludeSelfDerivedController).GetTypeInfo(), Array.Empty<object>())
{
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<object>())
{
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
{
}
}

Loading…
Cancel
Save