8000 `Verify` exception should include complete call expression for delegate mocks by stakx · Pull Request #680 · devlooped/moq · GitHub
[go: up one dir, main page]

Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The format is loosely based on [Keep a Changelog](http://keepachangelog.com/en/1
* More precise `out` parameter detection for mocking COM interfaces with `[in,out]` parameters (@koutinho, #645)
* Prevent false 'Different number of parameters' error with `Returns` callback methods that have been compiled from `Expression`s (@stakx, #654)
* `Verify` exception should report configured setups for delegate mocks (@stakx, #679)
* `Verify` exception should include complete call expression for delegate mocks (@stakx, #680)


## 4.9.0 (2018-07-13)
Expand Down
3 changes: 3 additions & 0 deletions src/Moq/ExpressionStringBuilder.cs
8000
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,10 @@ private void AsCommaSeparatedValues<T>(IEnumerable<T> source, Action<T> toString

private void ToStringInvocation(InvocationExpression iv)
{
ToString(iv.Expression);
builder.Append('(');
ToStringExpressionList(iv.Arguments);
builder.Append(')');
return;
}

Expand Down
36 changes: 35 additions & 1 deletion tests/Moq.Tests/VerifyFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1397,7 +1397,41 @@ public void Verification_error_message_contains_setup_for_delegate_mock()
var ex = Record.Exception(() => mock.Verify(m => m(), Times.Once()));

Assert.Contains("Configured setups:", ex.Message);
Assert.Contains("Action m =>", ex.Message);
Assert.Contains("Action m => m()", ex.Message);
}

[Fact]
public void Verification_error_message_contains_setup_for_delegate_mock_with_parameters()
{
var mock = new Mock<Action<int, int>>();
mock.Setup(m => m(1, It.IsAny<int>()));

var ex = Record.Exception(() => mock.Verify(m => m(1, 2), Times.Once()));

Assert.Contains("Configured setups:", ex.Message);
Assert.Contains("Action<Int32, Int32> m => m(1, It.IsAny<Int32>())", ex.Message);
}

[Fact]
public void Verification_error_message_contains_complete_call_expression_for_delegate_mock()
6FE8 {
var mock = new Mock<Action>();
mock.Setup(m => m());

var ex = Record.Exception(() => mock.Verify(m => m(), Times.Once()));

Assert.Contains("but was 0 times: m => m()", ex.Message);
}

[Fact]
public void Verification_error_message_contains_complete_call_expression_for_delegate_mock_with_parameters()
{
var mock = new Mock<Action<int, int>>();
mock.Setup(m => m(1, It.IsAny<int>()));

var ex = Record.Exception(() => mock.Verify(m => m(1, 2), Times.Once()));

Assert.Contains("but was 0 times: m => m(1, 2)", ex.Message);
}

public interface IBar
Expand Down
0