Skip to content

Commit 2412354

Browse files
committed
test: 增加单元测试
1 parent d97e6a4 commit 2412354

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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([email protected]) Website: https://www.blazor.zone
5+
6+
using System.Data;
7+
8+
namespace UnitTest.Components;
9+
10+
public class DataTableDynamicContextTest : BootstrapBlazorTestBase
11+
{
12+
[Fact]
13+
public void UseCache_Ok()
14+
{
15+
var table = new DataTable();
16+
table.Columns.Add("Id", typeof(int));
17+
table.Rows.Add(1);
18+
table.AcceptChanges();
19+
20+
var context = new DataTableDynamicContext(table);
21+
Assert.True(context.UseCache);
22+
23+
var data = context.GetItems();
24+
Assert.Single(data);
25+
Assert.Equal(1, data.First().GetValue("Id"));
26+
27+
// 增加数据
28+
table.Rows.Add(2);
29+
var data2 = context.GetItems();
30+
Assert.Equal(data, data2);
31+
32+
// 关闭缓存
33+
context.UseCache = false;
34+
table.Rows.Add(3);
35+
data2 = context.GetItems();
36+
Assert.Equal(3, data2.Count());
37+
}
38+
}

0 commit comments

Comments
 (0)