Exemple #1
0
        /// <summary>
        /// This testcase checks if the webparser is still working
        /// </summary>
        private void CheckWebParserStillWorking()
        {
            // Add start entry to report
            if (OnUpdateGuiEvent != null)
            {
                OnUpdateGuiEvent(this, new GuiUpdateEventArgs(GuiUpdateState.TestCaseStart, new List <string> {
                    System.Reflection.MethodBase.GetCurrentMethod().Name
                }));
            }

            // Create RegexList
            RegExList regexList = new RegExList(@"FirstRegex", new RegexElement(@"RegexString1", 1, true, false, new List <RegexOptions>()
            {
                RegexOptions.None
            }));

            regexList.Add(@"SecondRegex", new RegexElement(@"RegexString2", 1, false, false, new List <RegexOptions>()
            {
                RegexOptions.Singleline, RegexOptions.IgnoreCase
            }));
            // Set regexlist to webparser
            _webParser.RegexList = regexList;
            // Set website to webparser
            _webParser.WebSite = @"http://www.google.com";
            // Start parsing
            _webParser.StartParsing();
        }
Exemple #2
0
        public void Test_1_CheckParserAlreadyBusy()
        {
            // 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 Parser
            if (Uri.TryCreate(@"http://www.google.com", UriKind.Absolute, out var uriResult))
            {
                webSiteUrl = uriResult;
            }

            // Create RegexList
            var regexList = new RegExList(@"FirstRegex",
                                          new RegexElement(@"RegexString1", 1, true, new List <RegexOptions>()
            {
                RegexOptions.None
            }));

            regexList.Add(@"SecondRegex",
                          new RegexElement(@"RegexString2", 1, false,
                                           new List <RegexOptions>()
            {
                RegexOptions.Singleline, RegexOptions.IgnoreCase
            }));

            // 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
            newParser.StartParsing();
            Thread.Sleep(25);

            // Try to start parsing again
            var result = newParser.StartParsing();

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

            ShowParsingErrorCodes(receivedEventsCodes, receivedEventsWebContent);

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