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;
		}
예제 #4
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);
		}
예제 #5
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);
		}
예제 #6
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);
		}
		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");
		}