When is a Test not a Unit-test?

See Michael Feathers’ definition A test is not a unit test if: It talks to the database It communicates across the network It touches the file system It can’t run at the same time as any of your other unit tests You have to do special things to your environment (such as editing config files) … Read more

how do I mock sqlconnection or should I refactor the code?

SqlBulkWriter class is tightly coupled to implementation concerns which make it difficult to test the class in isolation. Knowing the connection string is not really a concern of that class and can be delegated out to another service. Something like public interface IDbConnectionFactory { IDbConnection CreateConnection(); } and its implementation for your class would look … Read more

Testing route configuration in ASP.NET WebApi

I was recently testing my Web API routes, and here is how I did that. First, I created a helper to move all Web API routing logic there: public static class WebApi { public static RouteInfo RouteRequest(HttpConfiguration config, HttpRequestMessage request) { // create context var controllerContext = new HttpControllerContext(config, Substitute.For<IHttpRouteData>(), request); // get route data … Read more