public void WritesFormattedMessageToTextWriter(string text, object[] expectedSeverityAndMessages) { var parser = new SeverityPrefixParser(); List<object> actualSeverityAndMessages = new List<object>(); foreach (string line in text.Split('\n')) { LogSeverity severity; string message; bool hasSeverity = parser.ParseLine(line, out severity, out message); actualSeverityAndMessages.Add(new object[] { severity, message }); Assert.AreEqual(line.StartsWith("["), hasSeverity, "Should indicate whether the line had its own severity indication."); } Assert.AreElementsEqual(expectedSeverityAndMessages, actualSeverityAndMessages); }
public void LoggerAndParserAreSymmetrical(LogSeverity severity) { const string message = "Message"; StringWriter writer = new StringWriter(); writer.NewLine = "\n"; var logger = new SeverityPrefixLogger(new TextLogger(writer)); logger.Log(severity, message); var parser = new SeverityPrefixParser(); LogSeverity parsedSeverity; string parsedMessage; bool hasSeverity = parser.ParseLine(writer.ToString().Trim(), out parsedSeverity, out parsedMessage); Assert.AreEqual(severity, parsedSeverity); Assert.AreEqual(message, parsedMessage); Assert.IsTrue(hasSeverity); }