I'm trying to test a method and verify whether another method was called or not. This depends on a bool value. If it's true, the other method should be called. Still, the assertion occasionally works because the true scenario might run before the false scenario, and xUnit counts the call that happens there.
[Theory]
[InlineData(false)]
[InlineData(true)]
public async Task Test_Resync(bool shouldUpdate)
{
...
await Resync().ConfigureAwait(false);
if (shouldUpdate)
{
A.CallTo(() => mock.AnyMethod()).MustHaveHappened();
return;
}
A.CallTo(() => mock.AnyMethod()).MustNotHaveHappened();
}
Although I can use MustHaveHappenedOnceOrLess as a workaround, I think this is not reflecting the behavior expected, so my doubt is: is there a way to have independent cases when using Theory? Would it be better to separate both scenarios?