public void width_is_the_text_width() { var text = "a bunch of text"; var line = new PlainLine(text); line.Width.ShouldEqual(text.Length); }
private StringBuilder GetMessageBuilder(PlainLine line, List <PlainLine> spanningLines) { var sb = new StringBuilder(); var msgType = GetMessageType(line); var isFirstLineInMessage = msgType != null; var isSingleLineMessage = spanningLines == null; if (!isFirstLineInMessage) { if (isSingleLineMessage) { return(sb.Append(line.Line)); } } else { if (isSingleLineMessage) { return(sb.Append(GetMessage(line, msgType.Value))); } foreach (var item in spanningLines) { sb.Append(item.Line); } return(sb); } return(sb); }
public void write() { var text = "a bunch of text"; var line = new PlainLine(text); var writer = MockRepository.GenerateMock <TextWriter>(); line.Write(writer); writer.AssertWasCalled(x => x.WriteLine(text)); }
private string GetMessage(PlainLine line, LogType msgType) { string msgTypeString = $"[{msgType.ToString()}]"; var firstMessagCharacterIndex = line.Line.IndexOf(msgTypeString); if (firstMessagCharacterIndex == -1) { return(null); } return(line.Line.Substring(firstMessagCharacterIndex)); }
private LogType?GetMessageType(PlainLine line) { var match = new Regex(AppResources.DefaultMessageTypeRegexFormat); if (!match.IsMatch(line.Line)) { return(null); } var messageType = match.Match(line.Line).Value; LogType result; if (!Enum.TryParse(messageType, out result)) { return(null); } return(result); }
private DateTime?GetTimeStamp(PlainLine line) { var dateStamp = new Regex(AppResources.DefaultTimeStampRegexFormat); if (!dateStamp.IsMatch(line.Line)) { return(null); } var match = dateStamp.Match(line.Line).Value; DateTime result; //TODO : change substring with more efficient technique if (!DateTime.TryParseExact(match.Substring(1, match.Length - 2), AppResources.DefaultTimeStampFormat, null, System.Globalization.DateTimeStyles.AssumeLocal, out result)) { return(null); } return(result); }
public string GetSingleLineMessage(PlainLine line) { return(GetMessageBuilder(line, null)?.ToString()); }