public void ThrowNotifyExceptionTest() { var hlp = new Helpers.EventProviderProxy(); using (var ep = new EventProvider(hlp)) { var e = Helpers.GetTestEventsNames(); var testEx = Helpers.GetTestException(); EvntHandler ehp = (sender, evName, args) => { throw Helpers.GetTestException(); }; ep.ListenEvent(hlp, ehp, e[0]); ep.NotifyEvent(e[0]); } }
public void OneBindingUnlistenEvent() { var hlp = new Helpers.EventProviderProxy(); using (var ep = new EventProvider(hlp)) { var e = Helpers.GetTestEventsNames(); int cntCalls = e.Length; EvntHandler ehp = (sender, evName, args) => cntCalls-- > int.MinValue; for (int i = 0; i < cntCalls; i++) ep.ListenEvent(hlp, ehp, e[0]); ep.UnlistenEvent(hlp, ehp, e[0]); ep.NotifyEvent(e[0]); Assert.IsTrue(cntCalls == 1, "Ошибка логики привязки/вызова событий"); } }
public void DettachObjectTest() { var hlp = new Helpers.EventProviderProxy(); using (var ep = new EventProvider(hlp)) { var e = Helpers.GetTestEventsNames(); int cntCalls = 0; EvntHandler ehp = (sender, evName, args) => cntCalls-- > int.MinValue; foreach (var item in e) ep.ListenEvent(hlp, ehp, item); ep.ListenEvent(hlp, ehp, e[0]); ep.DettachObject(hlp); foreach (var item in e) ep.NotifyEvent(item); ep.NotifyEvent(e[0]); Assert.IsTrue(cntCalls == 0, "Ошибка логики привязки событий"); } }
public void BindingListenEvent() { var hlp = new Helpers.EventProviderProxy(); using (var ep = new EventProvider(hlp)) { var e = Helpers.GetTestEventsNames(); var e1 = e.ToList(); int cntCalls = e.Length; EvntHandler ehp = (sender, evName, args) => e1.Remove(evName) && cntCalls-- > int.MinValue; foreach (var item in e) ep.ListenEvent(hlp, ehp, item); foreach (var item in e) ep.NotifyEvent(item); Assert.IsTrue(cntCalls == 0, "Ошибка логики привязки/вызова событий"); } }