|
|
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?FreeOZ用户注册
x
大家好,
我有一个method需要unit testing
using Microsoft.VisualStudio.TestTools.UnitTesting;
public async Task Test(string sql)
{
if (string.IsNullOrWhiteSpace(sql))
{
throw new ArgumentNullException("sql");
}
......
}
我现在可以用下面的代码来测试,没问题
[TestMethod]
public void ParameterEmpty_ExpectedException()
{
......
try
{
xxx.Test(string.Empty).Wait();
}
catch (AggregateException ae)
{
Assert.AreEqual(1, ae.InnerExceptions.Count);
Assert.IsTrue(ae.InnerExceptions[0] is ArgumentNullException);
}
}
但我想如下面一样仅在头上加,问题是AggregateException太广了,我想指定InnerExceptions是ArgumentNullException,该如何写啊?
[TestMethod]
[ExpectedException(typeof(AggregateException))]
public void ParameterEmpty_ExpectedException()
谢谢 |
|