public void DeregisterAsyncHandler_NullLog_ThrowsArgumentNullException()
        {
            var manager = new OrionEventManager();

            Assert.Throws <ArgumentNullException>(
                () => manager.DeregisterAsyncHandler <TestEvent>(async evt => await Task.Delay(100), null !));
        }
        public void Raise_NullEvt_ThrowsArgumentNullException()
        {
            var manager = new OrionEventManager();
            var log     = Mock.Of <ILogger>();

            Assert.Throws <ArgumentNullException>(() => manager.Raise <TestEvent>(null !, log));
        }
        public void DeregisterAsyncHandler_NullHandler_ThrowsArgumentNullException()
        {
            var manager = new OrionEventManager();
            var log     = Mock.Of <ILogger>();

            Assert.Throws <ArgumentNullException>(() => manager.DeregisterAsyncHandler <TestEvent>(null !, log));
        }
        public void RegisterHandler_Raise_ThrowsException()
        {
            var manager = new OrionEventManager();
            var log     = Mock.Of <ILogger>();

            manager.RegisterHandler <TestEvent>(evt => throw new InvalidOperationException(), log);
            var evt = new TestEvent();

            manager.Raise(evt, Logger.None);
        }
        public void RegisterAsyncHandler_Raise_ThrowsException()
        {
            var manager = new OrionEventManager();
            var log     = Mock.Of <ILogger>();

#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
            manager.RegisterAsyncHandler <TestEvent>(async evt => throw new InvalidOperationException(), log);
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
            var evt = new TestEvent();

            manager.Raise(evt, log);
        }
        public void RegisterHandler_Raise()
        {
            var manager = new OrionEventManager();
            var log     = Mock.Of <ILogger>();

            manager.RegisterHandler <TestEvent>(evt => evt.Value = 100, log);
            var evt = new TestEvent();

            manager.Raise(evt, Logger.None);

            Assert.Equal(100, evt.Value);
        }
        public void RegisterHandler_Raise_EventCanceled()
        {
            var manager = new OrionEventManager();
            var log     = Mock.Of <ILogger>();

            manager.RegisterHandler <TestEvent2>(TestEvent2Handler, log);
            manager.RegisterHandler <TestEvent2>(TestEvent2Handler2, log);
            var evt = new TestEvent2();

            manager.Raise(evt, Logger.None);

            Assert.Equal(0, evt.Value);
        }
        public void RegisterAsyncHandler_Raise_EventCanceled()
        {
            var manager = new OrionEventManager();
            var log     = Mock.Of <ILogger>();

            manager.RegisterHandler <TestEvent2>(TestEvent2Handler, log);
            manager.RegisterAsyncHandler <TestEvent2>(TestEvent2Handler2Async, log);
            var evt = new TestEvent2();

            manager.Raise(evt, Logger.None);

            // HACK: sleep here to ensure that the handler is finished.
            Thread.Sleep(1000);

            Assert.Equal(0, evt.Value);
        }
        public void RegisterAsyncHandler_Raise_ThrowsExceptionAsynchronously()
        {
            var manager = new OrionEventManager();
            var log     = Mock.Of <ILogger>();

            manager.RegisterAsyncHandler <TestEvent>(async evt =>
            {
                await Task.Delay(100);

                throw new InvalidOperationException();
            }, log);
            var evt = new TestEvent();

            manager.Raise(evt, log);

            // HACK: sleep here to ensure that the handler is finished.
            Thread.Sleep(1000);
        }
        public void RegisterAsyncHandler_Raise()
        {
            var manager = new OrionEventManager();
            var log     = Mock.Of <ILogger>();

            manager.RegisterAsyncHandler <TestEvent>(async evt =>
            {
                await Task.Delay(100);

                evt.Value = 100;
            }, log);
            var evt = new TestEvent();

            manager.Raise(evt, Logger.None);

            // HACK: sleep here to ensure that the handler is finished.
            Thread.Sleep(1000);

            Assert.Equal(100, evt.Value);
        }
        public void DeregisterHandler_NullLog_ThrowsArgumentNullException()
        {
            var manager = new OrionEventManager();

            Assert.Throws <ArgumentNullException>(() => manager.DeregisterHandler <TestEvent>(evt => { }, null !));
        }
        public void Raise_NullLog_ThrowsArgumentNullException()
        {
            var manager = new OrionEventManager();

            Assert.Throws <ArgumentNullException>(() => manager.Raise(new TestEvent(), null !));
        }