Skip to content

If When(Func<bool> condition) is used to setup a mock, the setup verification is skipped. #959

@FranceyD

Description

@FranceyD

It is possible to use Verifiable() on a conditional setup (I mean a setup with When preceding the setup method), but the Verify() method doesn't actually verify it.

Example:

var mock = new Mock<ICloneable>();
mock.When(() => true)
	.Setup(o => o.Clone())
	.Verifiable();
mock.Verify(); // No exception
	
mock.Setup(o => o.Clone())
	.Verifiable();
mock.Verify(); // MockException, setup was not matched.

As I have seen in the source code, it looks like the method SetupCollection.ToArrayLive ignores all setups with a condition.

For me, it would be convenient that the Verify method verifies also the setup if the condition is valid during the verification.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions