Exemplo n.º 1
0
 public void Add(ContextDataItems contextDataItems)
 {
     foreach (DataItem item in contextDataItems.items)
     {
         Add(item.Clone());
     }
 }
Exemplo n.º 2
0
        public string Build(string message, object[] messageArgs, string reason, ContextDataItems contextData)
        {
            string result = SubstituteReasonTag(message, SanitizeReason(reason));

            result = SubstituteContextualTags(result, contextData);
            result = FormatArgumentPlaceholders(result, messageArgs);
            return(result);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Creates a nested scope used during chaining.
 /// </summary>
 internal AssertionScope(AssertionScope sourceScope, bool sourceSucceeded)
 {
     assertionStrategy = sourceScope.assertionStrategy;
     contextData       = sourceScope.contextData;
     reason            = sourceScope.reason;
     useLineBreaks     = sourceScope.useLineBreaks;
     parent            = sourceScope.parent;
     expectation       = sourceScope.expectation;
     evaluateCondition = sourceSucceeded;
 }
        private string SubstituteContextualTags(string message, ContextDataItems contextData)
        {
            var regex = new Regex(@"\{(?<key>[a-z|A-Z]+)(?:\:(?<default>[a-z|A-Z|\s]+))?\}");

            return(regex.Replace(message, match =>
            {
                string key = match.Groups["key"].Value;
                return contextData.AsStringOrDefault(key) ?? match.Groups["default"].Value;
            }));
        }
        private string SubstituteContextualTags(string message, ContextDataItems contextData)
        {
            string pattern = @"(?<!\{)\{(?<key>[a-z|A-Z]+)(?:\:(?<default>[a-z|A-Z|\s]+))?\}(?!\})";

            return(Regex.Replace(message, pattern, match =>
            {
                string key = match.Groups["key"].Value;
                return contextData.AsStringOrDefault(key)?.Replace("{", "{{").Replace("}", "}}") ?? match.Groups["default"].Value;
            }));
        }
        // SMELL: Too many parameters.
        public string Build(string message, object[] messageArgs, string reason, ContextDataItems contextData, string identifier, string fallbackIdentifier)
        {
            message = Regex.Replace(message, "{reason}", SanitizeReason(reason));

            message = SubstituteIdentifier(message, identifier?.EscapePlaceholders(), fallbackIdentifier);

            message = SubstituteContextualTags(message, contextData);

            message = FormatArgumentPlaceholders(message, messageArgs);

            return(message);
        }
Exemplo n.º 7
0
        private static string SubstituteContextualTags(string message, ContextDataItems contextData)
        {
            const string pattern = @"(?<!\{)\{(?<key>[a-z|A-Z]+)(?:\:(?<default>[a-z|A-Z|\s]+))?\}(?!\})";

            return(Regex.Replace(message, pattern, match =>
            {
                string key = match.Groups["key"].Value;
                string contextualTags = contextData.AsStringOrDefault(key);
                string contextualTagsSubstituted = contextualTags?.EscapePlaceholders();

                return contextualTagsSubstituted ?? match.Groups["default"].Value;
            }));
        }