Skip to content

Instantly share code, notes, and snippets.

@PureKrome
Created February 6, 2014 03:47
Show Gist options
  • Save PureKrome/8838120 to your computer and use it in GitHub Desktop.
Save PureKrome/8838120 to your computer and use it in GitHub Desktop.
Dapper-Wrapper idea.
This is something that i'm doing .. and right now .. there's no way I can. (Yes, i can fork and PR :+1: )
(pseudo code)
public class Foo
{
private readonly string _connectionString;
private readonly IDbExecutor _sqlConnectionWrapper;
// Ctor - for normal code.
public Foo(string connectionString)
{
connectionString.ShouldNotBeEmpty();
_connectionString = connectionString
}
// Ctor - for when we mock.
public Foo(IDbExecutor dbExecutor)
{
dbExecutor.ShouldNotBe(null);
_dbExecutor = dbExecutor;
}
// Method to test.
public int? Bar()
{
int? userId = 0;
using (var sqlConnection = (_sqlConnectionWrapper ?? new SqlExecutor(new SqlConnection(_connectionString))))
{
try
{
sqlConnection.Open(); // ******* Compile Error *******
userId = sqlConnection.Query<int?>("SELECT ... ").SingleOrDefault();
}
finally
{
sqlConnection.Close();
}
}
return userId;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment