Пример #1
0
        public void TestRegexLookupInFileType()
        {
            Workshare.Policy.Condition.ContentAnalysis analysis = new Workshare.Policy.Condition.ContentAnalysis();
            string regEx = @"(The quick brown fox jumped over the lazy dog.){1}";
            string[] context = { "Paragraph", "HeaderOrFooter", "Comment", "Footnote", "Endnote", "TrackChange", "TextBox", "Reviewer", "HiddenText", "SmallText", "WhiteText", "AttachedTemplate", "SmartTag", "Version", "AutoVersion", "Field", "Hyperlink", "RoutingSlip", "Variable", "HiddenSlide", "SpeakerNote" };
            string[] fileTypes = { "WordDocument" };

            string filename = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\ContentAnalysis.Tests\docs\TestDocument1.doc");
            string description = "Originally a test document used by one of FCS Lite's tests.";
            using (IFile testFile = Workshare.Policy.Engine.FileFactory.Create(filename, description))
            {
                System.Collections.DictionaryEntry[] foundRegex = analysis.RegExLookupInFileType(testFile, fileTypes, regEx, context);

                Assert.AreEqual(1, foundRegex.Length);
            }

            //right file type, wrong content
            filename = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\ContentAnalysis.Tests\docs\testlookup.doc");
            description = "File doesn't contain any of the stuff we're searching for";
            using (IFile testFile = Workshare.Policy.Engine.FileFactory.Create(filename, description))
            {
                System.Collections.DictionaryEntry[] foundRegex = analysis.RegExLookupInFileType(testFile, fileTypes, regEx, context);
                Assert.AreEqual(0, foundRegex.Length);
            }

            //wrong file type, right content
            filename = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\ContentAnalysis.Tests\docs\TestDocument.txt");
            description = "File contains things we're looking for";
            using (IFile testFile = Workshare.Policy.Engine.FileFactory.Create(filename, description))
            {
                System.Collections.DictionaryEntry[] foundRegex = analysis.RegExLookupInFileType(testFile, fileTypes, regEx, context);
                Assert.AreEqual(0, foundRegex.Length);
            }

            //now change file type and repeat with previous doc - right file type, right content
            fileTypes[0] = "TextDocument";
            using (IFile testFile = Workshare.Policy.Engine.FileFactory.Create(filename, description))
            {
                System.Collections.DictionaryEntry[] foundRegex = analysis.RegExLookupInFileType(testFile, fileTypes, regEx, context);
                Assert.AreEqual(1, foundRegex.Length);
            }                
        
        
        }