Had an API controller under unit test which made use of the HttpMessageRequest which I needed to mock.How do I get a handle on this?
Again pretty simple really (my initial train of thought was back to front on this one)
var request = new HttpMessageRequest(HttpMethod.Get, "http://....."
controllerUnderTest.request = request;
I was unable to mock
as SQLException has a parameterless constructor as in….
‘System.Data.SqlClient.SqlException’ must be a non-abstract type with a public parameterless constructor in order to use it as parameter ‘TException’ in the generic type or method ‘Moq.Language.IThrows.Throws()’
So what to do?
var exception = FormatterServices.GetUninitializedObject(typeof(SqlException)) as SqlException;
mockInvalidDBContext.Setup(d => d.GetConnection()).Throws(exception);
Credit to http://stackoverflow.com/questions/11976996/moq-and-throwing-a-sqlexception
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.