Comments (11)
[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.
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.
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.
Thanks, I'll do my best to find some time to look at the PR as soon as possible.
from moq.dapper.
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.
Do you mind if I ask for a simple sample?
from moq.dapper.
@steventmayer @UnoSD @shahabganji
Did this get resolved?
from moq.dapper.
@steventmayer @UnoSD would like an update on the status of this if possible.
Thanks
from moq.dapper.
Is there a solution to this yet?
from moq.dapper.
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.
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.
@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)
- moq.dapper 1.0.4 is a breaking change (only targets .Net Standard 2.1)
- When writing a test for query which has .Any method it throws an error Value cannot be null
- issue with DateTime in Core3.1 (works on 2.1)
- QuerySingleOrDefault cannot return null HOT 1
- QueryFirstAsync<string> doesn't work and throws sequence contains no elements error HOT 2
- Cannot moq 'Execute' after mocking 'QuerySingle<int>'
- How to Moq QueryMultipleAsync HOT 2
- ObjectExtensions - ToDataTable does not support string HOT 1
- QueryAsync<Dynamic> HOT 4
- Cannot mock ExecuteAsync for IDbConnection HOT 1
- Cannot QueryFirstAsync with Enum Type
- Can't query Tuples. Requires wrapping class type.
- One Approach to Moq dapper methods that not supported by this project
- No Support for ExecuteAsync on IDBConnection
- ExecuteScalarAsync not supported
- GPL2 licence issues HOT 3
- QueryAsync returns no records
- Moq with ReturnAsync for GUID is not working
- Testing Query with string array parameter
- Requesting support for Verify functions too
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from moq.dapper.