コード例 #1
0
        public void EventManagerShouldNotifyActionWithDestroyedTargetTest()
        {
            var gameObject = new GameObject(nameof(EventManagerShouldNotifyActionWithDestroyedTargetTest));
            var target     = gameObject.AddComponent <TestHelperMonoBehaviour>();

            EventAggregator.AddHandler <TestEvent>(target.ActionWithAllowInvocationFromDestroyedObject);

            Object.DestroyImmediate(gameObject);

            EventAggregator.Event(new TestEvent());

            Assert.True(target.invokedAllowInvocationFromDestroyedObject);
        }
コード例 #2
0
        public void AddHandlerShouldRemoveUnityObjectHandlerTest()
        {
            var gameObject = new GameObject(nameof(AddHandlerShouldRemoveUnityObjectHandlerTest));
            var handler    = gameObject.AddComponent <TestMonoBehaviour>();

            handler.callback = () => Assert.Fail();

            EventAggregator.AddHandler(handler);
            EventAggregator.RemoveHandler(handler);
            EventAggregator.Event(new TestEvent());

            Object.DestroyImmediate(gameObject);
        }
コード例 #3
0
        public void EventManagerShouldNotifyActionWithDestroyedTargetAndLogTest()
        {
            var gameObject = new GameObject(nameof(EventManagerShouldNotifyActionWithDestroyedTargetAndLogTest));
            var target     = gameObject.AddComponent <TestHelperMonoBehaviour>();

            EventAggregator.AddHandler <TestEvent>(target.ActionWithAllowInvocationFromDestroyedObjectButLogWarning);

            Object.DestroyImmediate(gameObject);

            EventAggregator.Event(new TestEvent());

            LogAssert.Expect(LogType.Error, ExceptionHelper.Messages.ActionWasCalledInTheDestroyedObject);
            Assert.True(target.invokedAllowInvocationFromDestroyedObjectButLogWarning);
        }
コード例 #4
0
        public void EventManagerDispatcherShouldCreateNewEventManagerWhenSceneWereSwitchedTest()
        {
            int handlerInvocationCount = 0;

            var initialScene = SceneManager.CreateScene("initial",
                                                        new CreateSceneParameters {
                localPhysicsMode = LocalPhysicsMode.None
            });

            initialScene.name = $"Initial scene for {nameof(EventManagerDispatcherShouldCreateNewEventManagerWhenSceneWereSwitchedTest)}";
            SceneManager.SetActiveScene(initialScene);

            EventAggregator.AddHandler <TestSceneWithAttributeEvent>(_ => handlerInvocationCount++);
            EventAggregator.Event <TestSceneWithAttributeEvent>(default);
コード例 #5
0
        public void AddHandlerShouldAddUnityObjectHandlerTest()
        {
            bool flag = false;

            var gameObject = new GameObject(nameof(AddHandlerShouldAddUnityObjectHandlerTest));
            var handler    = gameObject.AddComponent <TestMonoBehaviour>();

            handler.callback = () => flag = true;

            EventAggregator.AddHandler(handler);
            EventAggregator.Event(new TestEvent());

            Assert.True(flag);

            Object.DestroyImmediate(gameObject);
        }
コード例 #6
0
        //TODO: "ThrowException", Exception?
        public void EventManagerShouldLogExceptionWhenTryNotifyActionWithDestroyedTargetTest()
        {
            var gameObject =
                new GameObject(nameof(EventManagerShouldLogExceptionWhenTryNotifyActionWithDestroyedTargetTest));
            var target = gameObject.AddComponent <TestHelperMonoBehaviour>();

            EventAggregator.AddHandler <TestEvent>(target.ActionWithPreventInvocationFromDestroyedObject);

            Object.DestroyImmediate(gameObject);

            LogAssert.Expect(LogType.Exception,
                             new Regex("." + ExceptionHelper.Messages.ActionCannotCalledWhenObjectIsDestroyed));

            EventAggregator.Event(new TestEvent());

            Assert.False(target.invokedPreventInvocationFromDestroyedObject);
        }
コード例 #7
0
        public void ShouldLogExceptionAndResetQueueEventsWhenHandlerThrowExceptionTest()
        {
            string keyMessage = nameof(keyMessage);

            EventAggregator.AddHandler <NotIsolateEvent>(_ => EventAggregator.Event <IsolateEvent>(new IsolateEvent()));
            EventAggregator.AddHandler <IsolateEvent>(_ => Assert.Fail());

            EventAggregator.AddHandler <NotIsolateEvent>(_ => throw new Exception(keyMessage));
            EventAggregator.AddHandler <NotIsolateEvent>(_ => Assert.Fail());

            LogAssert.Expect(LogType.Exception, new Regex(".keyMessage"));
            EventAggregator.Event(new NotIsolateEvent());

            EventManagerDispatcher <NotIsolateEvent> .RemoveEventManagerInternal();

            EventManagerDispatcher <IsolateEvent> .RemoveEventManagerInternal();
        }
コード例 #8
0
        public void ShouldLogExceptionAndShouldNotResetQueueEventsAndNotStopCurrentEventWhenHandlerThrowExceptionTest()
        {
            string keyMessage = nameof(keyMessage);
            bool   flagFromIsolateHandlers = false;
            bool   flagFromIsolateEvent    = false;

            EventAggregator.AddHandler <IsolateHandlersEvent>(_ => throw new Exception(keyMessage));
            EventAggregator.AddHandler <IsolateHandlersEvent>(_ => flagFromIsolateHandlers = true);
            EventAggregator.AddHandler <IsolateHandlersEvent>(_ => EventAggregator.Event(new IsolateEvent()));
            EventAggregator.AddHandler <IsolateEvent>(_ => flagFromIsolateEvent = true);

            LogAssert.Expect(LogType.Exception, new Regex(".keyMessage"));
            EventAggregator.Event(new IsolateHandlersEvent());

            Assert.True(flagFromIsolateHandlers);
            Assert.True(flagFromIsolateEvent);

            EventManagerDispatcher <IsolateHandlersEvent> .RemoveEventManagerInternal();

            EventManagerDispatcher <IsolateEvent> .RemoveEventManagerInternal();
        }
コード例 #9
0
 public void EventAggregatorShouldThrowPlatformExceptionWhenHisApiUsingInEditModeTest()
 {
     Assert.Throws <PlatformNotSupportedException>(() => EventAggregator.AddHandler <TestEvent>(_ => Assert.Fail()));
     Assert.Throws <PlatformNotSupportedException>(() => EventAggregator.Event <TestEvent>(default));