我正在尝试找到从我的逻辑中解开消息框的最佳方法,以便我可以正确地对其进行单元测试.现在我想知道如果我只是制作了一个单独的帮助类(C#)就足够了,我可以稍后将其存储到我的消息框中.例如:
static class messageBoxHelper
{
public static void msgBoxAlg(string message, string title, MessageBoxButtons buttons, MessageBoxIcon icons, bool show)
{
if (show)
{
MessageBox.Show(message, title, buttons, icons);
}
}
Run Code Online (Sandbox Code Playgroud)
然后,每当我需要使用消息框时,我只使用messageboxHelper/msgBoxAlg(...)而不是messagebox.show(...).使用bool show我可以在测试期间启用或禁用它.
我只是想知道这是否是"正确的方法".我的意思是,是否有更简单或更好的方法来做到这一点?我不能只丢弃消息框,他们将"重要"信息传递给用户("你想关闭这个窗口吗?"是/否等).它也可能只是我没有使用适当的软件工程,我应该将我的消息框与我的bussinesslogic分开更多?