ssannandeji / Zenject-2019

Dependency Injection Framework for Unity3D
MIT License
2.53k stars 363 forks source link

Integration test to check if signal was fired #564

Closed cpetry closed 5 years ago

cpetry commented 5 years ago

Hi there,

is there a possibility to check if a signal was fired in an integration test?
Best would be to yield until it was fired (of course with timeout).

With the new signal concept I need to use the SignalBusInstaller and declare signals like this:

SignalBusInstaller.Install(Container);
Container.DeclareSignal<Signal_ShowDialog>();

With mocks from normal classes I can assert if functions were called.
Is it possible to mock signals and check these mocks?

cooloon commented 5 years ago

How abount like this:

var isFired = false;
Container.BindSignal<Signal_ShowDialog >().ToMethod(s =>
{
    isFired = true;
    var isValid = s.someValue > 0;
    Assert.IsTrue(isValid, "Signal is fired and validated");
});
cpetry commented 5 years ago

Great!
I added this

yield return new WaitUntil(() => fired);

with a timeout attribute. Seems to work fine!

cooloon commented 5 years ago

You've got my point!