我在寻找一个私有静态方法的方法时遇到了问题。尽管我知道测试并不是必要的,但我的老板希望进行测试。
这是我正在尝试测试的代码:
namespace Retail_Utilities.Printables
{
public partial class WarrantyDropoffSlip : INotifyPropertyChanged
{
private static string AddBusinessDays(string businessDays)
{
if (string.IsNullOrEmpty(businessDays)) return DateTime.Now.ToShortDateString();
var bDays = int.Parse(businessDays);
var date = DateTime.Now;
while (bDays > 0)
{
date = date.AddDays(1);
if (date.DayOfWeek != DayOfWeek.Saturday && date.DayOfWeek != DayOfWeek.Sunday)
bDays--;
}
return date.ToShortDateString();
}
}
}
这是我的测试代码。
namespace RetailUtilitiesUnitTests.Printables_TEST
{
[TestClass]
public class WarrantyDropoffSlipTEST
{
[TestMethod]
public void AddBusinessdays_ValidInput()
{
PrivateObject po = new PrivateObject(typeof(WarrantyDropoffSlip));
object[] parameters = {"Sunday"};
po.Invoke("AddBusinessDays", parameters);
}
}
}
有什么想法吗?