Open vbreuss opened 3 hours ago
Funny timing, I actually started the work on casting objects back for some assertions last night:
My PR is currently more a proof of concept, so I am happy to adapt it to incorporate your changes, if you agree to the overall API changes...
I have a couple of issues with the current implementation of the
Throw
assertions:.ThrowsException().OfType<ArgumentException>(()
instead ofThrowsException<ArgumentException>()
Assert.That(action).ThrowsException()
I don't get the exception back to make further assertions on it.With.Message
does not keep the reference to the original exception.My suggestion is to refactor the delegate assertions as follows:
.Throws()
which removes the generic overload ofTActual
from subsequent calls.Nothing()
(no exception is thrown).Exception()
(any exception is thrown).OfType<TException>()
(an exception of type TException or any subtype is thrown).Exactly<TException>()
(an exception of type TException is thrown).WithMessage(string)
(checks that the message is equal).WithMessageMatching(string)
(checks that the message matches the (wildcard) pattern)WithInnerException()
which allows checks on the inner exceptionI created draft PR #870 to show, how this could be implemented...