public void Integration_OnFailWithRetry_Succeeds() { int firstCall = 0; int secondCall = 0; Delegate <TestEvent> firstHandler = (p) => { firstCall++; if (firstCall < 3) { throw new InvalidOperationException(); } }; FailDelegate <TestEvent> secondHandler = (p, e) => { secondCall++; }; EventBus.Subscribe <TestEvent>( firstHandler // try and call secondHandler if failed .AddOnFail <TestEvent, Exception>(secondHandler, OnException.ThrowException) // and retry this up to 5 times .Retry <TestEvent, Exception>(5) ); EventBus.Publish(new TestEvent(), this); Assert.AreEqual(3, firstCall); Assert.AreEqual(2, secondCall); }
public void OnFail_ExceptionDoNotMatch_ThrowsException() { bool secondCall = false; Delegate <TestEvent> firstHandler = (p) => { throw new InvalidOperationException(); }; FailDelegate <TestEvent> secondHandler = (p, e) => { secondCall = true; }; EventBus.Subscribe <TestEvent>( firstHandler.AddOnFail <TestEvent, ArgumentException>(secondHandler) ); EventBus.Publish(new TestEvent(), this); Assert.IsFalse(secondCall); }
public void OnFail_MatchingException_OnFailCalled() { bool secondCall = false; bool exceptionPublished = false; Delegate <TestEvent> firstHandler = (p) => { throw new InvalidOperationException(); }; FailDelegate <TestEvent> secondHandler = (p, e) => { secondCall = true; }; EventBus.Subscribe <TestEvent>(firstHandler.AddOnFail <TestEvent, Exception>(secondHandler, OnException.PublishExceptionToDefaultEventBus)); EventBus.Subscribe <Exception>((param) => { exceptionPublished = true; }); EventBus.Publish(new TestEvent(), this); Assert.IsTrue(secondCall); Assert.IsTrue(exceptionPublished); }
public void OnFail_ExceptionMatchButNotReThrown_HappyCase() { bool secondCall = false; bool exceptionPublished = false; Delegate <TestEvent> firstHandler = (p) => { throw new InvalidOperationException(); }; FailDelegate <TestEvent> secondHandler = (p, e) => { secondCall = true; }; EventBus.Subscribe <TestEvent>( firstHandler.AddOnFail <TestEvent, Exception>(secondHandler) ); EventBus.Subscribe <Exception>((param) => { exceptionPublished = true; }); EventBus.Publish(new TestEvent(), this); Assert.IsTrue(secondCall); Assert.IsFalse(exceptionPublished); }