Skip to content

Commit 5b10a8c

Browse files
committed
Add test for lamba matcher variables
1 parent 653db31 commit 5b10a8c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tests/Moq.Tests/VerifyFixture.cs

+17
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.
33

44
using System;
5+
using System.Linq.Expressions;
56
using System.Threading.Tasks;
67

78
using Moq;
@@ -65,6 +66,22 @@ public void ThrowsWithExpressionIfVerifiableExpectationWithLambdaMatcherNotCalle
6566
Assert.Contains(@".Execute(It.Is<string>(s => string.IsNullOrEmpty(s)))", mex.Message);
6667
}
6768

69+
[Fact]
70+
public void ThrowsWithExpressionIfVerifiableExpectationWithLambdaMatcherVariableNotCalled()
71+
{
72+
var mock = new Mock<IFoo>();
73+
74+
Expression<Func<string, bool>> nullOrEmpty = s => string.IsNullOrEmpty(s);
75+
76+
mock.Setup(x => x.Execute(It.Is(nullOrEmpty)))
77+
.Returns("ack")
78+
.Verifiable();
79+
80+
var mex = Assert.Throws<MockException>(() => mock.Verify());
81+
Assert.True(mex.IsVerificationError);
82+
Assert.Contains(@".Execute(It.Is<string>(s => string.IsNullOrEmpty(s)))", mex.Message);
83+
}
84+
6885
[Fact]
6986
public void VerifiesNoOpIfNoVerifiableExpectations()
7087
{

0 commit comments

Comments
 (0)