Skip to content

Commit

Permalink
Add test for lamba matcher variables
Browse files Browse the repository at this point in the history
  • Loading branch information
bfriesen committed Feb 1, 2021
1 parent 653db31 commit 5b10a8c
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/Moq.Tests/VerifyFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// All rights reserved. Licensed under the BSD 3-Clause License; see License.txt.

using System;
using System.Linq.Expressions;
using System.Threading.Tasks;

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

[Fact]
public void ThrowsWithExpressionIfVerifiableExpectationWithLambdaMatcherVariableNotCalled()
{
var mock = new Mock<IFoo>();

Expression<Func<string, bool>> nullOrEmpty = s => string.IsNullOrEmpty(s);

mock.Setup(x => x.Execute(It.Is(nullOrEmpty)))
.Returns("ack")
.Verifiable();

var mex = Assert.Throws<MockException>(() => mock.Verify());
Assert.True(mex.IsVerificationError);
Assert.Contains(@".Execute(It.Is<string>(s => string.IsNullOrEmpty(s)))", mex.Message);
}

[Fact]
public void VerifiesNoOpIfNoVerifiableExpectations()
{
Expand Down

0 comments on commit 5b10a8c

Please sign in to comment.