Пример #1
0
        public List <Event> Parse(string eventsToAdd)
        {
            List <Event> parsedEvents = new List <Event>();

            //substring getter
            SubstringBetweenFlagsGetter substringGetter = new SubstringBetweenFlagsGetter();
            //deserializer
            JsonEventParser jsonEventParser = new JsonEventParser();

            while (true)
            {
                string eventFromLogKey = substringGetter.Get(eventsToAdd, "key:", ",");
                string jsonFromLog     = substringGetter.Get(eventsToAdd, "json:", "\n");

                if ((String.IsNullOrEmpty(eventFromLogKey)) || (String.IsNullOrEmpty(jsonFromLog)))
                {
                    break;
                }

                int startingJsonIndex = eventsToAdd.IndexOf("json:");
                int endingJsonIndex   = startingJsonIndex + jsonFromLog.Length;

                eventsToAdd = eventsToAdd.Remove(0, endingJsonIndex);

                bool isTooBigEvent = jsonFromLog.Length > MaxAllowedJsonLength;

                if (!isTooBigEvent)
                {
                    Event parsedEvent = jsonEventParser.Parse(eventFromLogKey, jsonFromLog);
                    parsedEvents.Add(parsedEvent);
                }
            }
            return(parsedEvents);
        }
Пример #2
0
        public void Get_SearchBetweenKeyInStringWithKeyWithEndingFlag_ReturnKeyValue()
        {
            //Arrange
            SubstringBetweenFlagsGetter substringBetweenFlagsGetter = new SubstringBetweenFlagsGetter();

            //Act
            string Result = substringBetweenFlagsGetter.Get("Text contains key:_IamGreatestKey, good luck", "key:", ",");

            //Assert
            Assert.Equal("_IamGreatestKey", Result);
        }
Пример #3
0
        public void Get_SomeParamIsEmptyOrNoSuchProperty_ReturnNoParam(string inputLine, string startFlag, string endFlag)
        {
            //Arrange
            SubstringBetweenFlagsGetter substringBetweenFlagsGetter = new SubstringBetweenFlagsGetter();

            //Act
            string Result = substringBetweenFlagsGetter.Get(inputLine, startFlag, endFlag);

            //Assert
            Assert.Equal("", Result);
        }