为此我使用MSTEST和FluentAssertions 2.0.1.
我已经检查了这个Discussion on Codeplex,并看到它与异步异常方法的工作原理另一个关于FluentAssertions async tests的链接:
经过一段时间尝试使用我的“生产”代码,我已经关闭了Fluentassertions假的aync类,我的结果代码就像这样(把这个代码放在一个[TestClass]中:
[TestMethod] public void TestThrowFromAsyncmethod() { var asyncObject = new Asyncclass(); Action action = () => { Func<Task> asyncFunction = async () => { await asyncObject.ThrowAsync<ArgumentException>(); }; asyncFunction.ShouldNotthrow(); }; } internal class Asyncclass { public async Task ThrowAsync<TException>() where TException : Exception,new() { await Task.Factory.StartNew(() => { throw new TException(); }); } public async Task SucceedAsync() { await Task.Fromresult(0); } }
问题是ShouldNotthrow无效:
ShouldNotthrow method is not recognised by the code. If I try to
compile,it gives me this error:
‘System.Func’ does not contain a
deFinition for ‘ShouldNotthrow’ and the best extension method overload
‘FluentAssertions.AssertionExtensions.ShouldNotthrow(System.Action,
string,params object[])’ has some invalid arguments
谢谢.
解
2.0.1 FA版本不支持这个ShouldNotthrow功能,它将被包含在下一个reléase2.1(接近下周).
注意:在2.0.1versión中已经支持ShouldThrow.
解决方法
原文地址:https://www.jb51.cc/csharp/95361.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。