I'm creating some unit tests for a class library that does manipulations in a database.
The method being tested is this:
public object ExecuteNoQueryOperation ( string spOrSqlInstructions, CommandType commandType = CommandType.StoredProcedure, Dictionary<string, object> parameters = null )
{
NpgsqlCommand npgsqlCommand = new NpgsqlCommand(spOrSqlInstructions, Connection);
npgsqlCommand.CommandType = commandType;
if ( parameters != null )
foreach ( var item in parameters )
npgsqlCommand.Parameters.Add ( new NpgsqlParameter ( item.Key, item.Value ) );
try
{
Connection.Open ( );
return npgsqlCommand.ExecuteScalar ( );
}
catch ( NpgsqlException e )
{
throw new Exception ( "Error: " + e.ToString() );
}
finally
{
if ( Connection != null && Connection.State != ConnectionState.Closed )
Connection.Close ( );
npgsqlCommand.Dispose ( );
}
}
And here's my test case:
[TestMethod]
public void TestCallFunction ( )
{
Dictionary<string, object> dic= new Dictionary<string, object> ();
dic.Add ( "f_name", "Joice Silva" );
dic.Add ( "f_age", 31 );
pgDal.ExecuteNoQueryOperation ( "insertPerson", parameters: dic);
Assert.AreEqual ( 31, ret);
}
While running this test I'm getting the error:
Test Name: TestCallFunction FullName from Test: DataAccessLayerTest.PostgreSqlDataAccessTest.TestCallFunction Test Source: C: \ Users \ Matheus Hail \ OneDrive \ Development \ Systems \ DataAccessLayer \ DataAccessLayer \ DataAccessLayerTest \ PostgreSqlDataAccessTest.cs: line 39 Test result: Failed Duration of test Test: 0: 00: 00,1025821
Result StackTrace: in DataAccessLayerTest.PostgreSqlDataAccessTest.TestCallFunction () on C: \ Users \ Matheus Hail \ OneDrive \ Development \ Systems \ DataAccessLayer \ DataAccessLayer \ DataAccessLayerTest \ PostgreSqlDataAccessTest.cs: line 45 Result message: Test method DataAccessLayerTest.PostgreSqlDataAccessTest.TestCallFunction generated Exception: System.NullReferenceException: Object Reference Does Not defined for an instance of an object.
I can not identify the error.