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

            service.PushHandler(a);

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

            Assert.Same(a, foundHandler);
            foundHandler = service.GetHandler(typeof(A));
            Assert.Same(a, foundHandler);
        }
        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 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 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_return_null_if_handler_type_not_found()
        {
            var service = new EventHandlerService(null);

            service.PushHandler("Handler");

            // PopHandler asserts when an item isn't found
            using (new NoAssertContext())
            {
                Assert.Null(service.GetHandler(typeof(int)));
            }
        }
        public void GetHandler_should_return_last_inserted_handler_of_type()
        {
            var service = new EventHandlerService(null);

            service.PushHandler(new A());

            object second = new A();

            service.PushHandler(second);

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

            A a1 = new A();

            service.PushHandler(a1);
            A a2 = new A();

            service.PushHandler(a2);

            Assert.Same(a2, service.GetHandler(typeof(A)));
        }
        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 GetHandler_should_return_derived_handler_if_found()
        {
            var service = new EventHandlerService(null);
            A   a       = new A();

            service.PushHandler(a);
            B b = new B();

            service.PushHandler(b);

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

            Assert.Same(b, foundHandler);
        }
        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 GetHandler_should_return_null_if_lastHandlerType_null()
        {
            var service = new EventHandlerService(null);

            Assert.Null(service.GetHandler(typeof(object)));
        }
        public void GetHandler_should_throw_if_handlerType_null()
        {
            var service = new EventHandlerService(null);

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