Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignoring latest setup #1311

Closed
DVH-H opened this issue Dec 12, 2022 · 1 comment
Closed

Ignoring latest setup #1311

DVH-H opened this issue Dec 12, 2022 · 1 comment

Comments

@DVH-H
Copy link

DVH-H commented Dec 12, 2022

Encountered an unusal issue where the latest setup gets ignored (Cant find any similiar issues).

In the ctor of my TestClass i instantiate my repo with these setups.

_arcGis.Setup(x => x.AddFeatures(new List<Feature<Point>>())).ReturnsAsync(0);
_arcGis.Setup(x => x.UpdateFeatures(new List<Feature<Point>>())).ReturnsAsync(0);
_arcGis.Setup(x => x.DeleteFeatures(new List<Feature<Point>>())).ReturnsAsync(0);

(Returns the amount of affectedRows)

Trying to make the best use out of "If more than one setup is specified for the same method or property, the latest one wins and is the one that will be excuted"

Later in the respective test methods i overwrite those setups with eg.

_arcGis.Setup(x => x.AddFeatures(FeatureListWithItem)).ReturnsAsync(1);

Which works perfectly for all the other methods expect the on above. Where for some reason it ignores the new setup completely and makes use of the setup or mock from the ctor.

[DoesntWork]
image

[Works]
image

Assert.Equal() Failure
Expected: (1, 0, 0)
Actual: (0, 0, 0)

@stakx
Copy link
Contributor

stakx commented Dec 13, 2022

It's a bit diffucult to puzzle together what exactly your code looks like, given only these fragments and screenshots. Could you perhaps show your code directly?

_arcGis.Setup(x => x.AddFeatures(FeatureListWithItem)).ReturnsAsync(1);

Assuming that the type of FeatureListWithItem is a reference type, are you aware that this setup will only ever trigger when you call _arcGis.Mock.AddFeatures with that exact object as an argument? That is, it won't be enough to pass in some list containing a specific feature; you'll have to pass in that specific list (and its contents will be irrelevant).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants