Skip to content
grahamrhay edited this page Feb 22, 2011 · 1 revision

#Throws

Matches if the block throws an exception of the expected type

    [Test]
    public void Throws()
    {
        Assert.That(() => { throw new ArgumentNullException(); }, Throws.An<ArgumentNullException>());

        // with predicate
        Assert.That(() => { throw new ArgumentNullException("message", new Exception()); }, 
            Throws.An<ArgumentNullException>().With(e => e.Message == "message" 
            && e.InnerException.GetType() == typeof(Exception)));
    }
Clone this wiki locally