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

VerifyNoOtherCalls: Fix bugs with Mock.Of<T> #543

Merged
merged 2 commits into from
Dec 3, 2017

Conversation

stakx
Copy link
Contributor

@stakx stakx commented Dec 3, 2017

This PR ensures that mocks created with Mock.Of<T> initially have no recorded invocations.

Due to the way Mock.Of<T> is currently implemented, mocks created using this method might already have recorded invocations. This never really mattered up until now, where it can interfere with VerifyNoOtherCalls.

This solves one of two issues with the initial VerifyNoOtherCalls implementation, as tracked in #527 (comment).

Mocks created with `Mock.Of<T>` can already have recorded invocations.
This can make `VerifyNoOtherCalls` fail unexpectedly, as these tests
demonstrate.
@@ -108,7 +108,7 @@ public static class Mocks
[Obsolete("Moved to Mock.Of<T>, as it's a single one, so no reason to be on Mocks.", true)]
public static T OneOf<T>(Expression<Func<T, bool>> specification) where T : class
{
return CreateMockQuery<T>().First<T>(specification);
return Mock.Of<T>(specification);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Delegate to Mock.Of<T> (as claimed by the [Obsolete] attribute's message) so we don't need to duplicate the hack here.

@@ -94,7 +94,7 @@ public static class Mocks
[Obsolete("Moved to Mock.Of<T>, as it's a single one, so no reason to be on Mocks.", true)]
public static T OneOf<T>() where T : class
{
return CreateMockQuery<T>().First<T>();
return Mock.Of<T>();
Copy link
Contributor Author

@stakx stakx Dec 3, 2017

Choose a reason for hiding this comment

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

Delegate to Mock.Of<T> (as claimed by the [Obsolete] attribute's message).

@stakx stakx merged commit 4e06466 into devlooped:develop Dec 3, 2017
@stakx stakx deleted the verify-no-other-calls branch December 3, 2017 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant