我正在使用Bunit,Xunit和Moq为blazor webAssembly编写单元测试。
我想嘲笑MudBlazor.IDialogService
测试文件
var mockDialogService = new Mock<IDialogService>();
var ctx = new Bunit.TestContext();
ctx.Services.AddScoped<IDialogService, DialogService>();
var cut = new Participant(
mockDialogService.Object
);
剃刀法
var parameters = new DialogParameters();
parameters.Add("ContentText", "Please assign coordinator before schedule a meeting.");
parameters.Add("ButtonText", "Ok");
parameters.Add("Color", Color.Primary);
var options = new DialogOptions() { MaxWidth = MaxWidth.Medium };
var dialogresult = DialogService.Show<ConfirmationDialog>("Warning", parameters, options);
// when debugging in test mode dialogresult is null how can I setup this?
var result = await dialogresult.Result;
1条答案
按热度按时间jogvjijk1#
您需要模拟代表对话框的
IDialogReference
:然后将模拟的服务添加到DI容器中: