Exemplo n.º 1
0
        public void width_is_the_text_width()
        {
            var text = "a bunch of text";
            var line = new PlainLine(text);

            line.Width.ShouldEqual(text.Length);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
 public string GetSingleLineMessage(PlainLine line)
 {
     return(GetMessageBuilder(line, null)?.ToString());
 }