Skip to content

codibre/dotnet-sqlserver-connection-mock

Repository files navigation

Actions Status Actions Status Actions Status benchmark Test Coverage Maintainability

SqlServer mocking library for unit tests that uses Sqlite in-memory under the hood.

Why

Although one can argue that having a in memory real database is not unit testing, the results of using such approach for repositories unit tests is way better than mocking it using a IEnumerable, specially when working with Dapper.

How to use it

First, import the application namespace:

using Codibre.SqlServerMock

Now, create your connection using MssqlMockDbConnection. You'll need to create every table entity using SqlLite commands in your unit tests. For now, this library will only work with a limited number of SELECT queries.

Here's a list of idiomatics differences already treated here:

  • TOP => LIMIT;
  • (NOLOCK) => Removed as Sqlite doesn't have anything like that;
  • CONCAT Function => Little hacky but replaced using regex by || operator. Need to be refactored by using parsed TSqlFragment;

What comes next?

Anything that comes in the way of unit testing sql server repositories can be converted here, but be aware, that this library has no intention at all of reflecting every possible SQL Server functionality using in-memory SqlLite: it is absolutely impossible! But we believe is commom sense that the most commom used ones are expected to be possible to convert. Although we know that not everything will be possible to cover, having a least a good part of the repository layer unit tested, can really put the quality of a project to another level!

License

Licensed under MIT.

About

SqlServer connection mocker, for unit tests

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages