Skip to content

Commit

Permalink
test(TestBase): redesign test context base (#4144)
Browse files Browse the repository at this point in the history
* test: 移除 DrawerTestBase 基类

* test: 移除 DialogTestBase 基类

* test: 重构 AuthorizationViewTestBase 单元测试

* test: 更新继承关系精简代码

* test: 移除 EditorForm 测试基类

* test: 更新 EFCore 测试基类

* test: 重构 PdfTest 测试基类

* test: 移除 ErrorLogger 测试基类

* test: 移除 MessageTest 基类

* test: 移除 SwalTestBase

* test: 移除 RobbinTabTestBase

* test: 移除 PopoverTestBase

* test: 重构 TableDialogTestBase

* test: 移除 TableDrawerTestBase

* test: 移除 TablePopConfirmTestBase

* test: 重构 ValidateFormTestBase

* test: 重构 TabTestBase

* test: 移除 TableTestBase

* test: 移除 TableSortDialogTestBase

* test: 修复单元测试

* test: 移除 CollectionOrderer 规则

* test: 重构 SpeechTestBase

* test: 增加代码覆盖率排除规则

* chore: bump version 8.8.4
  • Loading branch information
ArgoZhang authored Aug 25, 2024
1 parent 0cc6eb5 commit 14161aa
Show file tree
Hide file tree
Showing 48 changed files with 57 additions and 1,274 deletions.
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>8.8.4-beta07</Version>
<Version>8.8.4</Version>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
Expand Down
11 changes: 0 additions & 11 deletions test/UnitTest.Localization/CollectionOrder/DisplayNameOrder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,3 @@
// Website: https://www.blazor.zone or https://argozhang.github.io/

[assembly: CollectionBehavior(DisableTestParallelization = true)]
[assembly: TestCollectionOrderer("UnitTest.CollectionOrder.DisplayNameOrderer", "UnitTest")]

namespace UnitTest.CollectionOrder;

public class DisplayNameOrderer : ITestCollectionOrderer
{
public IEnumerable<ITestCollection> OrderTestCollections(IEnumerable<ITestCollection> testCollections)
{
return testCollections.OrderBy(collection => collection.DisplayName);
}
}
1 change: 1 addition & 0 deletions test/UnitTest.Localization/LocalizerEnTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public void Foo_Json_Ok()
[Fact]
public void Dummy_Resource_Ok()
{
Context.Services.GetRequiredService<IStringLocalizer<Foo>>();
Assert.Equal("en-US", CultureInfo.CurrentUICulture.Name);

var val = Utility.GetDisplayName(typeof(DummyEn), nameof(DummyEn.Name));
Expand Down
1 change: 1 addition & 0 deletions test/UnitTest.Localization/LocalizerZhTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public void Foo_Json_Ok()
[Fact]
public void Dummy_Resource_Ok()
{
Context.Services.GetRequiredService<IStringLocalizer<Foo>>();
Assert.Equal("zh-CN", CultureInfo.CurrentUICulture.Name);

var val = Utility.GetDisplayName(typeof(Dummy), nameof(Dummy.Name));
Expand Down
2 changes: 1 addition & 1 deletion test/UnitTest/Components/AuthorizeViewTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace UnitTest.Components;

public class AuthorizeViewTest : AuthorizateViewTestBase
public class AuthorizeViewTest : AuthorizationViewTestBase
{
[Fact]
public void NotAuthorized_Ok()
Expand Down
6 changes: 3 additions & 3 deletions test/UnitTest/Components/BlockTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public void Authorized_Ok()
var cut = Context.RenderComponent<Block>(builder =>
{
builder.Add(a => a.Condition, true);
builder.Add(a => a.Authorized, b => b.AddContent(0, "Authorizated"));
builder.Add(a => a.Authorized, b => b.AddContent(0, "Authorized"));
});
Assert.Equal("Authorizated", cut.Markup);
Assert.Equal("Authorized", cut.Markup);
}

[Fact]
Expand Down Expand Up @@ -59,7 +59,7 @@ internal static RenderFragment BuildComponent() => builder =>
};
}

public class BlockAuthorizationTest : AuthorizationTestBase
public class BlockAuthorizationTest : AuthorizationViewTestBase
{
[Fact]
public void User_Ok()
Expand Down
2 changes: 1 addition & 1 deletion test/UnitTest/Components/DialogTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace UnitTest.Components;

public class DialogTest : DialogTestBase
public class DialogTest : BootstrapBlazorTestBase
{
[Fact]
public async Task Show_Ok()
Expand Down
2 changes: 1 addition & 1 deletion test/UnitTest/Components/EditorFormTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace UnitTest.Components;

public class EditorFormTest : BootstrapEditorFormTestBase
public class EditorFormTest : BootstrapBlazorTestBase
{
[Fact]
public void CascadedEditContext_Error()
Expand Down
2 changes: 1 addition & 1 deletion test/UnitTest/Components/ErrorHandlerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace UnitTest.Components;

public class ErrorHandlerTest : ErrorLoggerTestBase
public class ErrorHandlerTest : BootstrapBlazorTestBase
{
[Fact]
public async Task HandlerException_Ok()
Expand Down
2 changes: 1 addition & 1 deletion test/UnitTest/Components/LayoutTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ public void CollapseBarTemplate_Ok()
private static RenderFragment CreateSide(string? content = "Side") => builder => builder.AddContent(0, content);
}

public class LayoutAuthorizationTest : AuthorizateViewTestBase
public class LayoutAuthorizationTest : AuthorizationViewTestBase
{
[Fact]
public void Authorized_Ok()
Expand Down
3 changes: 0 additions & 3 deletions test/UnitTest/Components/MenuTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -485,10 +485,7 @@ public void MenuItem_Parent()
Assert.True(item.IsActive);
Assert.True(parent.IsActive);
}
}

public class MenuItemTest_Ok : DialogTestBase
{
[Fact]
public void ActiveItem_Ok()
{
Expand Down
2 changes: 1 addition & 1 deletion test/UnitTest/Components/MessageTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace UnitTest.Components;

public class MessageTest : MessageTestBase
public class MessageTest : BootstrapBlazorTestBase
{
[Fact]
public async Task Message_Ok()
Expand Down
2 changes: 1 addition & 1 deletion test/UnitTest/Components/PopConfirmButtonTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace UnitTest.Components;

public class PopConfirmButtonTest : PopoverTestBase
public class PopConfirmButtonTest : BootstrapBlazorTestBase
{
[Fact]
public async Task Show_Ok()
Expand Down
1 change: 0 additions & 1 deletion test/UnitTest/Components/RecognizerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace UnitTest.Components;


public class RecognizerTest : SpeechTestBase
{
[Fact]
Expand Down
2 changes: 1 addition & 1 deletion test/UnitTest/Components/RibbonTabAnchorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace UnitTest.Components;
/// <summary>
///
/// </summary>
public class RibbonTabAnchorTest : RibbonTabTestBase
public class RibbonTabAnchorTest : BootstrapBlazorTestBase
{
[Fact]
public void IsSupportAnchor_Ok()
Expand Down
2 changes: 1 addition & 1 deletion test/UnitTest/Components/SwalTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace UnitTest.Components;

public class SwalTest : SwalTestBase
public class SwalTest : BootstrapBlazorTestBase
{
[Fact]
public void Show_Ok()
Expand Down
2 changes: 1 addition & 1 deletion test/UnitTest/Components/TableConfirmTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace UnitTest.Components;

public class TableConfirmTest : TableConfirmTestBase
public class TableConfirmTest : BootstrapBlazorTestBase
{
[Fact]
public void TableCellPopConfirmButton_Ok()
Expand Down
2 changes: 1 addition & 1 deletion test/UnitTest/Components/TableDrawerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace UnitTest.Components;

public class TableDrawerTest : TableDrawerTestBase
public class TableDrawerTest : TableDialogTestBase
{
[Fact]
public async Task EditAsync_Ok()
Expand Down
2 changes: 1 addition & 1 deletion test/UnitTest/Components/TableSortDialogTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace UnitTest.Components;

public class TableSortDialogTest : TableSortDialogTestBase
public class TableSortDialogTest : BootstrapBlazorTestBase
{
[Fact]
public void AdvancedSort_Ok()
Expand Down
2 changes: 1 addition & 1 deletion test/UnitTest/Components/TableTemplateColumnTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace UnitTest.Components;

public class TableTemplateColumnTest : TableTestBase
public class TableTemplateColumnTest : BootstrapBlazorTestBase
{
[Theory]
[InlineData(TableRenderMode.CardView)]
Expand Down
2 changes: 1 addition & 1 deletion test/UnitTest/Components/TableTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace UnitTest.Components;

public class TableTest : TableTestBase
public class TableTest : BootstrapBlazorTestBase
{
[Fact]
public void Items_Ok()
Expand Down
58 changes: 0 additions & 58 deletions test/UnitTest/Core/AuthorizateViewTestBase.cs

This file was deleted.

49 changes: 0 additions & 49 deletions test/UnitTest/Core/AuthorizationTestBase.cs

This file was deleted.

20 changes: 20 additions & 0 deletions test/UnitTest/Core/AuthorizationViewTestBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) Argo Zhang ([email protected]). All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Website: https://www.blazor.zone or https://argozhang.github.io/

using Bunit.TestDoubles;

namespace UnitTest.Core;

public class AuthorizationViewTestBase : BootstrapBlazorTestBase
{
[NotNull]
protected TestAuthorizationContext? AuthorizationContext { get; private set; }

protected override void ConfigureServices(IServiceCollection services)
{
base.ConfigureServices(services);

AuthorizationContext = Context.AddTestAuthorization();
}
}
10 changes: 2 additions & 8 deletions test/UnitTest/Core/BootstrapBlazorTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,12 @@

namespace UnitTest.Core;

public class BootstrapBlazorTestBase : IDisposable
public class BootstrapBlazorTestBase : TestBase, IDisposable
{
protected TestContext Context { get; }

protected ICacheManager Cache { get; }

public BootstrapBlazorTestBase()
public BootstrapBlazorTestBase() : base()
{
Context = new TestContext();
// Mock 脚本
Context.JSInterop.Mode = JSRuntimeMode.Loose;

ConfigureServices(Context.Services);

ConfigureConfiguration(Context.Services);
Expand Down
Loading

0 comments on commit 14161aa

Please sign in to comment.