public void PopHandler_should_pop_if_handler_found_on_stack()
        {
            var service = new EventHandlerService(null);
            A   a       = new A();

            service.PushHandler(a);
            service.PopHandler(a);
            Assert.Null(service.GetHandler(typeof(A)));
        }
        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_not_pop_if_handler_not_found_on_stack()
        {
            var service = new EventHandlerService(null);
            A   a       = new A();

            service.PushHandler(a);

            // PopHandler asserts when an item isn't found
            using (new NoAssertContext())
            {
                service.PopHandler(new B());
            }

            Assert.Same(a, service.GetHandler(typeof(A)));
        }
        public void PopHandler_should_raise_changedEvent_if_handler_found_on_stack()
        {
            var service = new EventHandlerService(null);

            A a = new A();

            service.PushHandler(a);

            int callCount = 0;

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

            service.PopHandler(a);

            Assert.Equal(1, callCount);
        }
        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 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);
            }
        }
        public void PopHandler_should_not_throw_if_stack_empty()
        {
            var service = new EventHandlerService(null);

            service.PopHandler(typeof(ComboBox));
        }
        public void PopHandler_should_throw_if_handler_null()
        {
            var service = new EventHandlerService(null);

            Assert.Throws <ArgumentNullException>(() => service.PopHandler(null));
        }