1

Using FakeItEasy, I have a setup similar to the one below in one of my tests, and the CallTo assertion at the bottom is failing when setup like this.

var fakedTool = A.Fake<ITool>();

var concreteUnderTest = new Concrete(fakedTool);

concreteUnderTest.doSomething();

var fooConstraint = A<Foo>.That.Matches(f => f.Name.Equals('Alice'));
var barConstraint = A<Bar>.Ignored;

A.CallTo(() => fakedTool.ObservedFunction(fooConstraint , barConstraint))
    .MustHaveHappened(Repeated.Exactly.Once);

I have placed a breakpoint directly above the CallTo line, and the values of fooConstraint and barConstraint are both null.

When I set the assertion up like this, however, it passes:

A.CallTo(() =>
    fakedTool.ObservedFunction(
        A<Foo>.That.Matches(f => f.Name.Equals('Alice')),
        A<Bar>.Ignored
    )
).MustHaveHappened(Repeated.Exactly.Once);

What is causing this behaviour? Is it intended?

James Monger
  • 10,181
  • 7
  • 62
  • 98

1 Answers1

1

This is intended behaviour. You can see the section Always place Ignored and That inside A.CallTo in the docs.

As of FakeItEasy 2.0.0, FakeItEasy will throw an exception when they're stored as variables and invoked, rather than failing quietly by being null.

Blair Conrad
  • 233,004
  • 25
  • 132
  • 111
James Monger
  • 10,181
  • 7
  • 62
  • 98