我有一个名称的设计器类,ExpenseReceipts.aspx.designer.cs
其中部分类 ExpenseReciepts 包含
public partial class ExpenseReceipts {
protected global::System.Web.UI.WebControls.Panel ResultPanel;
}
我在使用 this 的模块中有另一个类 ExpenseReceipts.aspx.cs ResultPanel
。
public partial class ExpenseReceipts : LayoutsPageBase
{
public void HandleRecordsNotFound()
{
ResultPanel.Visible = false;
NoItemsMessage.Text = "No Items Found!!!";
NoItemsMessage.ForeColor = System.Drawing.Color.Red;
NoItemsPanel.Visible = true;
}
}
就生产代码而言,这可以正常工作,但是当我尝试为其编写单元测试时会出现问题。我有以下方法试图在这里填充所有内容。
[TestMethod]
public void HandleRecordsNotFound_ShouldMakeNoResultPanelVisible()
{
using (ShimsContext.Create())
{
bool flag = false;
ShimControl.AllInstances.VisibleSetBoolean = (PANEL, BOOLEAN) => { };
ShimLabel.AllInstances.TextSetString = (LABEL, TEXT) => { };
ShimWebControl.AllInstances.ForeColorSetColor = (WEBCONTROL, FORECOLOR) => { };
ShimControl.AllInstances.VisibleSetBoolean = (CONTROL, BOOLEAN) => { flag = true; };
ExpenseReceipts expenseReceipts = new ExpenseReceipts();
expenseReceipts.HandleRecordsNotFound();
Assert.IsTrue(flag);
}
}
它失败是因为 HandleRecordsNotFound 中抛出的异常说NUll pointer exception
指示 - ResultPanel
为空。
请帮我解决这个问题。提前致谢。PS:我正在使用 Sharepoint 2019。