Faking this is easy with actions - Says it can't find the call but shows it in the list

I use fake easily:

var callBackAction = A.Fake<Action<object>>();

//act
token.RegisterChangeCallback(callBackAction, "hi");

//assert
A.CallTo(() => callBackAction.Invoke(A<object>.Ignored)).MustHaveHappened();

      

and I get the error

    FakeItEasy.ExpectationException : Assertion failed for the following call: 

    System.Action`1[System.Object].Invoke(obj: <Ignored>) Expected to find it 

    exactly once but found it #0 times among the calls: 

          1:     System.Action`1[System.Object].Invoke(obj: "hi)

      

This seems very strange to me. I could figure out if he didn't find something or something to do with overriding equals (), but this is very strange since he obviously found my call and I am using the ignored one, but it doesn't match them. Does it have something to do with using actions?

+3


source to share


1 answer


This was because a thread was spawned that waits for a condition and an action is then called on that thread. Although in the test, this condition is true immediately, so the stream returns very quickly. This is not fast enough for the asset to be right as it happens immediately after the thread is created so that the test will not pass. However, after the assert fails and before FakeItEasy finishes collecting the calls that occurred for the error messages caused by the action. This causes FakeItEasy to show that it was called as part of an error message despite the test failing because it was not called.



This is what I think. Flow diagram

+4


source







All Articles