Code Monkey home page Code Monkey logo

Comments (11)

UnoSD avatar UnoSD commented on May 27, 2024 1
        [Test]
        public void Callback()
        {
            var connection = new Mock<IDbConnection>();

            int[] firstExpected = { 15 };
            int[] secondExpected = { 20 };

            IEnumerable<int> expected = firstExpected;

            connection.SetupDapper(x => x.Query<int>(It.IsAny<string>(), null, null, true, null, null))
                      .Returns(() => expected)
                      .Callback(() => expected = secondExpected);

            var firstActual = connection.Object.Query<int>("");
            Assert.That(firstActual, Is.EquivalentTo(firstExpected));

            var secondActual = connection.Object.Query<int>("");
            Assert.That(secondActual, Is.EquivalentTo(secondExpected));
        }

this may work as a solution. getting it to work appears to be way more complicated than I thought; it's hard to get the previous return value from Moq even with reflection and the ugly alternative is to keep a dictionary of the mocks and return values. I'm going for the hack, but new problems are bubbling up

from moq.dapper.

UnoSD avatar UnoSD commented on May 27, 2024

Hi @steventmayer, I may have some time in December to look at this, from a first glance at the specs, I would check the behaviour of Moq in this case, I have a feeling that it overrides the previous setup, too. One way to get around this would be to add a SetupSequence which I think may be not so difficult to implement and you would be able to setup multiple objects to return.

from moq.dapper.

steventmayer avatar steventmayer commented on May 27, 2024

Let me try playing around with SetupSequence . One area I was looking at was the ability to limit it if I declared the SQL ( c.QueryAsync("SP.StoredProcName" above instead) but need to look further into expressions. If I'm able to get something working, I'll put a PR in and see if you're interested.

from moq.dapper.

UnoSD avatar UnoSD commented on May 27, 2024

Thanks, I'll do my best to find some time to look at the PR as soon as possible.

from moq.dapper.

shahabganji avatar shahabganji commented on May 27, 2024

Let me try playing around with SetupSequence . One area I was looking at was the ability to limit it if I declared the SQL ( c.QueryAsync("SP.StoredProcName" above instead) but need to look further into expressions. If I'm able to get something working, I'll put a PR in and see if you're interested.

@steventmayer

Do you mind if I ask for a simple sample?

from moq.dapper.

kaijday avatar kaijday commented on May 27, 2024

@steventmayer @UnoSD @shahabganji

Did this get resolved?

from moq.dapper.

IanKeefer avatar IanKeefer commented on May 27, 2024

@steventmayer @UnoSD would like an update on the status of this if possible.

Thanks

from moq.dapper.

hampton1122 avatar hampton1122 commented on May 27, 2024

Is there a solution to this yet?

from moq.dapper.

IanKeefer avatar IanKeefer commented on May 27, 2024

Is there a solution to this yet?

I haven't ran into one myself and our unfortunate result so far is omitting the functions from code coverage.

Looks as if this repo is finished as the owner hasn't been active here or on GitHub in a long time.

from moq.dapper.

yogeshk97 avatar yogeshk97 commented on May 27, 2024

Is there any update on this issue please?
This hack is not working for me @UnoSD

        _mockIDbConnection
           .SetupDapperAsync(c => c.QueryAsync<ComboDishListModel>(
               It.IsAny<string>(), // You can specify the exact SQL query if needed
               It.IsAny<object>(),  // You can specify the expected parameters if needed
               It.IsAny<IDbTransaction>(),
               It.IsAny<int?>(),
               It.IsAny<CommandType?>()))
           .ReturnsAsync(comboDishListModels); // Provide the expected result

        _mockIDbConnection
.SetupDapperAsync(c => c.QueryAsync<OrderViewModel>(
    It.IsAny<string>(),
    new { command.OrderId, command.UserId },
    It.IsAny<IDbTransaction>(),
    It.IsAny<int?>(),
    It.IsAny<CommandType?>()))
.ReturnsAsync(ordersResult);

When apply the second setup, it overrides the first mock setup, even if T is different

from moq.dapper.

UnoSD avatar UnoSD commented on May 27, 2024

@yogeshk97 at the moment I do not have the capacity for working on the repo, but I welcome PRs and I am happy to review.

from moq.dapper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.