public void MatchDoesntMatch_StarOnEnd_WhenEmptySegments()
        {
            const string topicWithEmptySegments = "user..";
            var          topicList = new[] { "user.*", UserDeletedTopic };

            TopicMatcher.Match(topicWithEmptySegments, topicList).ShouldBeEmpty();
        }
        public void MatchDoesntMatch_HashTagOnBeginning_WhenEmptySegments()
        {
            const string topicWithEmptySegments = "..user";
            var          topicList = new[] { "#.user", UserDeletedTopic };

            TopicMatcher.Match(topicWithEmptySegments, topicList).ShouldBeEmpty();
        }
        public void MatchDoesntMatch_HashTagInMiddle_WhenEmptySegments()
        {
            const string topicWithEmptySegments = "user..added";
            var          topicList = new[] { "user.#.added", UserDeletedTopic };

            TopicMatcher.Match(topicWithEmptySegments, topicList).ShouldBeEmpty();
        }
        public void MatchDoesntMatch_StarInMiddle_When2Segments()
        {
            const string hashtagTopic = "user.*.added";
            var          topicList    = new[] { hashtagTopic, UserDeletedTopic };

            TopicMatcher.Match(LongAddedTopic, topicList).ShouldBeEmpty();
        }
        public void MatchMatches_StarOnEnd_When2Segment()
        {
            const string hashtagTopic = "user.something.*";
            var          topicList    = new[] { hashtagTopic, UserDeletedTopic };

            TopicMatcher.Match(LongAddedTopic, topicList).ShouldBeEmpty();
        }
        public void MatchMatches_ExactlySameTopic()
        {
            var topicList = new [] { UserAddedTopic, UserDeletedTopic };

            TopicMatcher.Match(UserAddedTopic, topicList).ToList()
            .ShouldHaveSingleItem()
            .ShouldBe(UserAddedTopic);
        }
        public void MatchMatches_MultipleStarts()
        {
            const string starTopic = "user.*.event.*.added";
            var          topicList = new[] { starTopic, UserDeletedTopic };

            TopicMatcher.Match(VeryLongAddedTopic, topicList)
            .ShouldHaveSingleItem()
            .ShouldBe(starTopic);
        }
        public void MatchMatches_HashtagStartCombination()
        {
            const string hashtagStarTopic = "user.#.bar.*";
            var          topicList        = new[] { hashtagStarTopic, UserDeletedTopic };

            TopicMatcher.Match(VeryLongAddedTopic, topicList)
            .ShouldHaveSingleItem()
            .ShouldBe(hashtagStarTopic);
        }
        public void MatchMatches_StarOnEnd_When1Segment()
        {
            const string hashtagTopic = "user.event.*";
            var          topicList    = new[] { hashtagTopic, UserDeletedTopic };

            TopicMatcher.Match(UserAddedTopic, topicList)
            .ShouldHaveSingleItem()
            .ShouldBe(hashtagTopic);
        }
        public void MatchMatches_StarInMiddle()
        {
            const string starTopic = "user.*.added";
            var          topicList = new [] { starTopic, UserDeletedTopic };

            TopicMatcher.Match(UserAddedTopic, topicList)
            .ShouldHaveSingleItem()
            .ShouldBe(starTopic);
        }
        public void MatchMatches_HashtagOnEnd_When2Segment()
        {
            const string hashtagTopic = "user.something.#";
            var          topicList    = new[] { hashtagTopic, UserDeletedTopic };

            TopicMatcher.Match(LongAddedTopic, topicList)
            .ShouldHaveSingleItem()
            .ShouldBe(hashtagTopic);
        }
        public void MatchMatches_HashTagInBeginning_When2Segments()
        {
            const string hashtagTopic = "#.event.added";
            var          topicList    = new[] { hashtagTopic, UserDeletedTopic };

            TopicMatcher.Match(LongAddedTopic, topicList)
            .ShouldHaveSingleItem()
            .ShouldBe(hashtagTopic);
        }
        public void MatchMatches_MultipleHashtags()
        {
            const string hashtagTopic = "user.#.bar.#";
            var          topicList    = new[] { hashtagTopic, UserDeletedTopic };

            TopicMatcher.Match(VeryLongAddedTopic, topicList)
            .ShouldHaveSingleItem()
            .ShouldBe(hashtagTopic);
        }
        public void MatchMatches_HashtagInMiddle_When1Segment()
        {
            const string hashtagTopic = "user.#.added";
            var          topicList    = new[] { hashtagTopic, UserDeletedTopic };

            TopicMatcher.Match(UserAddedTopic, topicList)
            .ShouldHaveSingleItem()
            .ShouldBe(hashtagTopic);
        }
예제 #15
0
 public MqttService(MqttClient mqttClient, MqttServiceSettings settings, IMessageBus messageBus, IObjectSerializer serializer, ILogger logger)
 {
     _mqttClient   = mqttClient ?? throw new ArgumentNullException(nameof(mqttClient));
     _settings     = settings ?? throw new ArgumentNullException(nameof(settings));
     _messageBus   = messageBus ?? throw new ArgumentNullException(nameof(messageBus));
     _serializer   = serializer ?? throw new ArgumentNullException(nameof(serializer));
     _logger       = logger ?? throw new ArgumentNullException(nameof(logger));
     _topicMatcher = new TopicMatcher(settings);
     _mqttClient.ConnectionClosed       += ConnectionClosed;
     _mqttClient.MqttMsgPublishReceived += MessageReceived;
 }
        private void InvokeMatchingTopicCallbacks(
            EventMessage eventMessage,
            string queueName)
        {
            var matchingTopics = TopicMatcher.Match(
                eventMessage.RoutingKey,
                _queueCallbacks[queueName].Select(t => t.Topic).ToArray());

            _queueCallbacks[queueName]
            .Where(t => matchingTopics.Contains(t.Topic))
            .ToList()
            .ForEach(t => t.Callback(eventMessage));
        }
        public void MatchDoesntMatch_StarOnEnd_WhenNoSegments()
        {
            var topicList = new[] { "user.added.*", UserDeletedTopic };

            TopicMatcher.Match(ShortAddedTopic, topicList).ShouldBeEmpty();
        }
 public void MatchReturnsEmptyListIfInputListIsNull()
 {
     TopicMatcher.Match(UserAddedTopic, null).ShouldBeEmpty();
 }
        public void MatchDoesntMatch_HashtagInMiddle_WhenNoSegments()
        {
            var topicList = new[] { "user.#.added", UserDeletedTopic };

            TopicMatcher.Match(ShortAddedTopic, topicList).ShouldBeEmpty();
        }
 public void MatchReturnsEmptyListIfInputIsEmpty()
 {
     TopicMatcher.Match(UserAddedTopic, new string[0]).ShouldBeEmpty();
 }
 public void MatchReturnsEmptyListIfNoTopicsMatch()
 {
     TopicMatcher.Match(UserAddedTopic, new [] { "something.else" }).ShouldBeEmpty();
 }
 public void MatchReturnsEmptyListIfTopicIsWhiteSpace()
 {
     TopicMatcher.Match(" ", new [] { "foo.bar" }).ShouldBeEmpty();
 }
 public void MatchReturnsEmptyListIfTopicIsNull()
 {
     TopicMatcher.Match(null, new [] { "foo.bar" }).ShouldBeEmpty();
 }
        public void MatchDoesntMatch_HashTagOnBeginning_WhenNoSegments()
        {
            var topicList = new[] { "#.user.added", UserDeletedTopic };

            TopicMatcher.Match(ShortAddedTopic, topicList).ShouldBeEmpty();
        }