I have the following code to test that when a certain name is passed to my method, it throws a SQL exception (there is reason to that one, although it sounds a little odd).<
I just tried this out, and it worked for me:
private static void ThrowSqlException() { using (var cxn = new SqlConnection("Connection Timeout=1")) { cxn.Open(); } } // ... mockAccountDAL.Setup(m => m.CreateAccount(It.IsAny), "Display Name 2", It.IsAny())) .Callback(() => ThrowSqlException());