Skip to content

Commit f69c1cc

Browse files
committed
test: 更新单元测试
1 parent 62e8359 commit f69c1cc

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

test/UnitTest/Extensions/LambadaExtensionsTest.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
55

66
using System.ComponentModel.DataAnnotations;
7+
using System.Data;
78
using System.Dynamic;
89
using System.Linq.Expressions;
910

@@ -416,6 +417,62 @@ public void Sort_Queryable_Complex()
416417
Assert.Equal(10, orderFoos.ElementAt(0).Foo!.Count);
417418
}
418419

420+
[Fact]
421+
public void Sort_IDynamicObject_Ok()
422+
{
423+
var dataTable = new DataTable();
424+
425+
DataColumn column = new DataColumn
426+
{
427+
DataType = Type.GetType("System.Int32"),
428+
ColumnName = "ID"
429+
};
430+
dataTable.Columns.Add(column);
431+
432+
column = new DataColumn
433+
{
434+
DataType = Type.GetType("System.String"),
435+
ColumnName = "Name"
436+
};
437+
dataTable.Columns.Add(column);
438+
439+
//Creating some rows
440+
DataRow row = dataTable.NewRow();
441+
row["ID"] = 1;
442+
row["Name"] = "Bob";
443+
dataTable.Rows.Add(row);
444+
445+
row = dataTable.NewRow();
446+
row["ID"] = 3;
447+
row["Name"] = "Adam";
448+
dataTable.Rows.Add(row);
449+
450+
row = dataTable.NewRow();
451+
row["ID"] = 2;
452+
row["Name"] = "Jane";
453+
dataTable.Rows.Add(row);
454+
455+
var context = new DataTableDynamicContext(dataTable, (context, col) => { });
456+
var items = context.GetItems().ToList();
457+
458+
// 未排序
459+
Assert.Equal("Bob", items[0].GetValue("Name"));
460+
Assert.Equal("Adam", items[1].GetValue("Name"));
461+
Assert.Equal("Jane", items[2].GetValue("Name"));
462+
463+
// Name 排序
464+
var nameItems = items.Sort("Name", SortOrder.Asc).ToList();
465+
Assert.Equal("Adam", nameItems[0].GetValue("Name"));
466+
Assert.Equal("Bob", nameItems[1].GetValue("Name"));
467+
Assert.Equal("Jane", nameItems[2].GetValue("Name"));
468+
469+
// Name 倒序
470+
nameItems = items.Sort("Name", SortOrder.Desc).ToList();
471+
Assert.Equal("Adam", nameItems[2].GetValue("Name"));
472+
Assert.Equal("Bob", nameItems[1].GetValue("Name"));
473+
Assert.Equal("Jane", nameItems[0].GetValue("Name"));
474+
}
475+
419476
[Fact]
420477
public void GetPropertyValueLambda_Null()
421478
{

0 commit comments

Comments
 (0)