I am trying to test some exceptions in my project and one of the Exceptions I catch is SQlException.
It seems that you can\'t go new SqlException(
Edit Ouch: I didn't realise SqlException is sealed. I've been mocking DbException, which is an abstract class.
You can't create a new SqlException, but you can mock a DbException, which SqlException derives from. Try this:
var ex = new Mock();
ex.ExpectGet(e => e.Message, "Exception message");
var conn = new Mock();
conn.Expect(c => c.Open()).Throws(ex.Object);
So your exception is thrown when the method tries to open the connection.
If you expect to read anything other than the Message property on the mocked exception then don't forget to Expect (or Setup, depending on your version of Moq) the "get" on those properties.