我正在尝试验证返回的异常和消息,但我在此消息中有一个可变的文件名。是否可以仅在一种方法中使用单元测试来做到这一点?
public static string FileName
{
get
{
return "EXT_RF_ITAUVEST_201605091121212";
}
}
[TestMethod()]
[ExpectedException(typeof(Exception), String.Format("Error on file {0}", FileName))]
public void ValidarNomeArquivo_DataNomeIncorreta_Mensagem()
{
throw new Exception(String.Format("Error on file {0}", FileName));
}
上面的代码返回错误“属性参数必须是属性参数类型的常量表达式、typeof表达式或数组创建表达式。”。