public void CreateInvalidGlobalWildcardHandlerChannel()
        {
            var dispatcher = new ChannelDispatcher();
            var handler1   = new CounterHandler();

            dispatcher.Register("/services/test/**/edit", handler1);
        }
        public void TestGlobalWildcardChannelMatching()
        {
            var dispatcher     = new ChannelDispatcher();
            var handler1       = new CounterHandler();
            var handler2       = new CounterHandler();
            var handler3       = new CounterHandler();
            var defaultHandler = new CounterHandler();

            dispatcher.Register("/services/test/**", handler1);
            dispatcher.Register("/services/test", handler2);
            dispatcher.Register("/services/banana/*", handler2);
            dispatcher.Register("/services/banana/**", handler3);
            dispatcher.RegisterDefault(defaultHandler);
            Assert.IsNotNull(dispatcher.DefaultHandler);

            dispatcher.Handle("/services/test", "data..."); // hits handler2
            Assert.AreEqual(0, defaultHandler.Calls);
            Assert.AreEqual(0, handler1.Calls);
            Assert.AreEqual(1, handler2.Calls);
            Assert.AreEqual(0, handler3.Calls);

            dispatcher.Handle("/services/test/edit", "data..."); // hits handler1
            Assert.AreEqual(0, defaultHandler.Calls);
            Assert.AreEqual(1, handler1.Calls);
            Assert.AreEqual(1, handler2.Calls);
            Assert.AreEqual(0, handler3.Calls);

            dispatcher.Handle("/services/test/1/edit", "data..."); // hits handler1
            Assert.AreEqual(0, defaultHandler.Calls);
            Assert.AreEqual(2, handler1.Calls);
            Assert.AreEqual(1, handler2.Calls);
            Assert.AreEqual(0, handler3.Calls);

            dispatcher.Handle("/services/banana", "data..."); // hits default handler
            Assert.AreEqual(1, defaultHandler.Calls);
            Assert.AreEqual(2, handler1.Calls);
            Assert.AreEqual(1, handler2.Calls);
            Assert.AreEqual(0, handler3.Calls);

            dispatcher.Handle("/services/banana/1/edit", "data..."); // hits handler3
            Assert.AreEqual(1, defaultHandler.Calls);
            Assert.AreEqual(2, handler1.Calls);
            Assert.AreEqual(1, handler2.Calls);
            Assert.AreEqual(1, handler3.Calls);
        }
        public void TestWildcardBasicChannelMatchingWith3Handlers()
        {
            var dispatcher     = new ChannelDispatcher();
            var handler1       = new CounterHandler();
            var handler2       = new CounterHandler();
            var handler3       = new CounterHandler();
            var defaultHandler = new CounterHandler();

            dispatcher.Register("/services/test/*/edit", handler1);
            dispatcher.Register("/services/test/2", handler2);
            dispatcher.Register("/services/banana/*", handler2);
            dispatcher.Register("/services/internal", handler3);
            dispatcher.RegisterDefault(defaultHandler);
            Assert.IsNotNull(dispatcher.DefaultHandler);

            dispatcher.Handle("/services/test/1", "data..."); // hits default
            Assert.AreEqual(1, defaultHandler.Calls);
            Assert.AreEqual(0, handler1.Calls);
            Assert.AreEqual(0, handler2.Calls);
            Assert.AreEqual(0, handler3.Calls);

            dispatcher.Handle("/services/internal", "data..."); // hits handler3
            Assert.AreEqual(1, defaultHandler.Calls);
            Assert.AreEqual(0, handler1.Calls);
            Assert.AreEqual(0, handler2.Calls);
            Assert.AreEqual(1, handler3.Calls);

            dispatcher.Handle("/services/test/1/edit", "data..."); // hits handler1
            Assert.AreEqual(1, defaultHandler.Calls);
            Assert.AreEqual(1, handler1.Calls);
            Assert.AreEqual(0, handler2.Calls);
            Assert.AreEqual(1, handler3.Calls);

            dispatcher.Handle("/services/banana/edit", "data..."); // hits handler2
            Assert.AreEqual(1, defaultHandler.Calls);
            Assert.AreEqual(1, handler1.Calls);
            Assert.AreEqual(1, handler2.Calls);
            Assert.AreEqual(1, handler3.Calls);

            dispatcher.Handle("/services/banana/1/edit", "data..."); // hits default
            Assert.AreEqual(2, defaultHandler.Calls);
            Assert.AreEqual(1, handler1.Calls);
            Assert.AreEqual(1, handler2.Calls);
            Assert.AreEqual(1, handler3.Calls);
        }
        public void TestBasicChannelMatchingWith2Handlers()
        {
            var dispatcher     = new ChannelDispatcher();
            var handler1       = new CounterHandler();
            var handler2       = new CounterHandler();
            var defaultHandler = new CounterHandler();

            dispatcher.Register("/services/test/1", handler1);
            dispatcher.Register("/services/test/2", handler2);
            dispatcher.RegisterDefault(defaultHandler);
            Assert.IsNotNull(dispatcher.DefaultHandler);

            dispatcher.Handle("/services/test/2", "data...");
            Assert.AreEqual(1, handler2.Calls, "Invalid number of test/2 notifications!");
            Assert.AreEqual(0, handler1.Calls, "Too many test/2 handler calls on handler1!");
            Assert.AreEqual(0, defaultHandler.Calls, "Too many test/2 handler calls on defaultHandler!");

            dispatcher.Handle("/services/test/1", "data...");
            Assert.AreEqual(1, handler2.Calls, "Invalid number of test/2 notifications!");
            Assert.AreEqual(1, handler1.Calls, "Invalid number of test/1 notifications!");
            Assert.AreEqual(0, defaultHandler.Calls, "Too many test/1 handler calls on defaultHandler!");
        }