public void TestPropertiesValidOnCleaner() { Redactor r = new Redactor(); Assert.IsNotNull(r); Assert.IsNotNull(r.ExcludedFieldTypes); Assert.IsNotNull(r.ExcludedMetadataTypes); IMetadataTypeCollection imdtel = r.ExcludedMetadataTypes; Assert.AreEqual(0, imdtel.Count); Assert.AreEqual(0, r.ExcludedFieldTypes.Count); }
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); Redactor r = new Redactor(); // set up to redact only hidden text and track changes r.ExcludedMetadataTypes.Fill();// Exclude cleaning of all metadata types r.ExcludedMetadataTypes.Remove(MetadataType.HiddenText); r.ExcludedMetadataTypes.Remove(MetadataType.TrackedChange); string targetFileName = Path.GetTempFileName(); r.RedactFileTo(filename, targetFileName); }
public void TestRtfFile() { string testDoc = TestUtils.TestFileUtils.MakeRootPathAbsolute(@"Projects\Workshare.API\Workshare.API.Tests\TestDocs\test.rtf"); using (TempFile tf = new TempFile(testDoc)) { Redactor r = new Redactor(); try { r.RedactFileTo(testDoc, "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(InvalidDataException), e); } } }
public void TestRelativePath3() { string outputDoc = TestUtils.TestFileUtils.MakeRootPathAbsolute(@"Projects\Workshare.API\Workshare.API.Tests\TestDocs\output.doc"); IRedactor c = new Redactor(); c.RedactFileTo("test.doc", outputDoc); }
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)) { Redactor r = new Redactor(); try { r.RedactFileTo(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); Redactor r = new Redactor(); try { r.RedactFileTo(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 TestRedactTo() { 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; Redactor r = new Redactor(); r.RedactFileTo(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 redaction to change the file contents"); } } }
public void TestActualRedact() { string testDoc = TestUtils.TestFileUtils.MakeRootPathAbsolute(@"Projects\Workshare.API\Workshare.API.Tests\TestDocs\test.doc"); using (TempFile tf = new TempFile(testDoc)) { string initialHash = tf.MD5Sum; Redactor r = new Redactor(); r.RedactFile(tf.FilePath); string newHash = tf.MD5Sum; Assert.AreNotEqual(initialHash, newHash, "We expected the redaction to change the file contents"); } }
public void TestRelativePath() { IRedactor c = new Redactor(); c.RedactFile("test.doc"); }
public void TestDiscoverAndRedact() { Discoverer d = new Discoverer(); string testDoc = TestUtils.TestFileUtils.MakeRootPathAbsolute(@"Projects\Workshare.API\Workshare.API.Tests\TestDocs\test.doc"); using (var result = d.DiscoverDocument(testDoc)) { Assert.IsTrue(result.HasMetadataOfType(MetadataType.HiddenText)); Assert.IsTrue(result.HasMetadataOfType(MetadataType.TrackedChange)); Assert.IsTrue(result.HasMetadataOfType(MetadataType.Header)); Assert.IsTrue(result.HasMetadataOfType(MetadataType.Footer)); Assert.IsTrue(result.HasMetadataOfType(MetadataType.DocumentStatistic)); Assert.IsTrue(result.HasMetadataOfType(MetadataType.BuiltInProperty)); Assert.IsTrue(result.HasMetadataOfType(MetadataType.Reviewer)); Assert.IsNotNull(result.GetItemsForType(MetadataType.HiddenText)); Assert.IsNull(result.GetItemsForType(MetadataType.HiddenSlide)); } string cleanedDoc = Path.GetTempFileName(); Redactor r = new Redactor(); r.RedactFileTo(testDoc, cleanedDoc); using (var result = d.DiscoverDocument(cleanedDoc)) { Assert.IsFalse(result.HasMetadataOfType(MetadataType.HiddenText)); Assert.IsFalse(result.HasMetadataOfType(MetadataType.TrackedChange)); Assert.IsTrue(result.HasMetadataOfType(MetadataType.Header), "redact cannot clean headers"); Assert.IsTrue(result.HasMetadataOfType(MetadataType.Footer), "redact cannot clean footers"); Assert.IsFalse(result.HasMetadataOfType(MetadataType.DocumentStatistic)); Assert.IsFalse(result.HasMetadataOfType(MetadataType.BuiltInProperty)); Assert.IsFalse(result.HasMetadataOfType(MetadataType.Reviewer)); } }