Skip to content

Commit 9c08e4d

Browse files
committed
test: 增加单元测试
1 parent 97d3e3f commit 9c08e4d

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/BootstrapBlazor/Extensions/DialogServiceExtensions.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,23 @@ public static async Task ShowErrorHandlerDialog(this DialogService service, Rend
263263
};
264264
await service.Show(option, dialog);
265265
}
266+
267+
/// <summary>
268+
/// 显示异常信息对话框扩展方法
269+
/// </summary>
270+
/// <param name="service"></param>
271+
/// <param name="exception"></param>
272+
/// <param name="dialog"></param>
273+
/// <returns></returns>
274+
public static async Task ShowExceptionDialog(this DialogService service, Exception exception, Dialog? dialog = null)
275+
{
276+
RenderFragment fragment = builder =>
277+
{
278+
builder.OpenElement(0, "div");
279+
builder.AddAttribute(10, "class", "error-stack");
280+
builder.AddContent(20, new MarkupString(exception.Message));
281+
builder.CloseElement();
282+
};
283+
await ShowErrorHandlerDialog(service, fragment, dialog);
284+
}
266285
}

test/UnitTest/Components/DialogTest.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,11 @@ await cut.InvokeAsync(() => dialog.ShowCloseDialog<MockValidateFormDialog>("Clos
578578
await cut.InvokeAsync(() => dialog.Show<MockValidateFormDialog>("Test Title"));
579579
await cut.InvokeAsync(() => modal.Instance.CloseCallback());
580580
#endregion
581+
582+
#region ShowExceptionDialog Method
583+
await cut.InvokeAsync(() => dialog.ShowExceptionDialog(new Exception("Test")));
584+
await cut.InvokeAsync(() => modal.Instance.CloseCallback());
585+
#endregion
581586
}
582587

583588
private class MockValidateFormDialog : ComponentBase

0 commit comments

Comments
 (0)