how to It.IsAny<T> in FakeItEasy?
Asked Answered
H

1

7

Does anyone know the equivalent of Moq It.IsAny<T> in FakeItEasy ?

I want to do assert that a method was called with an instance of a Type

v.Do(new Foo());

I tried:

A.CallTo(() => v.Do(A<Foo>.Ignored)).MustHaveHappened();

but this also accepts v.Do();

Howlend answered 10/12, 2010 at 14:19 Comment(0)
A
13

You're right in the A<Foo>.Ignored (or A<Foo>._) is the equivalent of It.IsAny<Foo> in Moq.

It seems that you've hit a bug if what you say is actually correct. I'll get on it as soon as possible.

EDIT I created the following integration test to reproduced the bug but the test passes so I'm not able to reproduce it, could you provide a code sample?

[Test]
public void Should_fail_assertion_when_overload_with_no_parameters_has_been_called_but_the_assertion_is_for_overload_with_parameters_but_ignoring_them()
{
    // Arrange
    var fake = A.Fake<ITypeWithOverloadedMethods>();

    // Act
    fake.Foo();

    // Assert
    Assert.Throws<ExpectationException>(() => A.CallTo(() => fake.Foo(A<int>._)).MustHaveHappened());
}

public interface ITypeWithOverloadedMethods
{
    void Foo();
    void Foo(int argument);
}
Adhesive answered 11/12, 2010 at 22:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.