I’d like to Assert that an exception is being thrown and then check some of the properties of the thrown exception.
I was under the impression that I could do something like the following:
ICommand command = CreateCommandObj();
Assert.That( () => command.DoWork(), Throws.TypeOf<ArgumentException>(),
Has.Property("ParamName").EqualTo("myParam") &
Has.Property("Message").EqualTo("myMessage") );
However this doesn’t even compile and looking at the expected parameters for Assert.That I can’t see how I would be able to do this? I’m sure I have used this before though…
Note the above is a contrived example to illustrate the point, ignore the fact I am looking for an ArgumentException on a method that doesnt except any parameters 🙂
Any help appreciated.
1) Cannot convert lambda expression to type ‘object’ because it is not a delegate type.
Ok, sorted.
I need to use the following syntax:
This approach allows me to check properties on the thrown exception. I can add any number of And or Or’s to the Assert.
Thanks everyone for the suggestions.