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

            service.PopHandler(typeof(ComboBox));
        }
コード例 #9
0
        public void PopHandler_should_throw_if_handler_null()
        {
            var service = new EventHandlerService(null);

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