Skip to content

Commit

Permalink
Rename Was... properties to Is...
Browse files Browse the repository at this point in the history
to better reflect that even though the 'matched' or 'verified' status
was set in the past, it is still subject to change. (For example, the
'matched' status of setups gets reset on `mock.Invocations.Clear()`.)
  • Loading branch information
stakx committed Apr 24, 2020
1 parent 4586f77 commit b544e19
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/Moq/IInvocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ public interface IInvocation
/// <summary>
/// Gets whether this invocation was successfully verified by any of the various <c>`Verify`</c> methods.
/// </summary>
bool WasVerified { get; }
bool IsVerified { get; }
}
}
10 changes: 5 additions & 5 deletions src/Moq/ISetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public interface ISetup
/// <seealso cref="Mock{T}.When(Func{bool})"/>
bool IsConditional { get; }

/// <summary>
/// Gets whether this setup was matched by at least one invocation on the mock.
/// </summary>
bool IsMatched { get; }

/// <summary>
/// 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).
Expand Down Expand Up @@ -89,11 +94,6 @@ public interface ISetup
/// </summary>
Expression OriginalExpression { get; }

/// <summary>
/// Gets whether this setup was matched by at least one invocation on the mock.
/// </summary>
bool WasMatched { get; }

/// <summary>
/// Verifies this setup and optionally all verifiable setups of its inner mock (if present and known).
/// <para>
Expand Down
2 changes: 1 addition & 1 deletion src/Moq/Invocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public MethodInfo MethodImplementation

public object ReturnValue => this.returnValue;

public bool WasVerified => this.verified;
public bool IsVerified => this.verified;

/// <summary>
/// Ends the invocation as if a <see langword="return"/> statement occurred.
Expand Down
2 changes: 1 addition & 1 deletion src/Moq/Mock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ private static void VerifyNoOtherCalls(Mock mock, HashSet<Mock> 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();

Expand Down
4 changes: 2 additions & 2 deletions src/Moq/Setup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -159,7 +159,7 @@ public bool TryVerify(bool recursive, Func<ISetup, bool> 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;
}

Expand Down
48 changes: 24 additions & 24 deletions tests/Moq.Tests/SetupFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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<MockException>(() => setup.Verify());
}

Expand All @@ -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();
}

Expand All @@ -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<MockException>(() => setup.Verify());
}

Expand All @@ -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();
}

Expand All @@ -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`
}

Expand All @@ -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<MockException>(() => setup.VerifyAll());
}

Expand All @@ -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<MockException>(() => setup.VerifyAll());
}
Expand All @@ -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();
}

Expand All @@ -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();
}

Expand All @@ -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();
}

Expand All @@ -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();
}

Expand Down
28 changes: 14 additions & 14 deletions tests/Moq.Tests/VerifyFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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<int>(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]
Expand All @@ -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<MockException>(() => mock.Verify(m => m.Echo(It.Is<int>(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]
Expand Down

0 comments on commit b544e19

Please sign in to comment.