DapperLib / DapperLib/Dapper

Trying to assert contents of DynamicParameters

Open
#1,068 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
18.4k
Forks
3.7k
Avg merge
5h 8m
Merged PRs (30d)
1

Description

Hi!

I'me building out a solution using TDD techniques and while I have all my dapper touch points in a mockable state using NSubstitute I'm struggling to assert the contents of DynamicParameters passed into the dapper calls from SqlBuilder!

Using the following code for example

var sqlBulder = new SqlBuilder();
var query = sqlBulder.AddTemplate("Select Id, Name From Person /**where**/");
sqlBulder.Where("Id = @Id", new {Id = siteId});
DynamicParameters receivedParam = null;

await HubConnection.QueryAsync<Site>(Arg.Any<string>(), Arg.Do<object>(x => receivedParam = x as DynamicParameters));

await Fixture.Get(siteId);

receivedParam.Should().BeEquivalentTo(query.Parameters);

I would have expected the received parameters to match my test parameters, but testing has shown that I can change the actual values and the test still passes.. looking further into the issue it appears that (to the testing framework at least) both objects are empty but behind the scenes I can see that there are templates with the dynamic properties hiding out!

Even when I don't cast the received object to a DynamicParameters class (ie leave as object) I can still see the original class & templates during a debug session!

Any thoughts or suggestions?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the SqlBuilder example around DynamicParameters, QueryAsync, and Fixture.Get(siteId). Inspect how query.Parameters and the object received by QueryAsync expose their values, then determine what assertion behavior is expected and verify it against the observed parameter changes.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, sql
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.