Exemplo n.º 1
0
		internal XmlElement CreateResultNode(XmlDocument xmlDocument, WsScanRule scanRule, WsMatchInRange result, string key)
		{
			if(null == xmlDocument)
				throw new WsException("Null xml document pointer passed in");

			if(null == scanRule)
				throw new WsException("Null scan rule passed in");

			if(null == result)
				throw new WsException("Null result passed in");

			if(scanRule.Condition != result.Condition)
				return null;

			if((scanRule.Ranges.Count != 0) && (!scanRule.Ranges.Contains(result.RangeType)))
				return null;

			XmlElement resultNode = xmlDocument.CreateElement("result");
			XmlAttribute matchAttribute = xmlDocument.CreateAttribute("match");
			matchAttribute.Value = key;
			resultNode.Attributes.Append(matchAttribute);

			XmlAttribute contextAttribute = xmlDocument.CreateAttribute("context");
			contextAttribute.Value = result.RangeType.ToString();
			resultNode.Attributes.Append(contextAttribute);

			XmlAttribute countAttribute = xmlDocument.CreateAttribute("count");
			countAttribute.Value = Convert.ToString(result.Matches[key]);
			resultNode.Attributes.Append(countAttribute);

			return resultNode;
		}
		public void TestAddMultipleConditionsForSingleRange()
		{
			WsMatchInRangeCollection matchInRangeCollection = new WsMatchInRangeCollection();
			Assert.AreEqual(0, matchInRangeCollection.Count);
			ArrayList matchesInParagraph = new ArrayList();
			const string scanText = "Test text";
			const string testConditionIndex = "TestTextIndex";
			matchesInParagraph.Add(scanText);
			matchesInParagraph.Add(scanText);
			WsMatchInRange matchInParagraphRange = new WsMatchInRange(RangeTypes.Paragraph, testConditionIndex, matchesInParagraph);
			matchInRangeCollection.Add(matchInParagraphRange);
			Assert.AreEqual(1, matchInRangeCollection.Count, "Expected the collection count to be one");
			Assert.AreEqual(2, matchInRangeCollection.TotalMatchCount, "Expected the total match count to be two");

			ArrayList matchesInParagraphRange2 = new ArrayList();
			const string scanText2 = "This is more text to find";
			const string testConditionIndex2 = "TestTextIndex2";
			matchesInParagraphRange2.Add(scanText2);
			WsMatchInRange matchInParagraphRange2 = new WsMatchInRange(RangeTypes.Paragraph, testConditionIndex2, matchesInParagraphRange2);
			matchInRangeCollection.Add(matchInParagraphRange2);

			Assert.AreEqual(2, matchInRangeCollection.Count, "Expected the collection count to be two, one for paragraph for first condition and one for paragraph for second condition");
			Assert.AreEqual(1, matchInRangeCollection.GetMatches(RangeTypes.Paragraph, testConditionIndex).Count, "Expected the collection count for paragraphs of first condition to be one");
			Assert.AreEqual(1, matchInRangeCollection.GetMatches(RangeTypes.Paragraph, testConditionIndex2).Count, "Expected the collection count for paragraphs of second condition to be one");

			Assert.AreEqual(3, matchInRangeCollection.TotalMatchCount, "Expected the total match count to be three");
			Assert.AreEqual(2, matchInRangeCollection.GetMatches(RangeTypes.Paragraph, testConditionIndex).TotalMatchCount, "Expected the match count for first condition to be two");
			Assert.AreEqual(1, matchInRangeCollection.GetMatches(RangeTypes.Paragraph, testConditionIndex2).TotalMatchCount, "Expected the match count for second condition to be one");
		}
		public void TestAddSingleConditionForMultipleRanges()
		{
			WsMatchInRangeCollection matchInRangeCollection = new WsMatchInRangeCollection();
			Assert.AreEqual(0, matchInRangeCollection.Count);
			ArrayList matchesInParagraph = new ArrayList();
			const string scanText = "Test text";
			const string testConditionIndex = "TestTextIndex";
			matchesInParagraph.Add(scanText);
			matchesInParagraph.Add(scanText);
			WsMatchInRange matchInParagraphRange = new WsMatchInRange(RangeTypes.Paragraph, testConditionIndex, matchesInParagraph);
			matchInRangeCollection.Add(matchInParagraphRange);
			Assert.AreEqual(1, matchInRangeCollection.Count, "Expected the collection count to be one");
			Assert.AreEqual(2, matchInRangeCollection.TotalMatchCount, "Expected the total match count to be two");

			ArrayList matchesInComment = new ArrayList();
			matchesInComment.Add(scanText);
			WsMatchInRange matchInCommentRange = new WsMatchInRange(RangeTypes.Comment, testConditionIndex, matchesInComment);
			matchInRangeCollection.Add(matchInCommentRange);

			Assert.AreEqual(2, matchInRangeCollection.Count, "Expected the collection count to be two, one for paragraph and one for comment");
			Assert.AreEqual(1, matchInRangeCollection.GetMatches(RangeTypes.Paragraph, testConditionIndex).Count, "Expected the collection count for paragraphs to be one");
			Assert.AreEqual(1, matchInRangeCollection.GetMatches(RangeTypes.Comment, testConditionIndex).Count, "Expected the collection count for comments to be one");

			Assert.AreEqual(3, matchInRangeCollection.TotalMatchCount, "Expected the total match count to be three");
			Assert.AreEqual(2, matchInRangeCollection.GetMatches(RangeTypes.Paragraph, testConditionIndex).TotalMatchCount, "Expected the match count for comments to be two");
			Assert.AreEqual(1, matchInRangeCollection.GetMatches(RangeTypes.Comment, testConditionIndex).TotalMatchCount, "Expected the match count for comments to be one");
		}
Exemplo n.º 4
0
		public void TestConstructor()
		{
			const string condition = "FindSomeCondition";
			const string testString = "some text";
			ArrayList matches = new ArrayList();
			matches.Add(testString);
			matches.Add(testString);
			WsMatchInRange matchInRange = new WsMatchInRange(RangeTypes.Paragraph, condition, matches);
			Assert.AreEqual(RangeTypes.Paragraph, matchInRange.RangeType);
			Assert.AreEqual(condition, matchInRange.Condition);
			Assert.AreEqual(2, matchInRange.TotalMatchCount);
			Assert.AreEqual(1, matchInRange.Matches.Count);
			Assert.AreEqual(2, matchInRange.Matches[testString]);
		}
Exemplo n.º 5
0
		public void TestCreateResultNodeNullScanRule()
		{
			const string findSomeIndex = "FindSomeIndex";
			WsScanRules scanRules = new WsScanRules();
			WsScanRule findSomeRule = new WsScanRule("Find some", findSomeIndex, "some", RuleLevels.High);
			scanRules.Add(findSomeRule);

			XMLContentBuilder xmlContentBuilder = new XMLContentBuilder(scanRules);
			WsMatchInRange result = new WsMatchInRange(RangeTypes.Paragraph, findSomeIndex, new ArrayList());
			XmlDocument xmlDocument = new XmlDocument();
			xmlContentBuilder.CreateResultNode(xmlDocument, null, result, "");
		}
Exemplo n.º 6
0
		public void TestCreateResultNodeInContext()
		{
			const string findSomeIndex = "FindSomeIndex";
			WsScanRules scanRules = new WsScanRules();
			WsScanRule findSomeRule = new WsScanRule("Find some", findSomeIndex, "some", RuleLevels.High);
			findSomeRule.Ranges.Add(RangeTypes.Paragraph);
			scanRules.Add(findSomeRule);

			XMLContentBuilder xmlContentBuilder = new XMLContentBuilder(scanRules);
			
			ArrayList someData = new ArrayList();
			someData.Add("Some");
			someData.Add("Some");

			XmlDocument xmlDocument = new XmlDocument();
			WsMatchInRange result = new WsMatchInRange(RangeTypes.Comment, findSomeIndex, someData);
			XmlElement resultNode = xmlContentBuilder.CreateResultNode(xmlDocument, findSomeRule, result, "Some");
			Assert.IsNull(resultNode, "Expected a null instance for a key that does not match the search data that is out of context");
		}
Exemplo n.º 7
0
		public void TestCreateResultNode()
		{
			const string findSomeIndex = "FindSomeIndex";
			WsScanRules scanRules = new WsScanRules();
			WsScanRule findSomeRule = new WsScanRule("Find some", findSomeIndex, "some", RuleLevels.High);
			findSomeRule.Ranges.Add(RangeTypes.Paragraph);
			scanRules.Add(findSomeRule);

			XMLContentBuilder xmlContentBuilder = new XMLContentBuilder(scanRules);
			
			ArrayList someData = new ArrayList();
			someData.Add("Some");
			someData.Add("Some");
			someData.Add("some");

			const string expectedResult1 = "<result match=\"Some\" context=\"Paragraph\" count=\"2\" />";
			const string expectedResult2 = "<result match=\"some\" context=\"Paragraph\" count=\"1\" />";

			XmlDocument xmlDocument = new XmlDocument();
			WsMatchInRange result = new WsMatchInRange(RangeTypes.Paragraph, findSomeIndex, someData);
			XmlElement resultNode = xmlContentBuilder.CreateResultNode(xmlDocument, findSomeRule, result, "Some");
			Assert.AreEqual(expectedResult1, resultNode.OuterXml);
			resultNode = xmlContentBuilder.CreateResultNode(xmlDocument, findSomeRule, result, "some");
			Assert.AreEqual(expectedResult2, resultNode.OuterXml);
		}