2

I would like to check if the following method is called with the correct list of errors.

void ShowErrorCollection(string description, List<string> errors);

My configuration of fake it easy looks like this, I am trying to save the given list to a lokal field:

 A.CallTo(() => dataPresenter.ShowErrorCollection(A<string>.Ignored, A<List<string>>.Ignored))
    .Invokes((string _, List<string> givenErrors) => this.errors = givenErrors);

That does not work. The errors collection is allways null and I don't get the collection. What am I doing wrong?

Edit:

Well it seems to be a bug in my code. I wrote following test and it's green:

[Test]
public void name()
{
    var errorHandler = A.Fake<IErrorHandler>();
    A.CallTo(() => errorHandler.ShowErrorCollection(A<string>.Ignored, A<List<string>>.Ignored))
        .Invokes((string _, List<string> givenErrors) => this.errors = givenErrors);

    errorHandler.ShowErrorCollection("bla", new List<string>() {"Hallo"});

    this.errors.Should().NotBeEmpty();
    this.errors.First().Should().Be("Hallo");
}
Alex
  • 37,502
  • 51
  • 204
  • 332
HerrLoesch
  • 1,023
  • 1
  • 13
  • 24

1 Answers1

0

Had the same issue, It seems to be an order of execution thing.

Invokes does not support OOO, Which means you need to stick to AAA for it to really work.

Arrange: configure fake with Invokes. Act: trigger whatever CallTo was evaluating.

Eyal Perry
  • 2,255
  • 18
  • 26