public static void AddDiv4FinalMessage(this ControlCollection controls, TestXmlFile testXmlFile, int errorCount)
 {
     controls.AddDiv("<br/>&nbsp;&nbsp;&nbsp;&nbsp;(Всего: " + testXmlFile.TestRules.Sum(_ => _.TestSents.Count) + " штук, &nbsp;" + ((errorCount == 0) ? "Ошибок НЕТ)" : "Ошибок: " + errorCount + " штук)"));
 }
        protected void runTestButton_Click(object sender, EventArgs e)
        {
            #region [.set controls state.]
            runTestButton.Visible         = false;
            testFileUpload1.Visible       = false;
            testFileUpload2.Visible       = false;
            showOnlyErrorCheckBox.Visible = false;
            againHyperLink1.Visible       = true;
            againHyperLink2.Visible       = true;
            //repeatLinkButton1    .Visible = true;
            //repeatLinkButton2    .Visible = true;
            backHyperLink2.Visible = true;
            #endregion

            #region [.read text-file.]
            var testXmlFile = new TestXmlFile(TestFileContent);
            #endregion

            #region [.test.]
            var errorCount = 0;
            foreach (var rule in testXmlFile.TestRules)
            {
                foreach (var sent in rule.TestSents)
                {
                    try
                    {
                        var result = GetDigestOutputResult(sent);

                        #region [check SNTFINAL.]
                        var subsentNodes = result.OutputXml.ToXDocument().XPathSelectElements("//SUB_SENT").ToArray();   // || "TEXT/SENT/SUB_SENT"
                        if (sent.SNTFINALs.Count != subsentNodes.Length)
                        {
                            throw (new TestException("Число подпредложений в строке не равно числу атрибутов-@SNTFINAL в тестовом файле."));
                        }
                        for (var i = 0; i < sent.SNTFINALs.Count; i++)
                        {
                            var snt1 = subsentNodes[i].GetAttributeSNTFINAL();
                            var snt2 = sent.SNTFINALs[i];
                            if (snt1 != snt2)
                            {
                                throw (new TestException("Подпредложение " + subsentNodes[i].Value.ToHtmlBold().InSingleQuotes() +
                                                         " получило @SNTFINAL=" + snt1.ToString().ToHtmlBold().InSingleQuotes() +
                                                         ", должно быть @SNTFINAL=" + snt2.ToString().ToHtmlBold().InSingleQuotes()));
                            }
                        }
                        #endregion

                        #region [.check operate-rule-order.]
                        if (result.OperateRulesNames != null)
                        {
                            var indexofStartSearch = 0;
                            foreach (var id in rule.Ids)
                            {
                                var name = result.OperateRulesNames
                                           .Skip(indexofStartSearch)
                                           .FirstOrDefault(n => n.StartsWith(id, StringComparison.InvariantCultureIgnoreCase));
                                if (name != null)
                                {
                                    var indexofStartSearchNew = indexofStartSearch +
                                                                result.OperateRulesNames.Skip(indexofStartSearch).ToList().IndexOf(name);
                                    //result.OperateRulesNames.IndexOf( name );

                                    for (int i = indexofStartSearch; i < indexofStartSearchNew; i++)
                                    {
                                        var value = result.OperateRulesNames[i];
                                        if (3 <= value.Length &&
                                            100 <= value.Substring(0, 3).TryConvert2Int().GetValueOrDefault())
                                        {
                                            //found who's don't shoul be found!!!!!
                                            throw (new TestException("Сработало правило " + value.InSingleQuotes().ToHtmlBold() + ", которое не должно было сработать: " + result.OperateRulesNames.ToHtml()));
                                        }
                                    }

                                    indexofStartSearch = indexofStartSearchNew + 1;
                                }
                                else
                                {
                                    //not found!!!!!!!
                                    throw (new TestException("Правило " + id.InSingleQuotes().ToHtmlBold() + " не найдено среди сработавших правил: " + result.OperateRulesNames.ToHtml()));
                                }
                            }
                        }
                        #endregion

                        if (showOnlyErrorCheckBox.Checked)
                        {
                            continue;
                        }

                        resultDiv.Controls.AddDiv4OkMessage(rule, sent);
                    }
                    catch (Exception ex)
                    {
                        #region
                        errorCount++;

                        resultDiv.Controls.AddDiv4ExceptionMessage(ex, rule, sent);

                        if (ex is CommunicationException)   //EndpointNotFoundException)
                        {
                            resultDiv.Controls.AddDiv("....выполниение теста прервано....");
                            return;
                        }
                        #endregion
                    }
                    resultDiv.Controls.AddHr();
                }
            }

            resultDiv.Controls.AddDiv4FinalMessage(testXmlFile, errorCount);
            #endregion
        }