public void TestSimpleClean() { string testDoc = TestUtils.TestFileUtils.MakeRootPathAbsolute(@"Projects\Workshare.API\Workshare.API.Tests\TestDocs\test.doc"); using (TempFile tf = new TempFile(testDoc)) { string initialHash = tf.MD5Sum; IOfficeCleaner c = new OfficeCleaner(); c.CleanFile(tf.FilePath); string newHash = tf.MD5Sum; Assert.AreNotEqual(initialHash, newHash, "We expected the Cleanion to change the file contents"); } }
public static void Execute(IActiveDocument activeDocument, IPublishPdfOptions options) { var instance = new OfficeCleaner(); instance.ExcludedMetadataTypes = new MetadataTypeCollection(options.ExcludedMetadata); instance.ExcludedFieldTypes = new FieldTypeCollection(PolicyBridge.GetCommonExcludedFieldTypes()); instance.AdvancedFieldExclusionList = PolicyBridge.GetAdvancedExcludedFields(); instance.CustomPropertyExclusionList = PolicyBridge.GetAdvancedExcludedCustomProperties(); instance.DocumentVariableExclusionList = PolicyBridge.GetAdvancedExcludedDocumentVariables(); instance.FieldDeletionList = PolicyBridge.GetFieldDeletetionList(); instance.TreatFootNotesAsMetadata = PolicyBridge.TreatFootNotesAsMetadata(); instance.CleanFile(activeDocument.CurrentSnapShot); }
public void TestIndexing() { OfficeCleaner c = new OfficeCleaner(); IMetadataTypeCollection mdtel = c.ExcludedMetadataTypes; mdtel.Add(MetadataType.AttachedTemplate); mdtel.Add(MetadataType.AutoVersion); mdtel.Add(MetadataType.BuiltInProperty); Assert.AreEqual(3, mdtel.Count); Assert.AreEqual(MetadataType.AttachedTemplate, mdtel[0]); Assert.AreEqual(MetadataType.AutoVersion, mdtel[1]); Assert.AreEqual(MetadataType.BuiltInProperty, mdtel[2]); }
public void TestFillAndClean() { OfficeCleaner c = new OfficeCleaner(); c.ExcludedMetadataTypes.Fill(); Assert.AreNotEqual(0, c.ExcludedMetadataTypes.Count); Assert.AreEqual(Enum.GetValues(typeof(MetadataType)).Length, c.ExcludedMetadataTypes.Count); c.ExcludedMetadataTypes.Clear(); Assert.AreEqual(0, c.ExcludedMetadataTypes.Count); c.ExcludedFieldTypes.Fill(); Assert.AreNotEqual(0, c.ExcludedFieldTypes.Count); Assert.AreEqual(Enum.GetValues(typeof(CommonFieldType)).Length, c.ExcludedFieldTypes.Count); c.ExcludedFieldTypes.Clear(); Assert.AreEqual(0, c.ExcludedFieldTypes.Count); }
public void TestAddRemoveContains() { OfficeCleaner c = new OfficeCleaner(); IMetadataTypeCollection mdtel = c.ExcludedMetadataTypes; Assert.IsFalse(mdtel.Contains(MetadataType.AttachedTemplate)); mdtel.Add(MetadataType.AttachedTemplate); Assert.IsTrue(mdtel.Contains(MetadataType.AttachedTemplate)); mdtel.Add(MetadataType.AttachedTemplate); // do not expect a throw Assert.IsTrue(mdtel.Contains(MetadataType.AttachedTemplate)); mdtel.Remove(MetadataType.AttachedTemplate); Assert.IsFalse(mdtel.Contains(MetadataType.AttachedTemplate)); mdtel.Remove(MetadataType.AttachedTemplate); // do not expect a throw Assert.IsFalse(mdtel.Contains(MetadataType.AttachedTemplate)); }
public void TestSimpleCleanRtf() { string testDoc = TestUtils.TestFileUtils.MakeRootPathAbsolute(@"Projects\Workshare.API\Workshare.API.Tests\TestDocs\test.rtf"); using (TempFile tf = new TempFile(testDoc)) { string initialHash = tf.MD5Sum; IOfficeCleaner c = new OfficeCleaner(); c.CleanFile(tf.FilePath); string newHash = tf.MD5Sum; Assert.AreNotEqual(initialHash, newHash, "We expected the Cleanion to change the file contents"); Discoverer d = new Discoverer(); using (var result = d.DiscoverDocument(tf.FilePath)) { Assert.IsFalse(result.HasMetadataOfType(MetadataType.TrackedChange)); } } }
public static void Main(string[] args) { // ensure path to file is absolute, not relative string filename = args[0]; if (!Path.IsPathRooted(filename)) filename = Path.Combine(Environment.CurrentDirectory, filename); OfficeCleaner c = new OfficeCleaner(); // set up to redact only fields and comments c.ExcludedMetadataTypes.Fill();// Exclude cleaning of all metadata types c.ExcludedMetadataTypes.Remove(MetadataType.Comment); // re-enable cleaning of desired types c.ExcludedMetadataTypes.Remove(MetadataType.Field); // exclude cleaning of certain field types c.ExcludedFieldTypes.Add(CommonFieldType.Numbering); c.ExcludedFieldTypes.Add(CommonFieldType.Formula); c.ExcludedFieldTypes.Add(CommonFieldType.Reference); string targetFileName = Path.GetTempFileName(); c.CleanFileTo(filename, targetFileName); }
public void TestSimpleCleanTo() { string testDoc = TestUtils.TestFileUtils.MakeRootPathAbsolute(@"Projects\Workshare.API\Workshare.API.Tests\TestDocs\test.docx"); using (TempFile tf = new TempFile(testDoc)) { using (TempFile dest = new TempFile()) { File.Delete(dest.FilePath); string initialHash = tf.MD5Sum; IOfficeCleaner c = new OfficeCleaner(); c.CleanFileTo(tf.FilePath, dest.FilePath); Assert.IsTrue(File.Exists(dest.FilePath), "We expected the dest file to be created"); string newHash = dest.MD5Sum; Assert.AreNotEqual(initialHash, newHash, "We expected the Cleanion to change the file contents"); } } }
public void TestRelativePath3() { string outputDoc = TestUtils.TestFileUtils.MakeRootPathAbsolute(@"Projects\Workshare.API\Workshare.API.Tests\TestDocs\output.doc"); IOfficeCleaner c = new OfficeCleaner(); c.CleanFileTo("test.doc", outputDoc); }
public void TestBadOutputFile() { string testDoc = TestUtils.TestFileUtils.MakeRootPathAbsolute(@"Projects\Workshare.API\Workshare.API.Tests\TestDocs\test.docx"); using (TempFile tf = new TempFile(testDoc)) { OfficeCleaner r = new OfficeCleaner(); try { r.CleanFileTo(tf.FilePath, "q:\\blah\\no\\existy\\here.doc"); Assert.Fail("We expected not to get here - should have thrown an exception"); } catch (Exception e) { //Assert.IsInstanceOf(typeof(IOException), e); } } }
public void TestLockedOutputFile() { string testDoc = TestUtils.TestFileUtils.MakeRootPathAbsolute(@"Projects\Workshare.API\Workshare.API.Tests\TestDocs\test.docx"); using (TempFile tf = new TempFile(testDoc)) { using (TempFile dest = new TempFile()) { using (Stream s = File.Open(dest.FilePath, FileMode.Open, FileAccess.ReadWrite)) { OfficeCleaner r = new OfficeCleaner(); try { r.CleanFileTo(tf.FilePath, dest.FilePath); Assert.Fail("We expected not to get here - should have thrown an exception"); } catch (Exception e) { //Assert.IsInstanceOf(typeof(IOException), e); } } } } }
public void TestMissingInputFile() { string testDoc = TestUtils.TestFileUtils.MakeRootPathAbsolute(@"Projects\Workshare.API\Workshare.API.Tests\TestDocs\i_do_not_exist.docx"); using (TempFile dest = new TempFile()) { File.Delete(dest.FilePath); OfficeCleaner r = new OfficeCleaner(); try { r.CleanFileTo(testDoc, dest.FilePath); Assert.Fail("We expected not to get here - should have thrown an exception"); } catch (Exception e) { Assert.IsInstanceOf(typeof(FileNotFoundException), e); } Assert.IsFalse(File.Exists(dest.FilePath), "We expected the dest file not to be created"); } }
public void TestCleanToWithPPTApp() { return; Microsoft.Office.Interop.PowerPoint.Application app = new Microsoft.Office.Interop.PowerPoint.Application(); try { AppCountMonitor monitor = new AppCountMonitor("powerpnt"); string testDoc = TestUtils.TestFileUtils.MakeRootPathAbsolute(@"Projects\Workshare.API\Workshare.API.Tests\TestDocs\test.ppt"); using (TempFile tf = new TempFile(testDoc)) { using (TempFile dest = new TempFile()) { File.Delete(dest.FilePath); string initialHash = tf.MD5Sum; IOfficeCleaner c = new OfficeCleaner(); c.CleanFileTo(tf.FilePath, dest.FilePath, app); Assert.IsTrue(File.Exists(dest.FilePath), "We expected the dest file to be created"); string newHash = dest.MD5Sum; Assert.AreNotEqual(initialHash, newHash, "We expected the Cleanion to change the file contents"); } } Assert.IsFalse(monitor.SeenMoreInstances(), "Additional instances of PowerPoint were created during the test run - that means it didn't use the provided instance"); } finally { object oFalse = false; app.Quit(); Marshal.ReleaseComObject(app); } }
public void TestRelativePath() { IOfficeCleaner c = new OfficeCleaner(); c.CleanFile("test.doc"); }