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

Uninvoke InnerMockSetup on mock.Invocations.Clear() #899

Merged
merged 2 commits into from
Aug 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Moq/InnerMockSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,13 @@ public override MockException TryVerifyAll()
{
return this.TryVerifyInnerMock(innerMock => innerMock.TryVerifyAll());
}

public override void Uninvoke()
{
if (this.ReturnsInnerMock(out var innerMock))
{
innerMock.Setups.UninvokeAll();
}
}
}
}
19 changes: 19 additions & 0 deletions tests/Moq.Tests/InvocationsFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,19 @@ public void Invocations_Clear_also_resets_setup_verification_state_of_sequence_s
Assert.Equal(MockExceptionReasons.UnmatchedSetup, ex.Reasons);
}

[Fact]
public void Invocations_Clear_also_resets_setup_verification_state_of_inner_mock_setups()
{
var mock = new Mock<IX>();
mock.Setup(m => m.Nested.Do());
mock.Object.Nested.Do();
mock.VerifyAll(); // ensure setup has been matched

mock.Invocations.Clear();
var ex = Assert.Throws<MockException>(() => mock.VerifyAll());
Assert.Equal(MockExceptionReasons.UnmatchedSetup, ex.Reasons);
}

[Fact]
[Obsolete()]
public void Invocations_Clear_resets_count_kept_by_setup_AtMost()
Expand All @@ -168,5 +181,11 @@ public void Invocations_Clear_resets_count_kept_by_setup_AtMost()
var ex = Assert.Throws<MockException>(() => mock.Object.CompareTo(default));
Assert.Equal(MockExceptionReasons.MoreThanOneCall, ex.Reasons);
}

public interface IX
{
IX Nested { get; }
void Do();
}
}
}