8000 Add support for void sequences by alexbestul · Pull Request #454 · devlooped/moq · GitHub
[go: up one dir, main page]

Skip to content

Add support for void sequences - #454

Closed
alexbestul wants to merge 1 commit into
devlooped:masterfrom
alexbestul:setupsequence-for-void-calls
Closed

alexbestul wants to merge 1 commit into
devlooped:masterfrom
alexbestul:setupsequence-for-void-calls

Conversation

@alexbestul
Copy link
Copy Markdown
Contributor

No description provided.

@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 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 develop branch (you can do so via the Edit button next to your PR's title.) and rebase on top of the main repo's develop branch.

  • 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 #### Added heading under a ## Unreleased section 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();
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.

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
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.

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
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.

  1. Same here regarding the name: if you follow my suggestion and rename the interface, perhaps the class should be called SetupSequentialActionContext?
  2. Please declare the class sealed, I don't think anyone's supposed to, nor is going to, subclass it.

return this;
}

private void DoNothing() { }
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.

Could you please declare this method as static?

{
void Do();

Task DoAsync();
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.

This method looks like it isn't actually used. Please remove.

{
/// <summary>
/// Language for ReturnSequence
/// </summary>
@stakx stakx Oct 1, 2017 •
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.

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);
}
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.

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.)

@alexbestul
Copy link
Copy Markdown
Contributor Author

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 Task, and my code started to conflict with the existing SetupSequence<TMock, TResult> implementation. I'm worried that a complete/correct implementation might require creating separate SetupSequence and SetupSequenceAsync APIs. As I said, though, my first attempt was very brief--I'll give it a more sincere effort, and see if I can come up with something.

@stakx
stakx commented Oct 1, 2017
Copy link
Copy Markdown
Contributor

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.

@alexbestul
Copy link
Copy Markdown
Contributor Author

The feedback in this PR has been addressed in #463. Any further comments can be posted there.

@alexbestul alexbestul closed this Oct 2, 2017
@devlooped devlooped locked and limited conversation to collaborators Sep 7, 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