Skip to content

Commit ab87080

Browse files
committed
test: 增加单元测试
1 parent 956ddb1 commit ab87080

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

test/UnitTest/Components/TableTest.cs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.ComponentModel.DataAnnotations;
1212
using System.Data;
1313
using System.Reflection;
14+
using System.Runtime.CompilerServices;
1415

1516
namespace UnitTest.Components;
1617

@@ -8635,6 +8636,65 @@ await Assert.ThrowsAsync<InvalidOperationException>(() =>
86358636
});
86368637
}
86378638

8639+
[Fact]
8640+
public void Modify_Ok()
8641+
{
8642+
var cut = Context.RenderComponent<Table<Foo>>(pb =>
8643+
{
8644+
pb.Add(a => a.TableColumns, foo => builder =>
8645+
{
8646+
builder.OpenComponent<TableColumn<Foo, string>>(0);
8647+
builder.AddAttribute(1, "Field", "Name");
8648+
builder.AddAttribute(2, "FieldExpression", Utility.GenerateValueExpression(foo, "Name", typeof(string)));
8649+
builder.CloseComponent();
8650+
});
8651+
pb.Add(a => a.ShowExtendEditButton, false);
8652+
pb.Add(a => a.ShowExtendDeleteButton, false);
8653+
});
8654+
Assert.True(CanEdit(cut.Instance));
8655+
Assert.True(CanDelete(cut.Instance));
8656+
8657+
cut.SetParametersAndRender(pb =>
8658+
{
8659+
pb.Add(a => a.ShowExtendEditButton, true);
8660+
pb.Add(a => a.ShowExtendDeleteButton, true);
8661+
pb.Add(a => a.DisableExtendEditButton, true);
8662+
pb.Add(a => a.DisableExtendDeleteButton, true);
8663+
});
8664+
Assert.True(CanEdit(cut.Instance));
8665+
Assert.True(CanDelete(cut.Instance));
8666+
}
8667+
8668+
static bool CanEdit(Table<Foo> @this)
8669+
{
8670+
var ret = false;
8671+
var methodInfo = @this.GetType().GetMethod("CanEdit", BindingFlags.Instance | BindingFlags.NonPublic);
8672+
if (methodInfo != null)
8673+
{
8674+
var result = methodInfo.Invoke(@this, null);
8675+
if (result is bool d)
8676+
{
8677+
ret = d;
8678+
}
8679+
}
8680+
return ret;
8681+
}
8682+
8683+
static bool CanDelete(Table<Foo> @this)
8684+
{
8685+
var ret = false;
8686+
var methodInfo = @this.GetType().GetMethod("CanDelete", BindingFlags.Instance | BindingFlags.NonPublic);
8687+
if (methodInfo != null)
8688+
{
8689+
var result = methodInfo.Invoke(@this, null);
8690+
if (result is bool d)
8691+
{
8692+
ret = d;
8693+
}
8694+
}
8695+
return ret;
8696+
}
8697+
86388698
class MockFoo(string name)
86398699
{
86408700
public string Name { get; set; } = name;

0 commit comments

Comments
 (0)