8000 Support indexer with multiple arguments by idigra · Pull Request #694 · devlooped/moq · GitHub
[go: up one dir, main page]

Skip to content

Support indexer with multiple arguments - #694

Merged
stakx merged 2 commits into
devlooped:masterfrom
idigra:indexer-with-multiple-arguments
Oct 8, 2018
Merged

stakx merged 2 commits into
devlooped:masterfrom
idigra:indexer-with-multiple-arguments

Conversation

@idigra
@idigra idigra commented Sep 18, 2018
Copy link
Copy Markdown
Contributor

This PR contains support in multiple arguments.

  1. Fix null reference exception in case of multiple arguments indexer.
  2. Proposal for new API method SetupSetMethod which allows using It.IsAny for the indexer arguments (can be used also for properties, although existing API already covers properties). This is only in proposal level, should be enhanced (documentation, overloading for any count of indexer arguments, exceptions on illegal input).

@stakx
stakx commented Sep 18, 2018 •
Copy link
Copy Markdown
Contributor

Hi @idigra, and thanks for this PR, too. Same as with the earlier one from today, I'll try to find some time for reviewing this soon.

Fix null reference exception in case of multiple arguments indexer.

Which null reference exception are we talking about here? Could you post an issue with repro code (or refer me to an existing closed issue)?

Proposal for new API method SetupSetMethod [...]

It shouldn't be necessary to introduce a SetupSetMethod. You'll find that the existing Setup, SetupGet, SetupSet etc. methods already try to recognize when they are called on indexers—indexers shouldn't have their own dedicated methods, from a user's perspective that doesn't make much sense. (SetupGet and SetupSet are probably already confusing enough.)

The problem with It.IsAny and SetupSet would be easily solvable by bringing back the old, deprecated SetupSet overload that takes two expressions: one for the property/indexer to be set up, and one for the value. But unfortunately, that overload has been marked deprecated. I think we should rather de-deprecate the existing method, instead of introducing a new one (if we do something at all).

@idigra
idigra commented Sep 20, 2018 •
Copy link
Copy Markdown
Contributor Author

Which null reference exception are we talking about here? Could you post an issue with repro code (or refer me to an existing closed issue)?

I added a test in the PR that reproduces the bug, named CallbackWithMultipleArgumentIndexerSetterWithoutAny. Now there's an issue #695 :)

I think we should rather de-deprecate the existing method, instead of introducing a new one (if we do something at all).

Why not? I think it's a useful scenario.
(BTW, even if you think not to de-deprecate, we should solve following issue: #696).

@idigra
idigra commented Sep 20, 2018
Copy link
Copy Markdown
Contributor Author

I now see that the second issue I opened (#696, mentioned above) is a duplicate of #218 which is closed in favor of #414. I couldn't find the reason why the SetupSet overload you mentioned was deprecated. Also consider the solution I proposed in my issue #696.

@stakx
stakx commented Sep 20, 2018
Copy link
Copy Markdown
Contributor

I couldn't find the reason why the SetupSet overload you mentioned was deprecated.

I don't know the exact reason, either. I am guessing that this decision was made simply because being able to write SetupSet(m => m.Something = value) is nicer than SetupSet(m => m.Something, () => value).

@stakx stakx left a comment •
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again for your PR! 👍

I'd appreciate if we could focus only on your PR's first stated goal, i.e. fixing the NullReferenceException when setting up an indexer with more than one index parameter. This is the reason why I'm asking you (below) to remove everything related to SetupSetMethod.

I'm happy to discuss SetupSetMethod / the deprecated SetupSet overload / improvements of the current implementation of SetupSetImpl in a separate issue, if you'd like.

Also, please add an entry for your bug fix to CHANGELOG.md:

 # Moq Changelog

 All notable changes to this project will be documented in this file.

 The format is loosely based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).


+## Unreleased
+
+#### Fixed
+
+* Short description of your bugfix (@idigra, #694)
+
+
 ## 4.10.0 (2018-09-08)

Comment thread src/Moq/Mock.cs Resolved
Comment thread tests/Moq.Tests/CallbacksFixture.cs Resolved
Comment thread tests/Moq.Tests/CallbacksFixture.cs Resolved
Comment thread tests/Moq.Tests/CallbacksFixture.cs Resolved
Comment thread tests/Moq.Tests/CallbacksFixture.cs Resolved
Comment thread src/Moq/Mock.Generic.cs Resolved
Comment thread src/Moq/Mock.cs Resolved
@stakx stakx left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for being quiet so long. All good to go now. I'll update the changelog for you.

Comment thread src/Moq/Mock.cs Resolved
@stakx
stakx merged commit 065afe7 into devlooped:master Oct 8, 2018
@stakx stakx added this to the 4.10.1 milestone Oct 15, 2018
@stakx
stakx commented Dec 3, 2018
Copy link
Copy Markdown
Contributor

@idigra, Moq 4.10.1, which includes your bugfix, has just been published on NuGet.

@idigra
idigra commented Dec 28, 2018
Copy link
Copy Markdown
Contributor Author

Thanks. I finally came to verify it, but then I understand that without extending the API to support Any match 8000 er in indexer argument I can't really reach a scenario in which the bug was reproduced.
I would be happy to check it if you have a real scenario in which the bug occurs.

@stakx
stakx commented Dec 29, 2018
Copy link
Copy Markdown
Contributor

I can't really reach a scenario in which the bug was reproduced.

Sorry, it's been a while, and there's not much context here. Which bug exactly are you referring to?

@idigra
idigra commented Dec 30, 2018
Copy link
Copy Markdown
Contributor Author

#696

@devlooped devlooped locked and limited conversation to collaborators Sep 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0