Skip to content

Commit f918b19

Browse files
committed
✅ test(Bing.Aop.AspectCore): 添加测试项目并调整引用
- 在解决方案中添加 Bing.Aop.AspectCore.Tests 测试项目 - 在 Bing.Aop.AspectCore 项目中添加对 Bing.Core 的直接引用 - 移除 references.props 文件,改用 ItemGroup 直接声明引用
1 parent 3262540 commit f918b19

File tree

10 files changed

+253
-8
lines changed

10 files changed

+253
-8
lines changed

Bing.All.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bing.AspNetCore.Abstraction
368368
EndProject
369369
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bing.Ddd.Domain.Extensions.Analyzers", "framework\src\Bing.Ddd.Domain.Extensions.Analyzers\Bing.Ddd.Domain.Extensions.Analyzers.csproj", "{BE5E6E82-3CB6-4C1B-8E2D-1B7A2483B41B}"
370370
EndProject
371+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bing.Aop.AspectCore.Tests", "framework\tests\Bing.Aop.AspectCore.Tests\Bing.Aop.AspectCore.Tests.csproj", "{F43AD659-D8F2-4B30-AB21-85CD376CAA20}"
372+
EndProject
371373
Global
372374
GlobalSection(SolutionConfigurationPlatforms) = preSolution
373375
Debug|Any CPU = Debug|Any CPU
@@ -834,6 +836,10 @@ Global
834836
{BE5E6E82-3CB6-4C1B-8E2D-1B7A2483B41B}.Debug|Any CPU.Build.0 = Debug|Any CPU
835837
{BE5E6E82-3CB6-4C1B-8E2D-1B7A2483B41B}.Release|Any CPU.ActiveCfg = Release|Any CPU
836838
{BE5E6E82-3CB6-4C1B-8E2D-1B7A2483B41B}.Release|Any CPU.Build.0 = Release|Any CPU
839+
{F43AD659-D8F2-4B30-AB21-85CD376CAA20}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
840+
{F43AD659-D8F2-4B30-AB21-85CD376CAA20}.Debug|Any CPU.Build.0 = Debug|Any CPU
841+
{F43AD659-D8F2-4B30-AB21-85CD376CAA20}.Release|Any CPU.ActiveCfg = Release|Any CPU
842+
{F43AD659-D8F2-4B30-AB21-85CD376CAA20}.Release|Any CPU.Build.0 = Release|Any CPU
837843
EndGlobalSection
838844
GlobalSection(SolutionProperties) = preSolution
839845
HideSolutionNode = FALSE
@@ -1001,6 +1007,7 @@ Global
10011007
{1538FB31-03B7-4D1F-9570-58909BDABE3C} = {3F07E19F-C285-47B5-9441-46F375ECD5C9}
10021008
{0359A38B-4080-41A1-BB75-6B2EA48D8E2D} = {C6B2743E-B7EE-418C-9F9B-79976B71C46B}
10031009
{BE5E6E82-3CB6-4C1B-8E2D-1B7A2483B41B} = {96F03C7E-0959-4BE4-BE87-E987E1C4BEDA}
1010+
{F43AD659-D8F2-4B30-AB21-85CD376CAA20} = {793DF696-AA3D-4D44-9657-B66000DCEFFA}
10041011
EndGlobalSection
10051012
GlobalSection(ExtensibilityGlobals) = postSolution
10061013
SolutionGuid = {C1202A0F-83CC-4602-BCE5-20CB640BCAD4}

framework/src/Bing.Aop.AspectCore/Bing.Aop.AspectCore.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
<Import Project="..\..\..\framework.props" />
99

10-
<Import Project="dependency.props" />
11-
12-
<Import Project="references.props" />
10+
<ItemGroup>
11+
<ProjectReference Include="..\Bing.Core\Bing.Core.csproj" />
12+
</ItemGroup>
1313

14+
<Import Project="dependency.props" />
1415
</Project>

framework/src/Bing.Aop.AspectCore/references.props

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<Import Project="..\..\..\framework.tests.props" />
3+
<ItemGroup>
4+
<ProjectReference Include="..\..\src\Bing.Aop.AspectCore\Bing.Aop.AspectCore.csproj" />
5+
</ItemGroup>
6+
7+
<PropertyGroup>
8+
<RootNamespace>Bing.Aop.AspectCore</RootNamespace>
9+
<XunitStartupFullName>Bing.Aop.AspectCore.Startup</XunitStartupFullName>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Xunit.DependencyInjection.Logging" Version="8.1.0" />
14+
<PackageReference Include="AspectCore.Extensions.Hosting" Version="2.4.0" />
15+
</ItemGroup>
16+
17+
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
18+
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.1.32" />
19+
<PackageReference Include="Xunit.DependencyInjection" Version="8.9.0" />
20+
</ItemGroup>
21+
22+
<ItemGroup Condition=" '$(TargetFramework)' == 'net5.0' ">
23+
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="5.0.17" />
24+
<PackageReference Include="Xunit.DependencyInjection" Version="8.9.0" />
25+
</ItemGroup>
26+
27+
<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
28+
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="6.0.14" />
29+
<PackageReference Include="Xunit.DependencyInjection" Version="8.9.0" />
30+
</ItemGroup>
31+
32+
<ItemGroup Condition=" '$(TargetFramework)' == 'net7.0' ">
33+
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="7.0.8" />
34+
<PackageReference Include="Xunit.DependencyInjection" Version="8.9.0" />
35+
</ItemGroup>
36+
37+
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
38+
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="8.0.14" />
39+
<PackageReference Include="Xunit.DependencyInjection" Version="9.9.0" />
40+
</ItemGroup>
41+
42+
<ItemGroup Condition=" '$(TargetFramework)' == 'net9.0' ">
43+
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="8.0.14" />
44+
<PackageReference Include="Xunit.DependencyInjection" Version="9.9.0" />
45+
</ItemGroup>
46+
47+
</Project>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using Bing.Aop.AspectCore.Samples;
2+
3+
namespace Bing.Aop.AspectCore;
4+
5+
/// <summary>
6+
/// 测试NotEmptyAttribute拦截器
7+
/// </summary>
8+
public class NotEmptyAttributeTest
9+
{
10+
/// <summary>
11+
/// 测试服务
12+
/// </summary>
13+
private readonly ITestService _service;
14+
15+
/// <summary>
16+
/// 测试初始化
17+
/// </summary>
18+
public NotEmptyAttributeTest(ITestService service)
19+
{
20+
_service = service;
21+
}
22+
23+
/// <summary>
24+
/// 测试 - 传入空字符串 - 抛出异常
25+
/// </summary>
26+
[Fact]
27+
public void NotEmpty_1()
28+
{
29+
Assert.Throws<ArgumentNullException>(() =>
30+
{
31+
_service.GetNotEmptyValue("");
32+
});
33+
}
34+
35+
/// <summary>
36+
/// 测试 - 传入字符串 - 返回字符串
37+
/// </summary>
38+
[Fact]
39+
public void NotEmpty_2()
40+
{
41+
Assert.Equal("a", _service.GetNotEmptyValue("a"));
42+
}
43+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using Bing.Aop.AspectCore.Samples;
2+
3+
namespace Bing.Aop.AspectCore;
4+
5+
/// <summary>
6+
/// 测试NotNullAttribute拦截器
7+
/// </summary>
8+
public class NotNullAttributeTest
9+
{
10+
/// <summary>
11+
/// 测试服务
12+
/// </summary>
13+
private readonly ITestService _service;
14+
15+
/// <summary>
16+
/// 测试初始化
17+
/// </summary>
18+
public NotNullAttributeTest(ITestService service)
19+
{
20+
_service = service;
21+
}
22+
23+
/// <summary>
24+
/// 测试 - 传入null - 抛出异常
25+
/// </summary>
26+
[Fact]
27+
public void NotNull_1()
28+
{
29+
Assert.Throws<ArgumentNullException>(() =>
30+
{
31+
_service.GetNotNullValue(null);
32+
});
33+
}
34+
35+
/// <summary>
36+
/// 测试 - 传入空字符串 - 返回空字符串
37+
/// </summary>
38+
[Fact]
39+
public void NotNull_2()
40+
{
41+
Assert.Equal("", _service.GetNotNullValue(""));
42+
}
43+
44+
/// <summary>
45+
/// 测试 - 传入字符串 - 返回字符串
46+
/// </summary>
47+
[Fact]
48+
public void NotNull_3()
49+
{
50+
Assert.Equal("a", _service.GetNotNullValue("a"));
51+
}
52+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Bing.Aspects;
2+
using Bing.DependencyInjection;
3+
4+
namespace Bing.Aop.AspectCore.Samples;
5+
6+
/// <summary>
7+
/// 测试服务
8+
/// </summary>
9+
public interface ITestService : ISingletonDependency
10+
{
11+
/// <summary>
12+
/// 获取值,值不能为空
13+
/// </summary>
14+
/// <param name="value">参数</param>
15+
string GetNotEmptyValue([NotEmpty] string value);
16+
17+
/// <summary>
18+
/// 获取值,值不能为null
19+
/// </summary>
20+
/// <param name="value">参数</param>
21+
string GetNotNullValue([NotNull] string value);
22+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Bing.Aspects;
2+
3+
namespace Bing.Aop.AspectCore.Samples;
4+
5+
/// <summary>
6+
/// 测试服务
7+
/// </summary>
8+
public class TestService : ITestService
9+
{
10+
/// <summary>
11+
/// 获取值,值不能为空
12+
/// </summary>
13+
/// <param name="value">参数</param>
14+
public string GetNotEmptyValue(string value) => value;
15+
16+
/// <summary>
17+
/// 获取值,值不能为null
18+
/// </summary>
19+
/// <param name="value">参数</param>
20+
public string GetNotNullValue([NotNull] string value) => value;
21+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using AspectCore.DynamicProxy.Parameters;
2+
using AspectCore.Extensions.Hosting;
3+
using Bing.DependencyInjection;
4+
using Microsoft.Extensions.DependencyInjection;
5+
using Microsoft.Extensions.Hosting;
6+
using Xunit.DependencyInjection.Logging;
7+
8+
namespace Bing.Aop.AspectCore;
9+
10+
/// <summary>
11+
/// 启动配置
12+
/// </summary>
13+
public class Startup
14+
{
15+
/// <summary>
16+
/// 配置主机
17+
/// </summary>
18+
public void ConfigureHost(IHostBuilder hostBuilder)
19+
{
20+
hostBuilder.ConfigureDefaults(null)
21+
.UseServiceContext();
22+
}
23+
24+
/// <summary>
25+
/// 配置服务
26+
/// </summary>
27+
public void ConfigureServices(IServiceCollection services, HostBuilderContext context)
28+
{
29+
// 日志
30+
services.AddLogging(logBuilder => logBuilder.AddXunitOutput());
31+
services.EnableAop(o =>
32+
{
33+
// 启用参数拦截,才会对参数进行验证
34+
o.EnableParameterAspect();
35+
});
36+
services.AddBing();
37+
}
38+
39+
/// <summary>
40+
/// 配置日志提供程序
41+
/// </summary>
42+
public void Configure()
43+
{
44+
45+
}
46+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
global using System.Collections.Generic;
2+
global using System.Collections;
3+
global using System.IO;
4+
global using System.Linq;
5+
global using System.Reflection;
6+
global using System.Text;
7+
global using System.Threading.Tasks;
8+
global using System.Threading;
9+
global using System;
10+
global using Xunit;
11+
global using Shouldly;

0 commit comments

Comments
 (0)