Пример #1
0
		public void TestCreateRuleNullXmlDocument()
		{
			WsScanRules scanRules = new WsScanRules();
			XMLContentBuilder xmlContentBuilder = new XMLContentBuilder(scanRules);
			WsScanRule findSomeRule = new WsScanRule("Find some", "FindSomeIndex", "some", RuleLevels.High);
			xmlContentBuilder.CreateRuleNode(null, findSomeRule);
		}
Пример #2
0
		public void TestCreateNullRule()
		{
			WsScanRules scanRules = new WsScanRules();
			XmlDocument xmlDocument = new XmlDocument();
			XMLContentBuilder xmlContentBuilder = new XMLContentBuilder(scanRules);
			XmlElement ruleElement = xmlContentBuilder.CreateRuleNode(xmlDocument, null);
		}
Пример #3
0
		public void TestCreateRuleNode()
		{
			WsScanRules scanRules = new WsScanRules();
			WsScanRule findSomeRule = new WsScanRule("Test rule", "Find some", "some", RuleLevels.High);
			scanRules.Add(findSomeRule);

			XmlDocument xmlDocument = new XmlDocument();
			XMLContentBuilder xmlContentBuilder = new XMLContentBuilder(scanRules);
			XmlElement ruleElement = xmlContentBuilder.CreateRuleNode(xmlDocument, findSomeRule);
			Assert.IsNotNull(ruleElement);
			Assert.AreEqual("<rule name=\"Find some\" level=\"High\" />", ruleElement.OuterXml);
		}
Пример #4
0
		public string GetContent()
		{
			XMLContentBuilder xmlContentBuilder = new XMLContentBuilder(m_scanRules);
			return xmlContentBuilder.BuildContent(m_results);
		}
Пример #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, "");
		}
Пример #6
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);
		}
Пример #7
0
		public void TestBuildContentNoResults()
		{
			const string expectedContent = "<DISRules />";

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

			XMLContentBuilder xmlContentBuilder = new XMLContentBuilder(scanRules);
			string xmlContent = xmlContentBuilder.BuildContent(new WsMatchInRangeCollection());
			Assert.AreEqual(expectedContent, xmlContent);
		}
Пример #8
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);
		}
Пример #9
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);
		}
Пример #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 TestCreateNullResultsNode()
		{
			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);
			xmlContentBuilder.CreateResultsNode(xmlDocument, scanRule, null);
		}
Пример #12
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);
		}
Пример #13
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");
		}
Пример #14
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);
		}