Skip to content

Please provide public getter to access DynamicParameters' parameters dictionary object #304

Open

Description

@ericlau-solid

I am using dapper and it is really frustrating that I have no way of mocking a dapper .execute or .query call and write tests on the parameters being sent to those method calls. Get<> method does not work with a mocked IDbConnection, and I am not the only one with this issue: http://stackoverflow.com/questions/29829209/machinespecs-unit-testing-dapper

Please add a getter to the parameters, or allow a way to get not just the param names, but also the input param values.

Activity

  1. johandanforth commented on Jun 20, 2015

    @johandanforth
    Contributor

    I've never tried this myself because mocking system.data is usually too much work to be worth it I think :) But having said that - I can't see why the Get<> wouldn't work. What kind of error do you get and could you provide a simple working example please?

  2. ericlau-solid commented on Jun 20, 2015

    @ericlau-solid
    Author

    I would never suggest we mock system.data. but that is not what this is
    about.

    I am writing a repository class, and depending on data, I have to set sproc
    params differently. I want to unit test if param setup is correct. In unit
    testing, get method does not error, but does not get expected values, thus
    failing unit tests.
    On Jun 20, 2015 06:58, "Johan Danforth" notifications@github.com wrote:

    I've never tried this myself because mocking system.data is usually too
    much work to be worth it I think :) But having said that - I can't see why
    the Get<> wouldn't work. What kind of error do you get and could you
    provide a simple working example please?

    —
    Reply to this email directly or view it on GitHub
    #304 (comment)
    .

  3. johandanforth commented on Jun 21, 2015

    @johandanforth
    Contributor

    I could still use some sample of how you mock the dbconnection + dbcommand for me to test this out and come with a good solution. I've tried mocking dbcommand with MOQ but it didn't went well... :)

  4. ericlau-solid commented on Jun 23, 2015

    @ericlau-solid
    Author

    I have a sample .sln to provide you, but message size is too big. Need
    another way to send you the zipped file (10mb). Please provide a means to
    send this.

    On Sun, Jun 21, 2015 at 3:10 AM, Johan Danforth notifications@github.com
    wrote:

    I could still use some sample of how you mock the dbconnection + dbcommand
    for me to test this out and come with a good solution. I've tried mocking
    dbcommand with MOQ but it didn't went well... :)

    —
    Reply to this email directly or view it on GitHub
    #304 (comment)
    .

    Eric Lau from Gmail account.

  5. johandanforth commented on Jun 23, 2015

    @johandanforth
    Contributor

    Wow, that big even with /bin and /obj removed from the zip? Perhaps you can place it on Google Drive or Microsoft Onedrive and mail me a readonly-link? you reach me at johan_danforth on hotmail

  6. johandanforth commented on Jun 25, 2015

    @johandanforth
    Contributor

    You wrote:

    I am writing a repository class, and depending on data, I have to set sproc
    params differently. I want to unit test if param setup is correct. In unit
    testing, get method does not error, but does not get expected values, thus
    failing unit tests.

    Can't you refactor out the code that do the sproc parameter settings in a separate class/method and test just that?

  7. ericlau-solid commented on Jun 25, 2015

    @ericlau-solid
    Author

    I could, but it is a total workaround in which the only reason for doing so
    is because dapper dynamicparameters do not have public getter. Another
    total workaround is to wrap dynamic parameters. Both add bloat to a code
    that a one getter will resolve.

    Eric
    On Jun 25, 2015 03:01, "Johan Danforth" notifications@github.com wrote:

    You wrote:

    I am writing a repository class, and depending on data, I have to set sproc
    params differently. I want to unit test if param setup is correct. In unit
    testing, get method does not error, but does not get expected values, thus
    failing unit tests.

    Can't you refactor out the code that do the sproc parameter settings in a
    separate class/method and test just that?

    —
    Reply to this email directly or view it on GitHub
    #304 (comment)
    .

  8. ericlau-solid commented on Jun 30, 2015

    @ericlau-solid
    Author

    Johan, I just sent you a zipped file at the address you requested. Thanks.

  9. NickCraver commented on Oct 10, 2015

    @NickCraver
    Member

    @mgravell thoughts on this? I also considered implementing IEnumerable<ParamInfo> with a corresponding .Add() handling cleaning and default sets to be sure which would allow for collection initializers usage, but we'd have to expose ParamInfo to make this possible. I think we can do that safely, but I'm not 100% sure we should (with respect to mutability).

  10. added
    area:api
    on May 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions