diff --git a/src/Moq/IInvocation.cs b/src/Moq/IInvocation.cs index 50d31c2b7..f58751fb8 100644 --- a/src/Moq/IInvocation.cs +++ b/src/Moq/IInvocation.cs @@ -29,6 +29,6 @@ public interface IInvocation /// /// Gets whether this invocation was successfully verified by any of the various `Verify` methods. /// - bool WasVerified { get; } + bool IsVerified { get; } } } \ No newline at end of file diff --git a/src/Moq/ISetup.cs b/src/Moq/ISetup.cs index d138c51ec..c4256ebe8 100644 --- a/src/Moq/ISetup.cs +++ b/src/Moq/ISetup.cs @@ -40,6 +40,11 @@ public interface ISetup /// bool IsConditional { get; } + /// + /// Gets whether this setup was matched by at least one invocation on the mock. + /// + bool IsMatched { get; } + /// /// Gets whether this setup has been overridden /// (that is, whether it is being shadowed by a more recent non-conditional setup with an equal expression). @@ -89,11 +94,6 @@ public interface ISetup /// Expression OriginalExpression { get; } - /// - /// Gets whether this setup was matched by at least one invocation on the mock. - /// - bool WasMatched { get; } - /// /// Verifies this setup and optionally all verifiable setups of its inner mock (if present and known). /// diff --git a/src/Moq/Invocation.cs b/src/Moq/Invocation.cs index 73f4750ef..c204857dc 100644 --- a/src/Moq/Invocation.cs +++ b/src/Moq/Invocation.cs @@ -71,7 +71,7 @@ public MethodInfo MethodImplementation public object ReturnValue => this.returnValue; - public bool WasVerified => this.verified; + public bool IsVerified => this.verified; /// /// Ends the invocation as if a statement occurred. diff --git a/src/Moq/Mock.cs b/src/Moq/Mock.cs index 21fec7288..cec7f1e6a 100644 --- a/src/Moq/Mock.cs +++ b/src/Moq/Mock.cs @@ -398,7 +398,7 @@ private static void VerifyNoOtherCalls(Mock mock, HashSet verifiedMocks) { if (!verifiedMocks.Add(mock)) return; - var unverifiedInvocations = mock.MutableInvocations.ToArray(invocation => !invocation.WasVerified); + var unverifiedInvocations = mock.MutableInvocations.ToArray(invocation => !invocation.IsVerified); var innerMockSetups = mock.MutableSetups.GetInnerMockSetups(); diff --git a/src/Moq/Setup.cs b/src/Moq/Setup.cs index 785b3e4e7..f1f8d9765 100644 --- a/src/Moq/Setup.cs +++ b/src/Moq/Setup.cs @@ -49,7 +49,7 @@ protected Setup(Expression originalExpression, Mock mock, InvocationShape expect public Expression OriginalExpression => this.originalExpression; - public bool WasMatched => (this.flags & Flags.Matched) != 0; + public bool IsMatched => (this.flags & Flags.Matched) != 0; public void Execute(Invocation invocation) { @@ -159,7 +159,7 @@ public bool TryVerify(bool recursive, Func predicate, out MockExce protected virtual bool TryVerifySelf(out MockException error) { - error = this.WasMatched ? null : MockException.UnmatchedSetup(this); + error = this.IsMatched ? null : MockException.UnmatchedSetup(this); return error == null; } diff --git a/tests/Moq.Tests/SetupFixture.cs b/tests/Moq.Tests/SetupFixture.cs index 73ae39c88..e32231510 100644 --- a/tests/Moq.Tests/SetupFixture.cs +++ b/tests/Moq.Tests/SetupFixture.cs @@ -20,11 +20,11 @@ public void IsMatched_becomes_true_as_soon_as_a_matching_invocation_is_made() mock.Setup(m => m.ToString()); var setup = mock.Setups.First(); - Assert.False(setup.WasMatched); + Assert.False(setup.IsMatched); _ = mock.Object.ToString(); - Assert.True(setup.WasMatched); + Assert.True(setup.IsMatched); } [Fact] @@ -36,7 +36,7 @@ public void IsMatched_of_setup_implicitly_created_by_SetupAllProperties_becomes_ _ = mock.Object.Property; var setup = mock.Setups.First(); - Assert.True(setup.WasMatched); + Assert.True(setup.IsMatched); } [Fact] @@ -46,11 +46,11 @@ public void IsMatched_of_setup_implicitly_created_by_multi_dot_expression_become mock.Setup(m => m.Inner.Property); var setup = mock.Setups.First(); - Assert.False(setup.WasMatched); + Assert.False(setup.IsMatched); _ = mock.Object.Inner; - Assert.True(setup.WasMatched); + Assert.True(setup.IsMatched); } [Fact] @@ -316,7 +316,7 @@ public void Verify_fails_on_unmatched_setup_even_when_not_flagged_as_verifiable( var setup = mock.Setups.First(); Assert.False(setup.IsVerifiable); // the root setup should be verified despite this - Assert.False(setup.WasMatched); + Assert.False(setup.IsMatched); Assert.Throws(() => setup.Verify()); } @@ -330,7 +330,7 @@ public void Verify_succeeds_on_matched_setup() _ = mock.Object.ToString(); Assert.False(setup.IsVerifiable); - Assert.True(setup.WasMatched); + Assert.True(setup.IsMatched); setup.Verify(); } @@ -344,9 +344,9 @@ public void Verify_fails_on_matched_setup_having_unmatched_verifiable_setup_on_i var innerMock = mock.Object.Inner; var innerMockSetup = Mock.Get(innerMock).Setups.First(); - Assert.True(setup.WasMatched); + Assert.True(setup.IsMatched); Assert.True(innerMockSetup.IsVerifiable); - Assert.False(innerMockSetup.WasMatched); // this should make recursive verification fail + Assert.False(innerMockSetup.IsMatched); // this should make recursive verification fail Assert.Throws(() => setup.Verify()); } @@ -360,9 +360,9 @@ public void Verify_succeeds_on_matched_setup_having_unmatched_setup_on_inner_moc var innerMock = mock.Object.Inner; var innerMockSetup = Mock.Get(innerMock).Setups.First(); - Assert.True(setup.WasMatched); + Assert.True(setup.IsMatched); Assert.False(innerMockSetup.IsVerifiable); // which means that the inner mock setup will be ignored - Assert.False(innerMockSetup.WasMatched); // this would make verification fail if that setup were not ignored + Assert.False(innerMockSetup.IsMatched); // this would make verification fail if that setup were not ignored setup.Verify(); } @@ -376,9 +376,9 @@ public void Verify_succeeds_on_matched_setup_having_unmatched_verifiable_setup_o var innerMock = mock.Object.Inner; var innerMockSetup = Mock.Get(innerMock).Setups.First(); - Assert.True(setup.WasMatched); + Assert.True(setup.IsMatched); Assert.True(innerMockSetup.IsVerifiable); - Assert.False(innerMockSetup.WasMatched); + Assert.False(innerMockSetup.IsMatched); setup.Verify(recursive: false); // which means that verification will never get to `innerMockSetup` } @@ -392,8 +392,8 @@ public void VerifyAll_is_always_recursive() var innerMock = mock.Object.Inner; var innerMockSetup = Mock.Get(innerMock).Setups.First(); - Assert.True(setup.WasMatched); - Assert.False(innerMockSetup.WasMatched); // this will make verification fail only if it is recursive + Assert.True(setup.IsMatched); + Assert.False(innerMockSetup.IsMatched); // this will make verification fail only if it is recursive Assert.Throws(() => setup.VerifyAll()); } @@ -407,7 +407,7 @@ public void VerifyAll_includes_non_verifiable_setups() var innerMock = mock.Object.Inner; var innerMockSetup = Mock.Get(innerMock).Setups.First(); - Assert.True(setup.WasMatched); + Assert.True(setup.IsMatched); Assert.False(innerMockSetup.IsVerifiable); // this should not exclude the inner mock setup from verification Assert.Throws(() => setup.VerifyAll()); } @@ -422,11 +422,11 @@ public void Verify_marks_invocations_matched_by_setup_as_verified() _ = mock.Object.ToString(); _ = mock.Object.ToString(); - Assert.All(mock.Invocations, i => Assert.False(i.WasVerified)); + Assert.All(mock.Invocations, i => Assert.False(i.IsVerified)); setup.Verify(); - Assert.All(mock.Invocations, i => Assert.True(i.WasVerified)); + Assert.All(mock.Invocations, i => Assert.True(i.IsVerified)); mock.VerifyNoOtherCalls(); } @@ -440,11 +440,11 @@ public void VerifyAll_marks_invocations_matched_by_setup_as_verified() _ = mock.Object.ToString(); _ = mock.Object.ToString(); - Assert.All(mock.Invocations, i => Assert.False(i.WasVerified)); + Assert.All(mock.Invocations, i => Assert.False(i.IsVerified)); setup.VerifyAll(); - Assert.All(mock.Invocations, i => Assert.True(i.WasVerified)); + Assert.All(mock.Invocations, i => Assert.True(i.IsVerified)); mock.VerifyNoOtherCalls(); } @@ -459,11 +459,11 @@ public void Verify_marks_invocation_matched_by_verifiable_inner_mock_setup_as_ve _ = innerMock.Property; var innerMockInvocation = Mock.Get(innerMock).Invocations.First(); - Assert.False(innerMockInvocation.WasVerified); + Assert.False(innerMockInvocation.IsVerified); setup.Verify(); - Assert.True(innerMockInvocation.WasVerified); + Assert.True(innerMockInvocation.IsVerified); mock.VerifyNoOtherCalls(); } @@ -478,11 +478,11 @@ public void VerifyAll_marks_invocation_matched_by_inner_mock_setup_as_verified() _ = innerMock.Property; var innerMockInvocation = Mock.Get(innerMock).Invocations.First(); - Assert.False(innerMockInvocation.WasVerified); + Assert.False(innerMockInvocation.IsVerified); setup.VerifyAll(); - Assert.True(innerMockInvocation.WasVerified); + Assert.True(innerMockInvocation.IsVerified); mock.VerifyNoOtherCalls(); } diff --git a/tests/Moq.Tests/VerifyFixture.cs b/tests/Moq.Tests/VerifyFixture.cs index ef6f9f9d4..b9dee4deb 100644 --- a/tests/Moq.Tests/VerifyFixture.cs +++ b/tests/Moq.Tests/VerifyFixture.cs @@ -1116,10 +1116,10 @@ public void Verify_if_successful_marks_matched_invocation_as_verified() mock.Object.Submit(); var invocation = mock.MutableInvocations.ToArray()[0]; - Assert.False(invocation.WasVerified); + Assert.False(invocation.IsVerified); mock.Verify(m => m.Submit()); - Assert.True(invocation.WasVerified); + Assert.True(invocation.IsVerified); } [Fact] @@ -1131,14 +1131,14 @@ public void Verify_if_successful_marks_only_matched_invocations_as_verified() mock.Object.Echo(3); var invocations = mock.MutableInvocations.ToArray(); - Assert.False(invocations[0].WasVerified); - Assert.False(invocations[1].WasVerified); - Assert.False(invocations[2].WasVerified); + Assert.False(invocations[0].IsVerified); + Assert.False(invocations[1].IsVerified); + Assert.False(invocations[2].IsVerified); mock.Verify(m => m.Echo(It.Is(i => i != 2))); - Assert.True(invocations[0].WasVerified); - Assert.False(invocations[1].WasVerified); - Assert.True(invocations[2].WasVerified); + Assert.True(invocations[0].IsVerified); + Assert.False(invocations[1].IsVerified); + Assert.True(invocations[2].IsVerified); } [Fact] @@ -1150,14 +1150,14 @@ public void Verify_if_unsuccessful_marks_no_matched_invocations_as_verified() mock.Object.Echo(3); var invocations = mock.MutableInvocations.ToArray(); - Assert.False(invocations[0].WasVerified); - Assert.False(invocations[1].WasVerified); - Assert.False(invocations[2].WasVerified); + Assert.False(invocations[0].IsVerified); + Assert.False(invocations[1].IsVerified); + Assert.False(invocations[2].IsVerified); Assert.Throws(() => mock.Verify(m => m.Echo(It.Is(i => i != 2)), Times.Exactly(1))); - Assert.False(invocations[0].WasVerified); - Assert.False(invocations[1].WasVerified); - Assert.False(invocations[2].WasVerified); + Assert.False(invocations[0].IsVerified); + Assert.False(invocations[1].IsVerified); + Assert.False(invocations[2].IsVerified); } [Fact]