public void ActionCalls_are_always_global_without_namespace()
        {
            /*
             * 1) Select all Messages
             * 2) Filter for any (namespace independent) "fibonacci" action calls
             */
            var fibonacciActionMessages = Scenario
                                          .Messages
                                          .ForAction("**/fibonacci")
                                          .Calls();

            fibonacciActionMessages.Should().NotBeEmpty();

            /*
             * Action name should be a global name
             * Action name should not have a placeholder
             * All messages belong to the actionName namespace
             */
            foreach (var actionCall in fibonacciActionMessages)
            {
                var actionName = actionCall.ActionName;

                RosNameRegex.IsGlobalPattern(actionName).Should().BeTrue();
                RosNameRegex.ContainsPlaceholders(actionName).Should().BeFalse();

                actionCall.GoalMessage.Topic.Should().StartWith(actionName);
                actionCall.ResultMessage?.Topic.Should().StartWith(actionName);
                actionCall.FeedbackMessages.Should().OnlyContain(x => x.Topic.StartsWith(actionName));
            }
        }
Example #2
0
        public void Match_lobal_namespace_and_topic(string topic, bool shouldMatch)
        {
            const string pattern = "/fooo/bar";

            var regex = RosNameRegex.Create(pattern);

            regex.IsMatch(topic).Should().Be(shouldMatch);
        }
Example #3
0
        public void Null_topic_name_is_not_allowed()
        {
            const string pattern = null;

            this.Invoking(x => RosNameRegex.Create(pattern))
            .Should()
            .Throw <ArgumentNullException>();
        }
Example #4
0
        public void Relative_namespace_topic_name_is_not_allowed()
        {
            const string pattern = "fooo/bar";

            this.Invoking(x => RosNameRegex.Create(pattern))
            .Should()
            .Throw <InvalidRosNamePatternException>();
        }
Example #5
0
        public void Any_postfix_placeholder_matches_all_topics_in_namespace(string topic, bool shouldMatch)
        {
            const string pattern = "/fooo/**";

            var regex = RosNameRegex.Create(pattern);

            regex.IsMatch(topic).Should().Be(shouldMatch);
        }
Example #6
0
        public void Any_prefix_placeholder_matches_all_namespaces(string topic, bool shouldMatch)
        {
            const string pattern = "**/bar";

            var regex = RosNameRegex.Create(pattern);

            regex.IsMatch(topic).Should().Be(shouldMatch);
        }
Example #7
0
        public void Match_partial_namespace_placeholder(string topic, bool shouldMatch)
        {
            const string pattern = "/fo*/bar";

            var regex = RosNameRegex.Create(pattern);

            regex.IsMatch(topic).Should().Be(shouldMatch);
        }
Example #8
0
        public void Match_topic_in_a_sub_namespace(string topic, bool shouldMatch)
        {
            const string pattern = "/*/*/bar";

            var regex = RosNameRegex.Create(pattern);

            regex.IsMatch(topic).Should().Be(shouldMatch);
        }
        private ActionMessagesCollection(string actionNamePattern, IEnumerable <IRecordedMessage> messages)
        {
            ActionNamePattern = actionNamePattern;
            AllMessages       = messages;

            IsFullQualifiedActionNamePattern = RosNameRegex.IsFullQualifiedPattern(actionNamePattern);

            _exists = new Lazy <bool>(ActionExists);
        }
        public static ActionMessagesCollection Create(string actionNamePattern, IEnumerable <IRecordedMessage> messages)
        {
            if (actionNamePattern == null)
            {
                throw new ArgumentNullException(nameof(actionNamePattern));
            }
            if (messages == null)
            {
                throw new ArgumentNullException(nameof(messages));
            }

            actionNamePattern = actionNamePattern.Trim();

            if (string.Empty.Equals(actionNamePattern))
            {
                throw new InvalidRosNamePatternException("ROS name pattern must not be empty", nameof(actionNamePattern));
            }

            if (actionNamePattern.EndsWith("/"))
            {
                throw new InvalidRosNamePatternException(
                          "ROS name pattern must not end with a namespace separator ('/')", nameof(actionNamePattern));
            }


            var actionName = actionNamePattern.Substring(actionNamePattern.LastIndexOf("/", StringComparison.InvariantCulture) + 1);

            if (RosNameRegex.ContainsPlaceholders(actionName))
            {
                throw new InvalidRosNamePatternException("ROS action name must not contain any placeholders", nameof(actionNamePattern));
            }

            var actionTopicsPattern = actionNamePattern + "/*";
            var actionMessages      = messages
                                      .InTopic(actionTopicsPattern);

            var actionMessagesCollection = new ActionMessagesCollection(actionNamePattern, actionMessages);

            return(actionMessagesCollection);
        }
Example #11
0
 public void Invalid_patterns_throw_exception(string pattern)
 {
     this.Invoking(x => RosNameRegex.Create(pattern))
     .Should()
     .Throw <InvalidRosNamePatternException>();
 }
Example #12
0
        public void AnyPlaceholder_match_tests(string topic, string pattern, bool shouldMatch)
        {
            var regex = RosNameRegex.Create(pattern);

            regex.IsMatch(topic).Should().Be(shouldMatch);
        }
Example #13
0
 public void Empty_topic_name_is_not_allowed()
 {
     this.Invoking(x => RosNameRegex.Create(String.Empty))
     .Should()
     .Throw <InvalidRosNamePatternException>();
 }