Пример #1
0
		internal XmlElement CreateResultsNode(XmlDocument xmlDocument, WsScanRule scanRule, WsMatchInRangeCollection results)
		{
			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 == results)
				throw new WsException("Null results passed in");
			
			XmlElement resultsNode = xmlDocument.CreateElement("results");
			foreach(WsMatchInRange result in results)
			{
				foreach(string key in result.Matches.Keys)
				{
					XmlElement resultNode = CreateResultNode(xmlDocument, scanRule, result, key);
					if(null != resultNode)
						resultsNode.AppendChild(resultNode);
				}
			}

			if(0 == resultsNode.ChildNodes.Count)
				return null;

			return resultsNode;
		}
		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");
		}
		public void TestAddNull()
		{
			WsMatchInRangeCollection matchInRangeCollection = new WsMatchInRangeCollection();
			Assert.AreEqual(0, matchInRangeCollection.Count);
			matchInRangeCollection.Add(null);
			Assert.AreEqual(0, matchInRangeCollection.Count);
		}
		internal WsMatchInRangeCollection GetMatches(RangeTypes type, string condition)
		{
			WsMatchInRangeCollection matches = new WsMatchInRangeCollection();
			foreach(WsMatchInRange match in this.List)
			{
				if(type == match.RangeType && condition == match.Condition)
					matches.Add(match);
			}
			return matches;
		}
Пример #6
0
		public string BuildContent(WsMatchInRangeCollection results)
		{
			XmlDocument xmlDocument = new XmlDocument();
			XmlElement rootNode = xmlDocument.CreateElement("DISRules");
			xmlDocument.AppendChild(rootNode);

			foreach(WsScanRule scanRule in m_scanRules)
			{
				XmlElement ruleNode = CreateRuleNode(xmlDocument, scanRule);
				
				XmlElement resultsNode = CreateResultsNode(xmlDocument, scanRule, results);
				if(null != resultsNode)
					ruleNode.AppendChild(resultsNode);

				if(false == ruleNode.IsEmpty)
					rootNode.AppendChild(ruleNode);
			}
			return xmlDocument.OuterXml;
		}
Пример #7
0
		public void TestBuildContentNoContext()
		{
			const string expectedContent = 
					  "<DISRules>" +
					  "<rule name=\"Find some\" level=\"High\">" +
					  "<results>" +
					  "<result match=\"Some\" context=\"Paragraph\" count=\"2\" />" +
					  "<result match=\"some\" context=\"Comment\" count=\"3\" />" +
					  "</results>" +
					  "</rule>" +
					  "</DISRules>";

			WsScanRules scanRules = new WsScanRules();
			WsScanRule findSomeRule = new WsScanRule("Rule 1", "Find some", "some", RuleLevels.High);
			scanRules.Add(findSomeRule);

			WsMatchInRangeCollection results = new WsMatchInRangeCollection();
			
			ArrayList someDataInParagraph = new ArrayList();
			someDataInParagraph.Add("Some");
			someDataInParagraph.Add("Some");
			results.Add(new WsMatchInRange(RangeTypes.Paragraph, findSomeRule.Condition, someDataInParagraph));

			ArrayList someDataInComment = new ArrayList();
			someDataInComment.Add("some");
			someDataInComment.Add("some");
			someDataInComment.Add("some");
			results.Add(new WsMatchInRange(RangeTypes.Comment, findSomeRule.Condition, someDataInComment));

			XMLContentBuilder xmlContentBuilder = new XMLContentBuilder(scanRules);
			string xmlContent = xmlContentBuilder.BuildContent(results);
			Assert.AreEqual(expectedContent, xmlContent);
		}
Пример #8
0
		public void TestBuildContent()
		{
			string expectedContent = 
					  "<DISRules>" +
					  "<rule name=\"Find some\" level=\"High\">" +
					  "<results>" +
					  "<result match=\"some\" context=\"Paragraph\" count=\"1\" />" +
					  "<result match=\"Some\" context=\"Paragraph\" count=\"2\" />" +
					  "</results>" +
					  "</rule>" +
					  "<rule name=\"Find that\" level=\"Medium\">" +
					  "<results>" +
					  "<result match=\"that\" context=\"Paragraph\" count=\"3\" />" +
					  "</results>" +
					  "</rule>" +
					  "</DISRules>";

			if (Is64Bit())
				expectedContent = "<DISRules>" +
					  "<rule name=\"Find some\" level=\"High\">" +
					  "<results>" +
					  "<result match=\"Some\" context=\"Paragraph\" count=\"2\" />" +
					  "<result match=\"some\" context=\"Paragraph\" count=\"1\" />" +
					  "</results>" +
					  "</rule>" +
					  "<rule name=\"Find that\" level=\"Medium\">" +
					  "<results>" +
					  "<result match=\"that\" context=\"Paragraph\" count=\"3\" />" +
					  "</results>" +
					  "</rule>" +
					  "</DISRules>";



			WsScanRules scanRules = new WsScanRules();
			WsScanRule findSomeRule = new WsScanRule("Rule 1", "Find some", "some", RuleLevels.High);
			findSomeRule.Ranges.Add(RangeTypes.Paragraph);
			scanRules.Add(findSomeRule);

			WsScanRule findThatRule = new WsScanRule("Rule 2", "Find that", "that", RuleLevels.Medium);
			findThatRule.Ranges.Add(RangeTypes.Paragraph);
			scanRules.Add(findThatRule);

			WsMatchInRangeCollection results = new WsMatchInRangeCollection();
			
			ArrayList someData = new ArrayList();
			someData.Add("Some");
			someData.Add("Some");
			someData.Add("some");
			results.Add(new WsMatchInRange(RangeTypes.Paragraph, findSomeRule.Condition, someData));

			ArrayList thatData = new ArrayList();
			thatData.Add("that");
			thatData.Add("that");
			thatData.Add("that");
			results.Add(new WsMatchInRange(RangeTypes.Paragraph, findThatRule.Condition, thatData));

			XMLContentBuilder xmlContentBuilder = new XMLContentBuilder(scanRules);
			string xmlContent = xmlContentBuilder.BuildContent(results);
			Assert.AreEqual(expectedContent, xmlContent);
		}
Пример #9
0
		public void TestCreateResultsNodeNoResultsName()
		{
			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);
			
			WsMatchInRangeCollection results = new WsMatchInRangeCollection();
			ArrayList someData = new ArrayList();
			someData.Add("Some");
			someData.Add("Some");
			someData.Add("some");
			results.Add(new WsMatchInRange(RangeTypes.Paragraph, findSomeRule.Condition, someData));

			string expectedResultsXml = 
					  "<results>" + 
					  "<result match=\"some\" context=\"Paragraph\" count=\"1\" />" +
					  "<result match=\"Some\" context=\"Paragraph\" count=\"2\" />" +
					  "</results>";

			if (Is64Bit())
				expectedResultsXml =
					  "<results>" +
					  "<result match=\"Some\" context=\"Paragraph\" count=\"2\" />" +
					  "<result match=\"some\" context=\"Paragraph\" count=\"1\" />" +
					  "</results>";

			
			XmlDocument xmlDocument = new XmlDocument();
			XmlElement resultsElement = xmlContentBuilder.CreateResultsNode(xmlDocument, findSomeRule, results);
			Assert.AreEqual(expectedResultsXml, resultsElement.OuterXml);
		}
Пример #10
0
		public void TestCreateResultsNodeNoResults()
		{
			WsScanRules scanRules = new WsScanRules();
			WsScanRule scanRule = new WsScanRule("Find some", "FindSomeIndex", "some", RuleLevels.High);
			scanRules.Add(scanRule);
			XmlDocument xmlDocument = new XmlDocument();
			XMLContentBuilder xmlContentBuilder = new XMLContentBuilder(scanRules);
			
			WsMatchInRangeCollection results = new WsMatchInRangeCollection();
			XmlElement resultsElement = xmlContentBuilder.CreateResultsNode(xmlDocument, scanRule, results);
			Assert.IsNull(resultsElement, "Expected a null results node for no results");
		}
Пример #11
0
		public void TestCreateResultsNodeNullScanRule()
		{
			WsScanRules scanRules = new WsScanRules();
			WsScanRule scanRule = new WsScanRule("Find some", "FindSomeIndex", "some", RuleLevels.High);
			scanRules.Add(scanRule);
			XmlDocument xmlDocument = new XmlDocument();
			XMLContentBuilder xmlContentBuilder = new XMLContentBuilder(scanRules);
			WsMatchInRangeCollection results = new WsMatchInRangeCollection();
			xmlContentBuilder.CreateResultsNode(xmlDocument, null, results);
		}
Пример #12
0
		internal WsResultSet(WsMatchInRangeCollection list)
		{
			m_matches = list;
		}