Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(TestBase): redesign test context base #4144

Merged
merged 24 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8426094
test: 移除 DrawerTestBase 基类
ArgoZhang Aug 25, 2024
d5e93ec
test: 移除 DialogTestBase 基类
ArgoZhang Aug 25, 2024
86abfe9
test: 重构 AuthorizationViewTestBase 单元测试
ArgoZhang Aug 25, 2024
14140a9
test: 更新继承关系精简代码
ArgoZhang Aug 25, 2024
bd6d081
test: 移除 EditorForm 测试基类
ArgoZhang Aug 25, 2024
bc1dfea
test: 更新 EFCore 测试基类
ArgoZhang Aug 25, 2024
e3ecd59
test: 重构 PdfTest 测试基类
ArgoZhang Aug 25, 2024
725fdbb
test: 移除 ErrorLogger 测试基类
ArgoZhang Aug 25, 2024
d8dfce2
test: 移除 MessageTest 基类
ArgoZhang Aug 25, 2024
5c02f15
test: 移除 SwalTestBase
ArgoZhang Aug 25, 2024
bde2d72
test: 移除 RobbinTabTestBase
ArgoZhang Aug 25, 2024
2f88c81
test: 移除 PopoverTestBase
ArgoZhang Aug 25, 2024
3c25422
test: 重构 TableDialogTestBase
ArgoZhang Aug 25, 2024
642124c
test: 移除 TableDrawerTestBase
ArgoZhang Aug 25, 2024
0a7bade
test: 移除 TablePopConfirmTestBase
ArgoZhang Aug 25, 2024
4275949
test: 重构 ValidateFormTestBase
ArgoZhang Aug 25, 2024
5fbc637
test: 重构 TabTestBase
ArgoZhang Aug 25, 2024
9d4f11b
test: 移除 TableTestBase
ArgoZhang Aug 25, 2024
081b614
test: 移除 TableSortDialogTestBase
ArgoZhang Aug 25, 2024
a25028e
test: 修复单元测试
ArgoZhang Aug 25, 2024
82c83b3
test: 移除 CollectionOrderer 规则
ArgoZhang Aug 25, 2024
f510ca1
test: 重构 SpeechTestBase
ArgoZhang Aug 25, 2024
26dbde7
test: 增加代码覆盖率排除规则
ArgoZhang Aug 25, 2024
a05f0de
chore: bump version 8.8.4
ArgoZhang Aug 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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