예제 #1
0
        public void ScanWithAllPassingFiles()
        {
            List <string> filePaths = new List <string>();

            filePaths.Add(Utilities.CreateTempTxtFile(""));
            filePaths.Add(Utilities.CreateTempTxtFile("some text"));
            filePaths.Add(Utilities.CreateTempTxtFile("some more text"));

            Scanner_Accessor accessor = new Scanner_Accessor();

            IMultiFileScanResult result = accessor.Scan(filePaths, new List <ITermTable>());

            Assert.AreEqual(result.Attempted, 3, "Attempted != 3 in return value from Scanner.Scanner.Scan with 3 passing files.");
            Assert.AreEqual(result.FailedScan, 0, "FailedScan != 0 in return value from Scanner.Scanner.Scan with 3 passing files.");
            Assert.AreEqual(result.PassedScan, 3, "PassedScan != 3 in return value from Scanner.Scanner.Scan with 3 passing files.");
            Assert.AreEqual(result.UnableToScan, 0, "UnableToScan != 0 in return value from Scanner.Scanner.Scan with 3 passing files.");
            Assert.IsNotNull(result.Results, "Results property was null in return value from Scanner.Scanner.Scan with 3 passing files.");

            int count = 0;

            foreach (IScanResult scanResult in result.Results)
            {
                ++count;
            }
            Assert.AreEqual(count, 3, "Results list did not contain 3 entries in return value from Scanner.Scanner.Scan with 3 passing files.");
        }
예제 #2
0
        public void ScanWithNullList()
        {
            Scanner_Accessor accessor = new Scanner_Accessor();

            bool thrown = Utilities.HasFunctionThrown <ArgumentException>(delegate { accessor.Scan(null, null); });

            Assert.IsTrue(thrown, "Scanner.Scanner.Scan did not throw ArgumentNullException with null list.");
        }
예제 #3
0
        public void ScanWithDifferentEncodings()
        {
            List <string> filePaths = new List <string>();

            filePaths.Add(Utilities.CreateTempTxtFile("first file", Encoding.Unicode));
            filePaths.Add(Utilities.CreateTempTxtFile("second file", Encoding.BigEndianUnicode));
            filePaths.Add(Utilities.CreateTempTxtFile("third file", Encoding.UTF32));
            filePaths.Add(Utilities.CreateTempTxtFile("fourth file", Encoding.UTF8));
            filePaths.Add(Utilities.CreateTempTxtFile("fifth file", Encoding.UTF7));
            filePaths.Add(Utilities.CreateTempTxtFile("sixth file", Encoding.ASCII));

            // TODO: what about different code pages within the ASCII encoding?

            List <ITermTable> termTables = new List <ITermTable>();

            MockTermTable table = new MockTermTable("file");

            table.AddSearchTerm(new MockTerm("first", 1, "class", "comment", "recommended", table));
            table.AddSearchTerm(new MockTerm("second", 1, "class", "comment", "recommended", table));
            table.AddSearchTerm(new MockTerm("third", 1, "class", "comment", "recommended", table));
            table.AddSearchTerm(new MockTerm("fourth", 1, "class", "comment", "recommended", table));
            table.AddSearchTerm(new MockTerm("fifth", 1, "class", "comment", "recommended", table));
            table.AddSearchTerm(new MockTerm("sixth", 1, "class", "comment", "recommended", table));

            termTables.Add(table);

            Scanner_Accessor accessor = new Scanner_Accessor();

            IMultiFileScanResult result = accessor.Scan(filePaths, termTables);

            Assert.AreEqual(6, result.Attempted, "Attempted count incorrect.");
            Assert.AreEqual(6, result.FailedScan, "FailedScan count incorrect.");
            Assert.AreEqual(0, result.PassedScan, "PassedScan count incorrect.");
            Assert.AreEqual(0, result.UnableToScan, "UnableToScan count incorrect.");

            int fileIndex = 0;

            foreach (IScanResult scanResult in result.Results)
            {
                int count = 0;
                foreach (IScanHit hits in scanResult.Results)
                {
                    ++count;
                }
                Assert.AreEqual(1, count, "Result " + fileIndex.ToString() + " did not have the expected number of hits.");
                ++fileIndex;
            }
        }
예제 #4
0
        public void ScanWithEmptyList()
        {
            Scanner_Accessor accessor = new Scanner_Accessor();

            IMultiFileScanResult result = accessor.Scan(new List <string>(), new List <ITermTable>());

            Assert.AreEqual(result.Attempted, 0, "Attempted != 0 in return value from Scanner.Scanner.Scan with empty list.");
            Assert.AreEqual(result.FailedScan, 0, "FailedScan != 0 in return value from Scanner.Scanner.Scan with empty list.");
            Assert.AreEqual(result.PassedScan, 0, "PassedScan != 0 in return value from Scanner.Scanner.Scan with empty list.");
            Assert.AreEqual(result.UnableToScan, 0, "UnableToScan != 0 in return value from Scanner.Scanner.Scan with empty list.");
            Assert.IsNotNull(result.Results, "Results property was null in return value from Scanner.Scanner.Scan with empty list.");

            int count = 0;

            foreach (IScanResult scanResult in result.Results)
            {
                ++count;
            }
            Assert.AreEqual(count, 0, "Results list was not empty in return value from Scanner.Scanner.Scan with empty list.");
        }