public void GetHandler_should_return_null_if_handler_not_found_on_stack()
        {
            var service = new EventHandlerService(null);

            service.GetTestAccessor().LastHandlerType = typeof(Button);
            service.GetTestAccessor().HandlerHead     = CreateStack();

            Assert.Null(service.GetHandler(typeof(ComboBox)));
        }
        public void GetHandler_should_return_lastHandlerType_if_matches()
        {
            var service = new EventHandlerService(null);
            var handler = new Button();

            service.GetTestAccessor().LastHandlerType = typeof(Button);
            service.GetTestAccessor().LastHandler     = handler;

            Assert.Same(handler, service.GetHandler(typeof(Button)));
        }
        public void GetHandler_should_set_lastHandlerType_if_handler_found_on_stack()
        {
            var service = new EventHandlerService(null);

            service.GetTestAccessor().LastHandlerType = typeof(Button);
            service.GetTestAccessor().HandlerHead     = CreateStack();

            var foundHandler = service.GetHandler(typeof(TextBox));

            Assert.Same(typeof(TextBox), service.GetTestAccessor().LastHandlerType);
        }
        public void GetHandler_should_set_lastHandler_if_handler_found_on_stack()
        {
            var service = new EventHandlerService(null);

            service.GetTestAccessor().LastHandlerType = typeof(Button);
            var stackHead = CreateStack();
            var handler   = stackHead.next.handler;

            service.GetTestAccessor().HandlerHead = stackHead;

            var foundHandler = service.GetHandler(handler.GetType());

            Assert.Same(handler, service.GetTestAccessor().LastHandler);
        }
        public void PopHandler_should_set_lastHandlerType_null_if_handler_found_on_stack()
        {
            var service = new EventHandlerService(null);

            service.GetTestAccessor().LastHandlerType = typeof(Button);
            var stackHead = CreateStack();
            var handler   = stackHead.next.handler;

            service.GetTestAccessor().HandlerHead = stackHead;

            service.PopHandler(handler);

            Assert.Null(service.GetTestAccessor().LastHandlerType);
        }
        public void PopHandler_should_raise_changedEvent_if_handler_found_on_stack()
        {
            var service = new EventHandlerService(null);

            service.GetTestAccessor().LastHandlerType = typeof(Button);
            var stackHead = CreateStack();
            var handler   = stackHead.next.handler;

            service.GetTestAccessor().HandlerHead = stackHead;
            int callCount = 0;

            service.EventHandlerChanged += (s, e) => { callCount++; };

            service.PopHandler(handler);

            Assert.Equal(1, callCount);
        }
        public void PushHandler_should_set_lastHandler_to_new_handler()
        {
            var service = new EventHandlerService(null);
            var handler = new Label();

            service.PushHandler(handler);

            Assert.Same(handler, service.GetTestAccessor().LastHandler);
        }
        public void PopHandler_should_pop_if_handler_found_on_stack()
        {
            var service = new EventHandlerService(null);

            service.GetTestAccessor().LastHandlerType = typeof(Button);
            var stackHead = CreateStack();
            var handler   = stackHead.next.handler;

            service.GetTestAccessor().HandlerHead = stackHead;

            service.PopHandler(handler);

            var depth = 0;

            for (HandlerEntry entry = service.GetTestAccessor().HandlerHead; entry != null; entry = entry.next)
            {
                depth++;
            }

            Assert.Equal(1, depth);
        }
        public void PopHandler_should_not_pop_if_handler_not_found_on_stack()
        {
            // we expect to hit Debug.Assert and unless we clear listeners we will crash to xUnit runner:
            //  "The active test run was aborted. Reason: Test host process crashed : Assertion Failed"
            using (new TraceListenerlessContext())
            {
                var service = new EventHandlerService(null);
                service.GetTestAccessor().LastHandlerType = typeof(Button);
                var stackHead = CreateStack();
                service.GetTestAccessor().HandlerHead = stackHead;

                service.PopHandler(typeof(ComboBox));

                var depth = 0;
                for (HandlerEntry entry = service.GetTestAccessor().HandlerHead; entry != null; entry = entry.next)
                {
                    depth++;
                }

                Assert.Equal(3, depth);
            }
        }