From b8c68576dbd279d06cbdc5142b2ab190bfe5130d Mon Sep 17 00:00:00 2001 From: stakx Date: Sun, 19 Aug 2018 18:21:58 +0200 Subject: [PATCH] Add tests re: `Verify()` and `VerifyNoOtherCalls` 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: https://github.com/moq/moq4/issues/607 --- tests/Moq.Tests/VerifyFixture.cs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/Moq.Tests/VerifyFixture.cs b/tests/Moq.Tests/VerifyFixture.cs index c654af48f..daabc1aab 100644 --- a/tests/Moq.Tests/VerifyFixture.cs +++ b/tests/Moq.Tests/VerifyFixture.cs @@ -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(); + 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(); + 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; } @@ -1355,6 +1382,11 @@ public interface IHaveMethodsNamedLikeEventAccessors void add_Something(); void remove_Something(); } + + public interface ICat + { + string Purr(int amount); + } } }