示例#1
0
        public override void Run()
        {
            if (!File.Exists(FullFilePath))
            {
                throw new AssertionException("File Not Found");
            }

            var doc = knownDocuments[FullFilePath];

            IEnumerable <XmlNode> nodeInstances = GetNodesWithName(XmlPath, doc);

            var nodeCount = nodeInstances.Count();

            if (nodeCount > MaximumOccurrences)
            {
                throw new AssertionException(
                          string.Format("{1} instance{2} of {0} found where no more than {3} {4} expected", XmlPath,
                                        nodeCount, nodeCount.pl("", "s"), MaximumOccurrences,
                                        MaximumOccurrences.pl("was", "were")));
            }

            if (nodeCount < MinimumOccurrences)
            {
                throw new AssertionException(
                          string.Format("{1} instance{2} of {0} found where at least {3} {4} expected", XmlPath,
                                        nodeCount, nodeCount.pl("", "s"), MinimumOccurrences,
                                        MinimumOccurrences.pl("was", "were")));
            }

            var nodesWithMatchingAttributes = new List <XmlNode>();

            nodesWithMatchingAttributes.AddRange(nodeInstances);
            nodeInstances = nodeInstances.Where(n => n.InnerXml == ExpectedValue);

            var nodesCount = nodeInstances.Count();

            if (nodesCount == 0)
            {
                throw new AssertionException(string.Format("No instances of {0} found with the expected content",
                                                           XmlPath));
            }

            if (nodesCount > 1)
            {
                throw new AssertionException(
                          string.Format(
                              "{0} instances of {1} found with the expected content where no more than 1 was expected",
                              nodesCount, XmlPath));
            }
        }
示例#2
0
        public override void Run()
        {
            if (!File.Exists(FullFilePath))
            {
                throw new AssertionException("File Not Found");
            }
            var doc = knownDocuments[FullFilePath];

            var nodeInstances = GetNodesWithName(XmlPath, doc);

            if (nodeInstances.Count > MaximumOccurrences)
            {
                throw new AssertionException(
                          string.Format("{1} instance{2} of {0} found where no more than {3} {4} expected", XmlPath,
                                        nodeInstances.Count, nodeInstances.Count.pl("", "s"), MaximumOccurrences,
                                        MaximumOccurrences.pl("was", "were")));
            }

            if (nodeInstances.Count < MinimumOccurrences)
            {
                throw new AssertionException(
                          string.Format("{1} instance{2} of {0} found where at least {3} {4} expected", XmlPath,
                                        nodeInstances.Count, nodeInstances.Count.pl("", "s"), MinimumOccurrences,
                                        MinimumOccurrences.pl("was", "were")));
            }

            var matchingAttributeCounts = nodeInstances.Select(GetMatchingAttributesCount).ToList();

            if (ExpectedValues.Count > 0 && matchingAttributeCounts.Count(c => c == ExpectedValues.Count) == 0)
            {
                throw new AssertionException(
                          string.Format("No instances of {0} found with all expected attributes matching (most was {1})",
                                        XmlPath,
                                        matchingAttributeCounts.Max()));
            }
        }