Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to It.IsAny<T> in FakeItEasy?

Tags:

moq

fakeiteasy

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();

like image 305
Omu Avatar asked Dec 10 '10 14:12

Omu


1 Answers

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);
}
like image 148
Patrik Hägne Avatar answered Nov 06 '22 06:11

Patrik Hägne