public void LastValueSingleValue() { TopicProperty property = new TopicProperty("Name"); property.Values.Add(new TopicPropertyValue("Value")); Assert.AreEqual("Value", property.LastValue, "Checking that the last value is correct."); }
public void HasValuePositive() { TopicProperty property = new TopicProperty("Name"); property.Values.Add(new TopicPropertyValue("Single rawVaue")); Assert.IsTrue(property.HasValue, "Checking that a property with a value returns the correct result."); }
public void AsListSingleValue() { TopicProperty property = new TopicProperty("Name"); property.Values.Add(new TopicPropertyValue("Single rawValue")); Assert.AreEqual(1, property.AsList().Count); Assert.AreEqual("Single rawValue", property.AsList()[0], "Checking that single rawValue is returned intact."); }
private static void ParseSingleLineProperties(string text, TopicPropertyCollection properties) { Regex propertyPattern = new Regex(c_propertyPattern, RegexOptions.Multiline); foreach (Match match in propertyPattern.Matches(text)) { string name = match.Groups["name"].Value; string rawValue = match.Groups["val"].Value.Trim(); TopicProperty topicProperty = null; if (!properties.Contains(name)) { topicProperty = new TopicProperty(name); properties.Add(topicProperty); } else { topicProperty = properties[name]; } TopicPropertyValue value = new TopicPropertyValue(rawValue); topicProperty.Values.Add(value); } }
private static void ParseMultiLineProperties(string text, TopicPropertyCollection properties) { string[] lines = text.Split('\n'); Regex propertyPattern = s_multilinePropertyRegex; bool inMultilineProperty = false; string currentProperty = null; string endDelimiter = null; StringBuilder rawValueBuilder = new StringBuilder(); foreach (string line in lines) { if (inMultilineProperty) { if (endDelimiter != null && line.Trim() == endDelimiter) { inMultilineProperty = false; TopicProperty property = new TopicProperty(currentProperty); property.Values.Add(new TopicPropertyValue(rawValueBuilder.ToString())); properties.Add(property); } else { rawValueBuilder.Append(line); rawValueBuilder.Append("\n"); } } else { Match match = propertyPattern.Match(line); if (match.Success) { inMultilineProperty = true; currentProperty = match.Groups["name"].Value; string delimiter = match.Groups["delim"].Value; switch (delimiter) { case "[": endDelimiter = "]"; break; case "{": endDelimiter = "}"; break; default: endDelimiter = null; break; } string rawValue = match.Groups["val"].Value.Trim(); rawValueBuilder.Length = 0; rawValueBuilder.Append(rawValue); } } } }
private static void AssertPropertyCorrect(TopicProperty property, string expectedName, params string[] expectedValues) { Assert.AreEqual(expectedName, property.Name, "Checking that property name was correct."); Assert.AreEqual(expectedValues.Length, property.Values.Count, "Checking that property had the right number of values."); for (int i = 0; i < expectedValues.Length; i++) { string message = string.Format("Checking that value {0} of property {1} is correct.", i, property.Name); Assert.AreEqual(expectedValues[i], property.Values[i].RawValue, message); } }
private void AddBuiltInProperty(ParsedTopic parsedTopic, string propertyName, string value) { // The built-in topics show up as the last value if the property already exists. // This should be reasonably back-compatible, as the last value wins when people // don't remember that properties can have multiple values. TopicProperty property = null; if (parsedTopic.Properties.Contains(propertyName)) { property = parsedTopic.Properties[propertyName]; } else { property = new TopicProperty(propertyName); parsedTopic.Properties.Add(property); } TopicPropertyValue topicPropertyValue = new TopicPropertyValue(value); property.Values.Add(topicPropertyValue); }
set => SetValue(TopicProperty, value);
private void AssertTopicPropertyCorrect(TopicProperty topicProperty, string propertyName, params string[] values) { Assert.AreEqual(propertyName, topicProperty.Name, "Checking that topic property name was correct."); Assert.AreEqual(values.Length, topicProperty.Values.Count, "Checking that the correct number of values are present."); for (int i = 0; i < values.Length; i++) { Assert.AreEqual(values[i], topicProperty.Values[i].RawValue, string.Format("Checking that value {0} is correct.", i)); } }
public void LastValueNoValues() { TopicProperty property = new TopicProperty("Name"); Assert.IsNull(property.LastValue, "Checking that null is returned when the property has no values."); }
public void HasValueNegative() { TopicProperty property = new TopicProperty("Name"); Assert.IsFalse(property.HasValue, "Checking that a property with no value returns the correct result."); }
public void AsListMultipleValues() { TopicProperty property = new TopicProperty("Name"); property.Values.Add(new TopicPropertyValue("List, of multiple, values")); AssertValueListCorrect(property.AsList(), "List", "of multiple", "values"); }