Skip to content

Commit 250ace0

Browse files
committed
refactor: 增加 SearchFilterAction 单元测试
1 parent 427a9ab commit 250ace0

3 files changed

Lines changed: 45 additions & 6 deletions

File tree

src/BootstrapBlazor/Components/Filters/IFilterAction.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ namespace BootstrapBlazor.Components;
1414
public interface IFilterAction
1515
{
1616
/// <summary>
17-
/// 获得 IFilter 实例中的过滤条件集合
17+
/// 重置过滤条件方法
1818
/// </summary>
19-
/// <returns></returns>
20-
FilterKeyValueAction GetFilterConditions();
19+
void Reset();
2120

2221
/// <summary>
23-
/// 重置过滤条件方法
22+
/// 获得 IFilter 实例中的过滤条件集合
2423
/// </summary>
25-
void Reset();
24+
/// <returns></returns>
25+
FilterKeyValueAction GetFilterConditions();
2626

2727
/// <summary>
2828
/// Override existing filter conditions

src/BootstrapBlazor/Components/Filters/SearchFilterAction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void Reset()
4343
/// <returns></returns>
4444
public Task SetFilterConditionsAsync(FilterKeyValueAction filter)
4545
{
46-
var first = filter.Filters?.FirstOrDefault() ?? filter;
46+
var first = filter.Filters.FirstOrDefault() ?? filter;
4747
if (first.FieldKey == Name)
4848
{
4949
Value = first.FieldValue;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the Apache 2.0 License
3+
// See the LICENSE file in the project root for more information.
4+
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
5+
6+
namespace UnitTest.Components;
7+
8+
public class SearchFilterActionTest
9+
{
10+
[Fact]
11+
public async Task SearchFilterAction_Ok()
12+
{
13+
var filter = new SearchFilterAction("Name", "Argo");
14+
Assert.Equal("Argo", filter.Value);
15+
16+
filter.Reset();
17+
Assert.Null(filter.Value);
18+
19+
await filter.SetFilterConditionsAsync(new FilterKeyValueAction
20+
{
21+
FieldKey = "Name",
22+
FieldValue = "Argo Zhang"
23+
});
24+
Assert.Equal("Argo Zhang", filter.Value);
25+
26+
await filter.SetFilterConditionsAsync(new FilterKeyValueAction
27+
{
28+
Filters =
29+
[
30+
new FilterKeyValueAction
31+
{
32+
FieldKey = "Name",
33+
FieldValue = "Argo"
34+
}
35+
]
36+
});
37+
Assert.Equal("Argo", filter.Value);
38+
}
39+
}

0 commit comments

Comments
 (0)