Example #1
0
        public void RegisteringCommandObserverDoesNotChangeState()
        {
            var observer = new TestCommandObserver();

            m_CommandDispatcher.RegisterCommandPreDispatchCallback(observer.Observe);
            Assert.That(GetState().FooBarStateComponent.Foo, Is.EqualTo(k_StateDefaultValue));
        }
Example #2
0
        public void RegisteredCommandObserverShouldBeCalledForEachCommandDispatched()
        {
            var observer = new TestCommandObserver();

            m_CommandDispatcher.RegisterCommandPreDispatchCallback(observer.Observe);

            m_CommandDispatcher.RegisterCommandHandler <TestGraphToolState, PassThroughCommand>(PassThroughCommand.PassThrough);
            m_CommandDispatcher.RegisterCommandHandler <TestGraphToolState, ChangeFooCommand>(ChangeFooCommand.DefaultHandler);
            m_CommandDispatcher.RegisterCommandHandler <TestGraphToolState, ChangeBarCommand>(ChangeBarCommand.DefaultHandler);
            Assert.That(observer.CommandObserved, Is.EqualTo(0));

            m_CommandDispatcher.Dispatch(new ChangeFooCommand(20));
            Assert.That(observer.CommandObserved, Is.EqualTo(1));

            m_CommandDispatcher.Dispatch(new ChangeBarCommand(10));
            Assert.That(observer.CommandObserved, Is.EqualTo(2));

            m_CommandDispatcher.Dispatch(new PassThroughCommand());
            Assert.That(observer.CommandObserved, Is.EqualTo(3));

            // Unregistered observer should not be notified anymore
            m_CommandDispatcher.UnregisterCommandPreDispatchCallback(observer.Observe);

            m_CommandDispatcher.Dispatch(new PassThroughCommand());
            Assert.That(observer.CommandObserved, Is.EqualTo(3));
        }
Example #3
0
        public void RegisteringCommandObserverTwiceThrows()
        {
            var observer = new TestCommandObserver();

            m_CommandDispatcher.RegisterCommandHandler <TestGraphToolState, ChangeFooCommand>(ChangeFooCommand.DefaultHandler);
            m_CommandDispatcher.RegisterCommandPreDispatchCallback(observer.Observe);

            Assert.Throws <InvalidOperationException>(() => m_CommandDispatcher.RegisterCommandPreDispatchCallback(observer.Observe));
        }
Example #4
0
        public void UnregisteringCommandObserverTwiceDoesNotThrow()
        {
            var observer = new TestCommandObserver();

            m_CommandDispatcher.RegisterCommandPreDispatchCallback(observer.Observe);

            m_CommandDispatcher.UnregisterCommandPreDispatchCallback(observer.Observe);
            m_CommandDispatcher.UnregisterCommandPreDispatchCallback(observer.Observe);
            LogAssert.NoUnexpectedReceived();
        }
Example #5
0
        public void CommandObserverShouldNotBeCalledAfterUnregistering()
        {
            var observer1 = new TestCommandObserver();

            m_CommandDispatcher.RegisterCommandPreDispatchCallback(observer1.Observe);

            m_CommandDispatcher.RegisterCommandHandler <TestGraphToolState, ChangeFooCommand>(ChangeFooCommand.DefaultHandler);
            Assert.That(observer1.CommandObserved, Is.EqualTo(0));

            m_CommandDispatcher.Dispatch(new ChangeFooCommand(10));
            Assert.That(observer1.CommandObserved, Is.EqualTo(1));

            m_CommandDispatcher.UnregisterCommandPreDispatchCallback(observer1.Observe);
            m_CommandDispatcher.Dispatch(new ChangeFooCommand(10));
            Assert.That(observer1.CommandObserved, Is.EqualTo(1));
        }
Example #6
0
        public void AllRegisteredCommandObserverShouldBeCalledForEachCommandDispatched()
        {
            var observer1 = new TestCommandObserver();
            var observer2 = new TestCommandObserver();

            m_CommandDispatcher.RegisterCommandPreDispatchCallback(observer1.Observe);
            m_CommandDispatcher.RegisterCommandPreDispatchCallback(observer2.Observe);

            m_CommandDispatcher.RegisterCommandHandler <TestGraphToolState, PassThroughCommand>(PassThroughCommand.PassThrough);
            m_CommandDispatcher.RegisterCommandHandler <TestGraphToolState, ChangeFooCommand>(ChangeFooCommand.DefaultHandler);
            m_CommandDispatcher.RegisterCommandHandler <TestGraphToolState, ChangeBarCommand>(ChangeBarCommand.DefaultHandler);
            Assert.That(observer1.CommandObserved, Is.EqualTo(0));
            Assert.That(observer2.CommandObserved, Is.EqualTo(0));

            m_CommandDispatcher.Dispatch(new ChangeFooCommand(10));
            Assert.That(observer1.CommandObserved, Is.EqualTo(1));
            Assert.That(observer2.CommandObserved, Is.EqualTo(1));

            m_CommandDispatcher.Dispatch(new PassThroughCommand());
            Assert.That(observer1.CommandObserved, Is.EqualTo(2));
            Assert.That(observer2.CommandObserved, Is.EqualTo(2));
        }