Skip to content

Commit

Permalink
Replace IInvocation.WasMatched w/ MatchingSetup property
Browse files Browse the repository at this point in the history
  • Loading branch information
stakx committed Apr 14, 2020
1 parent b6ecba4 commit 0ab5342
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 28 deletions.
13 changes: 2 additions & 11 deletions src/Moq/IInvocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,9 @@ public interface IInvocation
IReadOnlyList<object> Arguments { get; }

/// <summary>
/// Gets whether this invocation was matched by a setup.
/// If so, the matching setup is returned via the <see langword="out"/> parameter <paramref name="matchingSetup"/>.
/// Gets the setup that matched this invocation (or <see langword="null"/> if there was no matching setup).
/// </summary>
/// <param name="matchingSetup">
/// If this invocation was matched by a setup,
/// this <see langword="out"/> parameter will be set to the matching setup.
/// </param>
/// <returns>
/// <see langword="true"/> if this invocation was matched by a setup;
/// otherwise, <see langword="false"/>.
/// </returns>
bool WasMatched(out ISetup matchingSetup);
ISetup MatchingSetup { get; }

/// <summary>
/// Gets whether this invocation was successfully verified by any of the various <c>`Verify`</c> methods.
Expand Down
7 changes: 2 additions & 5 deletions src/Moq/Invocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public MethodInfo MethodImplementation

IReadOnlyList<object> IInvocation.Arguments => this.arguments;

public ISetup MatchingSetup => this.matchingSetup;

public Type ProxyType => this.proxyType;

public object ReturnValue => this.returnValue;
Expand Down Expand Up @@ -171,10 +173,5 @@ public override string ToString()

return builder.ToString();
}

public bool WasMatched(out ISetup matchingSetup)
{
return (matchingSetup = this.matchingSetup) != null;
}
}
}
20 changes: 8 additions & 12 deletions tests/Moq.Tests/InvocationsFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,19 +205,18 @@ public void Mock_Of_should_keep_record_of_invocations_caused_by_mocked_type_ctor
}

[Fact]
public void WasMatched_returns_false_if_there_was_no_matching_setup()
public void MatchingSetup_is_null_if_there_was_no_matching_setup()
{
var mock = new Mock<IX>();

mock.Object.Do();
var invocation = mock.Invocations.First();

Assert.False(invocation.WasMatched(out var matchingSetup));
Assert.Null(matchingSetup);
Assert.Null(invocation.MatchingSetup);
}

[Fact]
public void WasMatched_returns_true_if_there_was_a_matching_setup()
public void MatchingSetup_is_set_if_there_was_a_matching_setup()
{
var mock = new Mock<IX>();
mock.Setup(m => m.Do());
Expand All @@ -226,12 +225,11 @@ public void WasMatched_returns_true_if_there_was_a_matching_setup()
mock.Object.Do();
var invocation = mock.Invocations.First();

Assert.True(invocation.WasMatched(out var matchingSetup));
Assert.Same(setup, matchingSetup);
Assert.Same(setup, invocation.MatchingSetup);
}

[Fact]
public void WasMatched_returns_true_if_there_was_a_matching_setup_implicitly_created_by_SetupAllProperties()
public void MatchingSetup_is_set_if_there_was_a_matching_setup_implicitly_created_by_SetupAllProperties()
{
var mock = new Mock<IX>();
mock.SetupAllProperties();
Expand All @@ -240,12 +238,11 @@ public void WasMatched_returns_true_if_there_was_a_matching_setup_implicitly_cre
var invocation = mock.Invocations.First();
var setup = mock.Setups.First();

Assert.True(invocation.WasMatched(out var matchingSetup));
Assert.Same(setup, matchingSetup);
Assert.Same(setup, invocation.MatchingSetup);
}

[Fact]
public void WasMatched_returns_true_if_there_was_a_matching_setup_implicitly_created_by_multi_dot_expression()
public void MatchingSetup_is_set_if_there_was_a_matching_setup_implicitly_created_by_multi_dot_expression()
{
var mock = new Mock<IX>();
mock.Setup(m => m.Nested.Do());
Expand All @@ -254,8 +251,7 @@ public void WasMatched_returns_true_if_there_was_a_matching_setup_implicitly_cre
_ = mock.Object.Nested;
var invocation = mock.Invocations.First();

Assert.True(invocation.WasMatched(out var matchingSetup));
Assert.Same(setup, matchingSetup);
Assert.Same(setup, invocation.MatchingSetup);
}

public interface IX
Expand Down

0 comments on commit 0ab5342

Please sign in to comment.