public void ParameterDefinition_Constructor_Sets_Default_Formatter()
        {
            var parameterDefinition = new ParameterDefinition("name", "label");

            Assert.IsNotNull(parameterDefinition.Formatter);
            Assert.AreEqual("testing", parameterDefinition.Formatter("testing"));
        }
        public void ParameterDefinition_Constructor_Sets_Required_Properties()
        {
            var parameterDefinition = new ParameterDefinition("name", "label");

            Assert.AreEqual("name", parameterDefinition.Name);
            Assert.AreEqual("label", parameterDefinition.Label);
        }
        public void ParameterDefinition_Constructor_Sets_Optional_Properties()
        {
            Func<string, string> formatter = s => s + "great";
            var parameterDefinition = new ParameterDefinition("name", "label", formatter, true);

            Assert.AreEqual(true, parameterDefinition.IsRegexMatch);
            Assert.AreEqual(formatter, parameterDefinition.Formatter);
            Assert.AreEqual("so great", parameterDefinition.Formatter("so "));
        }
        public void ParameterDefinition_Constructor_Sets_All_Properties()
        {
            Func<string, string> formatter = s => s + "great";
            var parameterDefinition = new ParameterDefinition("name", "label", formatter);

            Assert.AreEqual("name", parameterDefinition.Name);
            Assert.AreEqual("label", parameterDefinition.Label);
            Assert.AreEqual(formatter, parameterDefinition.Formatter);
            Assert.AreEqual("so great", parameterDefinition.Formatter("so "));
        }
예제 #5
0
 /// <summary>
 /// Dump any parameters that match the given parameter definition's regular expression.
 /// </summary>
 /// <param name="parameterDefinition">Parameter definition to regex match with parameters.</param>
 /// <param name="parameters">All parameters to consider for a regex match.</param>
 /// <param name="writer">Action that takes a string to receive output.</param>
 private void DumpRegexParameters(ParameterDefinition parameterDefinition, Dictionary<string, string> parameters, Action<string> writer)
 {
     foreach (var pair in parameters)
     {
         var match = Regex.Match(pair.Key, parameterDefinition.Name);
         if (match.Success)
         {
             var label = parameterDefinition.Label.Replace("$1", match.Groups[1].Captures[0].Value);
             DumpParameter(parameterDefinition, label, pair.Value, writer);
         }
     }
 }
예제 #6
0
 /// <summary>
 /// Dump any parameter exactly matching the given parameter definition.
 /// </summary>
 /// <param name="parameterDefinition">Parameter definition to exactly match with parameters.</param>
 /// <param name="parameters">All parameters to consider for an exact match.</param>
 /// <param name="writer">Action that takes a string to receive debugger output.</param>
 private void DumpExactParameter(ParameterDefinition parameterDefinition, Dictionary<string, string> parameters, Action<string> writer)
 {
     string rawValue;
     if (parameters.TryGetValue(parameterDefinition.Name, out rawValue))
         DumpParameter(parameterDefinition, parameterDefinition.Label, rawValue, writer);
 }
예제 #7
0
 /// <summary>
 /// Create a new ProtocolDebugger with a given action to receive debugger output.
 /// </summary>
 /// <param name="parameterDefinitions">Array of ParameterDefinitions valid for this debugger.</param>
 public ProtocolDebugger(ParameterDefinition[] parameterDefinitions)
 {
     this.parameterDefinitions = parameterDefinitions;
 }
예제 #8
0
 /// <summary>
 /// Format and write a parameter to the current writer.
 /// </summary>
 /// <param name="parameterDefinition">Parameter to write out.</param>
 /// <param name="label">Human-readable label to prefix before the value.</param>
 /// <param name="rawValue">Raw value of the parameter to format before writing.</param>
 /// <param name="writer">Action that takes a string to receive output.</param>
 private void DumpParameter(ParameterDefinition parameterDefinition, string label, string rawValue, Action<string> writer)
 {
     var formattedValue = parameterDefinition.Formatter(rawValue);
     if (!String.IsNullOrWhiteSpace(formattedValue))
         writer(label.PadRight(24) + ": " + formattedValue);
 }
예제 #9
0
 /// <summary>
 /// Format and write a parameter to the current writer.
 /// </summary>
 /// <param name="parameterDefinition">Parameter to write out.</param>
 /// <param name="rawValue">Raw value of the parameter to format before writing.</param>
 private void WriteParameter(ParameterDefinition parameterDefinition, string rawValue)
 {
     var formattedValue = parameterDefinition.Formatter(rawValue);
     if (!String.IsNullOrWhiteSpace(formattedValue))
         writer(parameterDefinition.Label.PadRight(24) + ": " + formattedValue);
 }
예제 #10
0
 /// <summary>
 /// Create a new ProtocolDebugger with a given action to receive debugger output.
 /// </summary>
 /// <param name="writer">Action that takes a string to receive debugger output.</param>
 /// <param name="parameterDefinitions">Array of ParameterDefinitions valid for this debugger.</param>
 public ProtocolDebugger(Action<string> writer, ParameterDefinition[] parameterDefinitions)
 {
     this.writer = writer;
     this.parameterDefinitions = parameterDefinitions;
 }