Esempio n. 1
0
        public void TestTopicTree()
        {
            //因为树节点的测试类似,树从根开始,仅测试不同部分
            //测试无节点时的树根
            TopicTree <int> topicTree = new TopicTree <int>();

            Assert.Equal(".", topicTree.rootNode.Nodevalue);
            List <int> matchlist = topicTree.CollectMatches("#");

            Assert.Empty(matchlist);

            topicTree.Add(new Topic("work"), 20);

            topicTree.Add(new Topic("sport/ball/football"), 5);
            topicTree.Add(new Topic("sport/ball/longrun"), 6);
            topicTree.Add(new Topic("sport/run/longrun"), 8);
            topicTree.Add(new Topic("sport/run/shortrun"), 10);
            matchlist = topicTree.CollectMatches("#");
            Assert.Equal(5, matchlist.Count);
            matchlist = topicTree.CollectMatches("sport/#");
            Assert.Equal(4, matchlist.Count);
            matchlist = topicTree.CollectMatches("sport/+/longrun");
            Assert.Equal(2, matchlist.Count);

            topicTree.RemoveAll();
            matchlist = topicTree.CollectMatches("#");
            Assert.Empty(matchlist);
        }
Esempio n. 2
0
        public void Subscribe(Subscription subscription, PublishArrivedDelegate subscriber)
        {
            if (topicTree == null)
            {
                topicTree = new TopicTree <PublishArrivedDelegate>();
            }

            topicTree.Add(subscription.Topic, subscriber);

            // TODO: Check if we're already subscribed.
            Subscribe(subscription);
        }