Skip to content

Am I able to mock an output parameter #26

Description

@tpeiffer

Hello,

Given a function that executes a proc and returns the value of an output parameter, is it possible to Mock those parameters so that I can test that the method returns the correct value?

Given this method snippet in C#

var sproc = "dbo.usp_SomeProc";

var parameters = new DynamicParameters();
parameters.Add("@inParam", 100);
parameters.Add("@outParam", dbType: DbType.Int32, direction: ParameterDirection.Output);

await this.DbConnection
    .QueryAsync<int?>(sproc, parameters, commandType: CommandType.StoredProcedure);

return parameters.Get<int?>("outParam");

And this is where my test is at

// Arrange
var repository = this.CreateRepository();
var parameters = new DynamicParameters();
parameters.Add("@inParam", 100);
parameters.Add("@outParam", 999, DbType.Int32, ParameterDirection.Output);

var mockDbConnection = new MockDbConnection(new Settings() { ResetDapperCachePerCommand = true });
mockDbConnection
    .Setup(c => c.ExecuteAsync("dbo.usp_SomeProc", parameters, null, null, CommandType.StoredProcedure));

// Act
var result = await repository.Get(...);

// Assert
Assert.AreEqual(999, result);

Unfortunately, the test returns
Message: Assert.AreEqual failed. Expected:<999>. Actual:<(null)>.

I'm assuming that I need to mock more deeply into the command chain somehow.

Thanks for any guidance!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions