Skip to content

Commit 52058b6

Browse files
authored
test(TestBase): move IDispose interface to TestBase (#7134)
* test: 移动接口到基类 * test: 消除警告信息
1 parent f95a860 commit 52058b6

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

test/UnitTest/Core/BootstrapBlazorTestBase.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace UnitTest.Core;
99

10-
public class BootstrapBlazorTestBase : TestBase, IDisposable
10+
public class BootstrapBlazorTestBase : TestBase
1111
{
1212
protected ICacheManager Cache { get; }
1313

@@ -38,12 +38,6 @@ protected virtual void ConfigureConfiguration(IServiceCollection services)
3838
services.AddConfiguration();
3939
}
4040

41-
public void Dispose()
42-
{
43-
_ = Context.DisposeAsync();
44-
GC.SuppressFinalize(this);
45-
}
46-
4741
class FooLookupService : LookupServiceBase
4842
{
4943
public override IEnumerable<SelectedItem>? GetItemsByKey(string? key, object? data)

test/UnitTest/Core/TestBase.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace UnitTest.Core;
77

8-
public class TestBase
8+
public class TestBase : IDisposable
99
{
1010
protected BunitContext Context { get; }
1111

@@ -16,4 +16,13 @@ public TestBase()
1616

1717
Context.Services.AddMockEnvironment();
1818
}
19+
20+
public void Dispose()
21+
{
22+
#pragma warning disable CA2012
23+
// 由于 bUnit 2.0 继承了 IAsyncDisposable 接口,因此此处调用 DisposeAsync 方法
24+
Context.DisposeAsync();
25+
#pragma warning restore CA2012
26+
GC.SuppressFinalize(this);
27+
}
1928
}

0 commit comments

Comments
 (0)