Esempio n. 1
0
        public Task <RuleCheckResult> CheckRuleAsync(IWordDocument document)
        {
            var words  = _wordMatcher.MatchWords(document, WordPrefix);
            var tables = document.Tables.Where(f => f.Description.PlainDescription.EndsWith(TableDescriptionSuffix))
                         .ToList();

            if (!tables.Any())
            {
                return(Task.FromResult(RuleCheckResult.CreateFailure(RuleName, $"Table {WordPrefix} not found")));
            }

            if (tables.Count > 1)
            {
                return(Task.FromResult(RuleCheckResult.CreateFailure(RuleName, $"More than one Table {WordPrefix} found")));
            }

            var table = tables.Single();

            var tableEntries = table
                               .Cells
                               .Where(f => f.ColumnIndex == 1)
                               .Skip(1)
                               .Select(f => f.Words.Single())
                               .Select(f => f.Characters.Text)
                               .ToList();

            if (words.Count != tableEntries.Count())
            {
                return(Task.FromResult(RuleCheckResult.CreateFailure(RuleName, $"Found {words.Count} words, but {tableEntries.Count} table entries")));
            }

            for (var i = 0; i < words.Count; i++)
            {
                var word       = words.ElementAt(i).Value;
                var tableValue = $"[{tableEntries.ElementAt(i)}]";

                if (word != tableValue)
                {
                    return(Task.FromResult(RuleCheckResult.CreateFailure(RuleName, $"Found {word} word, but {tableValue} in table")));
                }
            }

            return(Task.FromResult(RuleCheckResult.CreatePassed(RuleName)));
        }
        public Task <RuleCheckResult> CheckRuleAsync(IWordDocument document)
        {
            var matches = _wordMatcher.MatchWords(document, ElementPrefix);
            var numbers = new List <int>();

            foreach (var matchingWord in matches)
            {
                var numStr = matchingWord.Groups.Single(f => f.Name == WordMatcher.NumberGroupName).Value;
                var num    = int.Parse(numStr);
                numbers.Add(num);
            }

            for (var i = 0; i < numbers.Count; i++)
            {
                var expectedLinkNumber = i + 1;

                if (numbers.ElementAt(i) != expectedLinkNumber)
                {
                    return(Task.FromResult(RuleCheckResult.CreateFailure(RuleName, $"{numbers.ElementAt(i)} not matching")));
                }
            }

            return(Task.FromResult(RuleCheckResult.CreatePassed(RuleName)));
        }