Skip to content

Instantly share code, notes, and snippets.

@WilliamBerryiii
Last active July 7, 2017 07:39
Show Gist options
  • Save WilliamBerryiii/3c1eb22fc963cffe6cbf to your computer and use it in GitHub Desktop.
Save WilliamBerryiii/3c1eb22fc963cffe6cbf to your computer and use it in GitHub Desktop.
Simple example of testing a stored procedure return code parameter with Moq
const string RETURN_CODE_NAME = "@return_code";
const int SP_RETURN_VALUE = 0;
Dictionary<string, SqlParameter> parameterList = null;
_mockSqlExecutor = new Mock<ISqlExecutor>();
_mockSqlExecutor.Setup(mdm =>
mdm
.ExecuteNonQuery(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<Dictionary<string, SqlParameter>>()))
.Callback(
(string conn, string procName, Dictionary<string, SqlParameter> plist) =>
{
parameterList = plist;
plist["RETURN_CODE_NAME"].Value = SP_RETURN_VALUE;
});
//Do Stuff With Mock Sql Executor
Assert.AreEqual(SP_RETURN_VALUE, (int)(parameterList["RETURN_CODE_NAME"].Value));
@freesky7
Copy link

freesky7 commented Jul 7, 2017

Hi,
Can I ask for what is the library ISqlExecutor belongs to?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment