Hi,
I've a unit test for a protected method that contains a ref parameter. The method to test looks like this:
protected void Select(ref int? intReturnValue,
ModelBase modelbase)
{
...some code....
//add the return value
SqlParameter paramReturn = new SqlParameter("@ReturnValue", 0);
paramReturn.Direction = ParameterDirection.ReturnValue;
sqlComm.Parameters.Add(paramReturn);
//run the proc
sqlConn.Open();
sqlComm.ExecuteNonQuery();
//get the return value
intReturnValue = Int32.Parse(sqlComm.Parameters["@ReturnValue"].Value.ToString());
The app checks the intReturnValue for the success or failure of the stored procedure run.
To test this method, I have the following test;
[TestMethod()]
[DeploymentItem("TestNav.exe")]
public void SelectTest()
{
int? intReturnValue = -100;
int? intReturnValueExpected = 0;
ModelBase modelbase = CreateNewPatient();
privateobject.Invoke("Select",
new Type[] { typeof(int?).MakeByRefType(), typeof(ModelBase) },
new object[] { intReturnValue, modelbase });
Assert.AreEqual(intReturnValueExpected, intReturnValue);
}
The problem is that despite passing the intReturnValue by ref using the MakeByRefType() method (or at least attempting to if I have done it correctly), intReturnValue does not update. I have set it's initial value to -100 as this is never returned by the stored proc, but the test always fails - ie. intReturnValue never receives the stored proc return value.
Can anyone please show me where I'm going wrong with this?