Skip to content

Commit

Permalink
Add tests re: Verify() and VerifyNoOtherCalls
Browse files Browse the repository at this point in the history
Add two tests that demonstrate how `VerifyNoOtherCalls` ought to
interact with both parameterless and parameterized `Verify` methods.

Currently, `VerifyNoOtherCalls` only works together with parameterized
`Verify`, but not with the parameterless variant (which internally is
actually very different as it targets setups, not invocations).

These tests are taken from:
devlooped#607
  • Loading branch information
stakx committed Aug 19, 2018
1 parent b8b61a4 commit b8c6857
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/Moq.Tests/VerifyFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,33 @@ public void VerifyNoOtherCalls_can_tell_apart_transitive_and_nontransitive_usage
// X is non-transitive if there are no invocations on the sub-object that occur later.
}

// (This test is somewhat duplicate, but sets the stage for the test following right after it.)
[Fact]
public void VerifyNoOtherCalls_works_together_with_parameterized_Verify()
{
var cat = new Mock<ICat>();
cat.Setup(x => x.Purr(15)).Returns("happy");

var mood = cat.Object.Purr(15);

cat.Verify(x => x.Purr(15));
Assert.Equal("happy", mood);
cat.VerifyNoOtherCalls();
}

[Fact]
public void VerifyNoOtherCalls_works_together_with_parameterless_Verify()
{
var cat = new Mock<ICat>();
cat.Setup(x => x.Purr(15)).Returns("happy").Verifiable();

var mood = cat.Object.Purr(15);

cat.Verify();
Assert.Equal("happy", mood);
cat.VerifyNoOtherCalls();
}

public interface IBar
{
int? Value { get; set; }
Expand Down Expand Up @@ -1355,6 +1382,11 @@ public interface IHaveMethodsNamedLikeEventAccessors
void add_Something();
void remove_Something();
}

public interface ICat
{
string Purr(int amount);
}
}
}

Expand Down

0 comments on commit b8c6857

Please sign in to comment.