|
11 | 11 | using System.ComponentModel.DataAnnotations; |
12 | 12 | using System.Data; |
13 | 13 | using System.Reflection; |
| 14 | +using System.Runtime.CompilerServices; |
14 | 15 |
|
15 | 16 | namespace UnitTest.Components; |
16 | 17 |
|
@@ -8635,6 +8636,84 @@ await Assert.ThrowsAsync<InvalidOperationException>(() => |
8635 | 8636 | }); |
8636 | 8637 | } |
8637 | 8638 |
|
| 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 | + cut.SetParametersAndRender(pb => |
| 8668 | + { |
| 8669 | + pb.Add(a => a.ShowExtendEditButton, true); |
| 8670 | + pb.Add(a => a.ShowExtendDeleteButton, true); |
| 8671 | + pb.Add(a => a.DisableExtendEditButton, false); |
| 8672 | + pb.Add(a => a.DisableExtendDeleteButton, false); |
| 8673 | + pb.Add(a => a.SelectedRows, [new Foo()]); |
| 8674 | + pb.Add(a => a.DisableExtendEditButtonCallback, rows => |
| 8675 | + { |
| 8676 | + return true; |
| 8677 | + }); |
| 8678 | + pb.Add(a => a.DisableExtendDeleteButtonCallback, rows => |
| 8679 | + { |
| 8680 | + return true; |
| 8681 | + }); |
| 8682 | + }); |
| 8683 | + Assert.True(CanEdit(cut.Instance)); |
| 8684 | + Assert.True(CanDelete(cut.Instance)); |
| 8685 | + } |
| 8686 | + |
| 8687 | + static bool CanEdit(Table<Foo> @this) |
| 8688 | + { |
| 8689 | + var ret = false; |
| 8690 | + var methodInfo = @this.GetType().GetMethod("CanEdit", BindingFlags.Instance | BindingFlags.NonPublic); |
| 8691 | + if (methodInfo != null) |
| 8692 | + { |
| 8693 | + var result = methodInfo.Invoke(@this, null); |
| 8694 | + if (result is bool d) |
| 8695 | + { |
| 8696 | + ret = d; |
| 8697 | + } |
| 8698 | + } |
| 8699 | + return ret; |
| 8700 | + } |
| 8701 | + |
| 8702 | + static bool CanDelete(Table<Foo> @this) |
| 8703 | + { |
| 8704 | + var ret = false; |
| 8705 | + var methodInfo = @this.GetType().GetMethod("CanDelete", BindingFlags.Instance | BindingFlags.NonPublic); |
| 8706 | + if (methodInfo != null) |
| 8707 | + { |
| 8708 | + var result = methodInfo.Invoke(@this, null); |
| 8709 | + if (result is bool d) |
| 8710 | + { |
| 8711 | + ret = d; |
| 8712 | + } |
| 8713 | + } |
| 8714 | + return ret; |
| 8715 | + } |
| 8716 | + |
8638 | 8717 | class MockFoo(string name) |
8639 | 8718 | { |
8640 | 8719 | public string Name { get; set; } = name; |
|
0 commit comments