我有一个看似愚蠢和简单的问题,但我几乎不知道如何进行。
我的问题是:
如何修改异常消息并对其进行自定义,以便我的单元测试仍然通过?
实际上我想自定义异常消息“学生“Johny”有相关文件!” 并且由于修改了 API 异常消息,单元测试失败。
约翰尼是一个可能会改变的变量......
任何帮助我如何实现上述目标。谢谢
在我的测试课上,我有
[ExpectedException(ExceptionType = typeof(Exception), ExpectedMessage = "The DELETE statement conflicted with the REFERENCE constraint \"FK_Issue_Priority\"")]
实际上我正在使用 NHibernate 并且在我的 API 中我正在处理如下异常:
catch (NHibernate.ADOException exception)
{
if (exception.InnerException.GetType().Equals(typeof(System.Data.SqlClient.SqlException)))
{
if (exception.InnerException.Message.Contains("FK_Issue_Priority"))
{
throw new Exception("The DELETE statement conflicted with the REFERENCE constraint \"FK_Issue_Priority\"");
}
else
{
throw new Exception("A database error occurred while trying to add the customer to project relation please the see inner exception for details", exception.InnerException);
}
}
else
{
throw exception;
}
}