Repository navigation
Add support for void sequences - #454
alexbestul wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Thanks for this PR! It is looking very good. Only a couple of general requests (apart from the line notes):
-
Please change this PR's target branch to the
developbranch (you can do so via the Edit button next to your PR's title.) and rebase on top of the main repo'sdevelopbranch. -
Please include the copyright notice at the beginning of all new files.
-
Please include a short summary of your changes in
CHANGELOG.md. (This should go under a#### Addedheading under a## Unreleasedsection at the top of the changelog, above the most recent version.)
That's it! :)
| /// <summary> | ||
| /// Throws an exception | ||
| /// </summary> | ||
| ISetupSequentialVoidResult Throws<TException>() where TException : Exception, new(); |
There was a problem hiding this comment.
I understand that you've written this interface to have the same basic structure as ISetupSequentialResult, so it's fine. Just as an aside, this could probably be an extension method on ISetupSequentialVoidResult (a.k.a. ISetupSequentialAction) instead, since its implementation is likely the same for all implementations. But let's keep it as is for now, for consistency's sake.
| /// <summary> | ||
| /// Language for ReturnSequence | ||
| /// </summary> | ||
| public interface ISetupSequentialVoidResult |
There was a problem hiding this comment.
I am not going to insist on this, but may I suggest that you rename this interface ISetupSequentialAction? …VoidResult just strikes me as somewhat contradictory. Perhaps later we could rename the existing ISetupSequentialResult to ISetupSequentialFunc to regain consistency.
|
|
||
| namespace Moq | ||
| { | ||
| internal class SetupSequentialVoidContext<TMock> : ISetupSequentialVoidResult |
There was a problem hiding this comment.
- Same here regarding the name: if you follow my suggestion and rename the interface, perhaps the class should be called
SetupSequentialActionContext? - Please declare the class
sealed, I don't think anyone's supposed to, nor is going to, subclass it.
| return this; | ||
| } | ||
|
|
||
| private void DoNothing() { } |
There was a problem hiding this comment.
Could you please declare this method as static?
| { | ||
| void Do(); | ||
|
|
||
| Task DoAsync(); |
There was a problem hiding this comment.
This method looks like it isn't actually used. Please remove.
| { | ||
| /// <summary> | ||
| /// Language for ReturnSequence | ||
| /// </summary> |
There was a problem hiding this comment.
I know this is the same comment as is used for the existing ISetupSequentialResult, but I think it would be better to use a <summary> description such as you find with e.g. ICallback or IRaise. That is, something like this:
/// <summary>
/// Defines the <c>Pass</c> and <c>Throws</c> verbs for sequence setups on <c>void</c> methods.
/// </summary>(The existing summary on ISetupSequentialResult can be adjusted to be in line with all the others at a later point in time.)
| where TMock : class | ||
| { | ||
| return new SetupSequentialVoidContext<TMock>(mock, expression); | ||
| } |
There was a problem hiding this comment.
I'm also not going to insist on this, but do you think we should also add PassAsync() and ThrowsAsync() overloads for consistency? (I haven't thought about it too much, to be honest, so probably it doesn't actually make sense.)
|
Thanks for the thorough feedback. The changes all sound perfectly reasonable and easily doable (with the possible exception of Async--more on that shortly). I'll make them and update this PR. I did make a very brief attempt at Async support before submitting my initial PR. I ran into problems because Async methods must return a |
|
Don't worry too much about the async bit, it can be dealt with later. Async support in Moq is somewhat spotty already, and there's still an open issue about cleaning it all up... I'll need to get back on that soon. |
|
The feedback in this PR has been addressed in #463. Any further comments can be posted there. |
No description provided.