示例#1
0
        public void Test_6_CheckParserSuccessful()
        {
            // Create parser
            var newParser = new Parser.Parser();
            // Create list for the received events
            var receivedEventsCodes      = new List <DataTypes.ParserErrorCodes>();
            var receivedEventsWebContent = new List <string>();

            // WebSiteUrl for the parser
            Uri webSiteUrl = null;

            // Set website to the Parser
            if (Uri.TryCreate(@"http://tbarth.eu/sunnyconnectoranalyzer", UriKind.Absolute, out var uriResult))
            {
                webSiteUrl = uriResult;
            }

            // Create regex list
            var regexList = new RegExList(@"Gesamt",
                                          new RegexElement(@">Gesamt-(.*?)<", -1, false, new List <RegexOptions>()
            {
                RegexOptions.None
            }));

            // Set parsing value to the parser
            newParser.ParsingValues = new ParsingValues(webSiteUrl, Encoding.UTF8.ToString(), regexList);

            // Create delegate function which adds the received events to the list
            newParser.OnParserUpdate += delegate(object sender, DataTypes.OnParserUpdateEventArgs e)
            {
                receivedEventsCodes.Add(e.ParserInfoState.LastErrorCode);
                receivedEventsWebContent.Add(e.ParserInfoState.WebSiteContentAsString);
            };

            // Start parsing
            var result = newParser.StartParsing();

            // Check if the start was not successful
            Assert.AreEqual(true, result);

            // Wait for the parsing result with a 5s timeout
            var counter = 0;

            while (counter < 500 &&
                   receivedEventsCodes.FindIndex(x => x == DataTypes.ParserErrorCodes.Finished) < 0)
            {
                Thread.Sleep(10);
                counter++;
            }

            ShowParsingErrorCodes(receivedEventsCodes, receivedEventsWebContent);

            // Check if the Finished event has been signaled
            Assert.GreaterOrEqual(receivedEventsCodes.FindIndex(x => x == DataTypes.ParserErrorCodes.Finished), 0);
        }