我有一些代码断言调用方法时引发异常,然后断言异常的各种属性:
var ex = Assert.Throws<MyCustomException>(() => MyMethod());
Assert.That(ex.Property1, Is.EqualTo("Some thing");
Assert.That(ex.Property2, Is.EqualTo("Some thing else");
我想将Assert.Throws<T>
调用转换为使用Assert.That
语法,因为这是我个人的偏好:
Assert.That(() => MyMethod(), Throw.Exception.TypeOf<MyCustomException>());
但是,我不知道如何从中返回异常,所以我可以执行后续的属性断言。有任何想法吗?