Skip to content

Commit fac2a48

Browse files
committed
!3789 test(#I6B6FF): add unit test for ModelEqualityComparer
* Merge branch 'main' into test-treeview * test: add Equals method unit test * refactor: rename IModelEqualityComparer extension * refactor: use IModelEqualityComparer interface for code reuse * fix: update code for Equals parameter * test: update code remove warning message * refactor: add nullable constraint * refactor: remove suggesion * refactor: add IModelEqualityComparer interface * refactor: change _itemCache to ItemCache * test: update GetKeyValue unit test * refactor: update Equlas check logic make it faster * refactor: update ModelComparer make it simple * test: add ExpandIcon unit test
1 parent 1b37405 commit fac2a48

4 files changed

Lines changed: 36 additions & 4 deletions

File tree

test/UnitTest/Components/TableTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4550,7 +4550,7 @@ public async Task DynamicContext_EqualityComparer()
45504550
context.EqualityComparer = (x, y) =>
45514551
{
45524552
comparered = true;
4553-
return x.GetValue("Id") == y.GetValue("Id");
4553+
return x!.GetValue("Id") == y!.GetValue("Id");
45544554
};
45554555
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>
45564556
{

test/UnitTest/Components/TreeViewTest.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,20 @@ public async Task IsReset_Ok()
377377
Assert.Equal(2, nodes.Count);
378378
}
379379

380+
[Fact]
381+
public void ExpandIcon_Ok()
382+
{
383+
var items = TreeFoo.GetTreeItems();
384+
items[1].ExpandIcon = "test-expand-icon";
385+
items[1].IsExpand = true;
386+
var cut = Context.RenderComponent<TreeView<TreeFoo>>(pb =>
387+
{
388+
pb.Add(a => a.ShowIcon, true);
389+
pb.Add(a => a.Items, items);
390+
});
391+
cut.Contains("test-expand-icon");
392+
}
393+
380394
[Fact]
381395
public void ModelEqualityComparer_Ok()
382396
{
@@ -505,12 +519,12 @@ public async Task ClearCheckedItems_Ok()
505519
await cut.InvokeAsync(() => checkbox[0].Click());
506520

507521
Assert.Contains("is-checked", cut.Markup);
508-
var ischecked = cut.Instance.GetCheckedItems().Count() != 0;
522+
var ischecked = cut.Instance.GetCheckedItems().Any();
509523
Assert.True(ischecked);
510524

511525
await cut.InvokeAsync(() => cut.Instance.ClearCheckedItems());
512526
Assert.DoesNotContain("is-checked", cut.Markup);
513-
var nochecked = cut.Instance.GetCheckedItems().Count() == 0;
527+
var nochecked = !cut.Instance.GetCheckedItems().Any();
514528
Assert.True(nochecked);
515529
}
516530

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
// Website: https://www.blazor.zone or https://argozhang.github.io/
4+
5+
using BootstrapBlazor.Shared;
6+
7+
namespace UnitTest.Misc;
8+
9+
public class ModelEqualityComparerTest
10+
{
11+
[Fact]
12+
public void Equals_Ok()
13+
{
14+
Assert.True(IModelEqualityComparerExtensions.Equals<Foo>(null!, null, null));
15+
Assert.False(IModelEqualityComparerExtensions.Equals<Foo>(null!, null, new Foo()));
16+
Assert.False(IModelEqualityComparerExtensions.Equals<Foo>(null!, new Foo(), null));
17+
}
18+
}

test/UnitTest/Utils/UtilityTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void GetKeyValue_CustomKeyAttribute()
3737
public void GetKeyValue_Null()
3838
{
3939
Foo? foo = null;
40-
Assert.Throws<ArgumentNullException>(() => Utility.GetKeyValue<object?, int>(foo));
40+
Assert.Equal(0, Utility.GetKeyValue<object?, int>(foo));
4141
}
4242

4343
[Fact]

0 commit comments

Comments
 (0)