コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        public void Raise_NullLog_ThrowsArgumentNullException()
        {
            var manager = new OrionEventManager();

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