// [Test] public void TestPdfDoesntOverwriteOtherFileWithSameName() { var attachment = new ProtectAttachment(TestUtils.CreateAttachment("FilesWithSameName.zip", "FilesWithSameName.zip", "1")); var attachments = new ObservableCollection<IProtectAttachment>() { attachment }; var actionQueue = new ActionQueue(); bool discoveryCompleted = false; bool appliedAllActions = false; actionQueue.StatusUpdate += (sender, args) => { if (args.Status == PropertyNames.DiscoveryCompleted) { discoveryCompleted = true; } if (args.Status == PropertyNames.AppliedAllActions) { appliedAllActions = true; } }; actionQueue.Discover(attachments.ToList()); SpinWait.SpinUntil(() => discoveryCompleted, 90000); Assert.IsTrue(discoveryCompleted, "Discovery failed to complete."); var xlsx = attachment.Children.First(x => x.FileName.Contains(".xlsx")); var options = new Dictionary<string, dynamic> {{PropertyNames.PdfFormat, PropertyValues.PdfA}}; var pdf = WorkshareTaskFactory.CreatePdfTask(xlsx, options); var task = new TaskRepack(attachments); actionQueue.ApplyTasks(new List<IWorkshareTask>() { pdf, task }); SpinWait.SpinUntil(() => appliedAllActions, 90000); Assert.IsTrue(appliedAllActions, "Failed to apply all actions within the time limit"); new Workshare.API.Cleaning.OfficeApplicationCacheControl().ReleaseOfficeApplications(); VerifyFilesAreNotEqual(attachment.FileName); SpinWait.SpinUntil(TestUtils.HasOfficeShutDown, 60000); }
public void TestSuspendResume_01() { var attachments = new List<IProtectAttachment>() { new ProtectAttachment(TestUtils.CreateAttachment("5DocStats2BuiltInProps.docx", "5DocStats2BuiltInProps.docx", "1")), new ProtectAttachment(TestUtils.CreateAttachment("5DocStats2BuiltInProps.docx", "5DocStats2BuiltInProps.docx", "2")), new ProtectAttachment(TestUtils.CreateAttachment("5DocStats2BuiltInProps.docx", "5DocStats2BuiltInProps.docx", "3")), new ProtectAttachment(TestUtils.CreateAttachment("5DocStats2BuiltInProps.docx", "5DocStats2BuiltInProps.docx", "4")), new ProtectAttachment(TestUtils.CreateAttachment("5DocStats2BuiltInProps.docx", "5DocStats2BuiltInProps.docx", "5")), new ProtectAttachment(TestUtils.CreateAttachment("5DocStats2BuiltInProps.docx", "5DocStats2BuiltInProps.docx", "6")), new ProtectAttachment(TestUtils.CreateAttachment("5DocStats2BuiltInProps.docx", "5DocStats2BuiltInProps.docx", "7")), new ProtectAttachment(TestUtils.CreateAttachment("5DocStats2BuiltInProps.docx", "5DocStats2BuiltInProps.docx", "9")), new ProtectAttachment(TestUtils.CreateAttachment("5DocStats2BuiltInProps.docx", "5DocStats2BuiltInProps.docx", "9")), new ProtectAttachment(TestUtils.CreateAttachment("5DocStats2BuiltInProps.docx", "5DocStats2BuiltInProps.docx", "10")) }; var actionQueue = new ActionQueue(); bool discoveryCompleted = false; actionQueue.StatusUpdate += (sender, args) => { if (args.Status == PropertyNames.DiscoveryCompleted) { discoveryCompleted = true; } }; actionQueue.Discover(attachments); actionQueue.Controller.Suspend(); Thread.Sleep(2000); actionQueue.Controller.Resume(); Thread.Sleep(2000); actionQueue.Controller.Suspend(); Thread.Sleep(2000); actionQueue.Controller.Resume(); Thread.Sleep(2000); actionQueue.Controller.Suspend(); Thread.Sleep(2000); actionQueue.Controller.Resume(); SpinWait.SpinUntil(() => discoveryCompleted, 30000); Assert.IsTrue(discoveryCompleted); foreach (var attachment in attachments) { Assert.IsTrue(attachment.HasMetadata); } }
public void TestSuspendResume_02() { var attachments = new List<IProtectAttachment>() { new ProtectAttachment(TestUtils.CreateAttachment("5DocStats2BuiltInProps.docx", "5DocStats2BuiltInProps.docx", "1")), new ProtectAttachment(TestUtils.CreateAttachment("5DocStats2BuiltInProps.docx", "5DocStats2BuiltInProps.docx", "2")), new ProtectAttachment(TestUtils.CreateAttachment("5DocStats2BuiltInProps.docx", "5DocStats2BuiltInProps.docx", "3")), new ProtectAttachment(TestUtils.CreateAttachment("5DocStats2BuiltInProps.docx", "5DocStats2BuiltInProps.docx", "4")), }; var actionQueue = new ActionQueue(); bool discoveryCompleted = false; actionQueue.StatusUpdate += (sender, args) => { if (args.Status == PropertyNames.DiscoveryCompleted) { discoveryCompleted = true; } }; actionQueue.Discover(attachments); actionQueue.Controller.Suspend(); SpinWait.SpinUntil(() => discoveryCompleted, 10000); Assert.IsFalse(discoveryCompleted); }
public void TestCancellation_02() { var attachments = new List<IProtectAttachment>() { new ProtectAttachment(TestUtils.CreateAttachment("Office 2010 docx risk elements15.zip", "Office 2010 docx risk elements15.zip", "1")), }; var actionQueue = new ActionQueue(); bool discoveryCompleted = false; actionQueue.StatusUpdate += (sender, args) => { if (args.Status == PropertyNames.DiscoveryCompleted) { discoveryCompleted = true; } }; actionQueue.Discover(attachments); Thread.Sleep(2000); actionQueue.Controller.Cancel(); SpinWait.SpinUntil(() => actionQueue.Controller.IsCancellationPending, 10000); Assert.IsFalse(discoveryCompleted); attachments = new List<IProtectAttachment>() { new ProtectAttachment(TestUtils.CreateAttachment("5DocStats2BuiltInProps.docx", "5DocStats2BuiltInProps.docx", "1")), }; actionQueue.Discover(attachments); SpinWait.SpinUntil(() => discoveryCompleted, 5000); Assert.IsFalse(discoveryCompleted); }
//[Test] public void TestExpandRepackMaintainsDirectoryStructure_03() // Bug fix { var zipAttachment = new ProtectAttachment(TestUtils.CreateAttachment("small.zip", "small.zip", "1")); var expectedDirectoryStructure = GetZipFileDirectoryStructure(zipAttachment.FileName); var attachments = new ObservableCollection<IProtectAttachment>() { zipAttachment }; var actionQueue = new ActionQueue(); bool discoveryCompleted = false; bool appliedAllActions = false; actionQueue.StatusUpdate += (sender, args) => { if (args.Status == PropertyNames.DiscoveryCompleted) { discoveryCompleted = true; } if (args.Status == PropertyNames.AppliedAllActions) { appliedAllActions = true; } }; actionQueue.Discover(attachments.ToList()); SpinWait.SpinUntil(() => discoveryCompleted, 90000); Assert.IsTrue(discoveryCompleted); var options = new Dictionary<string, dynamic> { { PropertyNames.PdfFormat, PropertyValues.PdfA } }; var tasks = WorkshareTaskFactory.Create(attachments, options, null); actionQueue.ApplyTasks(tasks); SpinWait.SpinUntil(() => appliedAllActions, 120000); Assert.IsTrue(appliedAllActions, "Failed to apply all actions within the time limit"); var flattenedList = TestUtils.Flatten(zipAttachment.Children, new List<FileType>() { FileType.Email }); foreach (var item in flattenedList) { Assert.IsTrue(item.FileType == FileType.PDFDocument); } zipAttachment.Children.Clear(); VerifyFilesAreOfType(zipAttachment, FileType.PDFDocument); var currentStructure = GetZipFileDirectoryStructure(zipAttachment.FileName); var result = expectedDirectoryStructure.Except(currentStructure).ToList(); Assert.IsTrue(result.Count == 0); new Workshare.API.Cleaning.OfficeApplicationCacheControl().ReleaseOfficeApplications(); SpinWait.SpinUntil(TestUtils.HasOfficeShutDown, 60000); }
// [Test] public void TestConvertCollectionToPdf_02() // Another bug fix { var zipAttachment = new ProtectAttachment(TestUtils.CreateAttachment("small.zip", "small.zip", "1")); var passwordAttachment = new ProtectAttachment(TestUtils.CreateAttachment("password.docx", "password.docx", "1")); var attachments = new ObservableCollection<IProtectAttachment>() { passwordAttachment, zipAttachment }; var actionQueue = new ActionQueue(); bool discoveryCompleted = false; bool appliedAllActions = false; actionQueue.StatusUpdate += (sender, args) => { if (args.Status == PropertyNames.DiscoveryCompleted) { discoveryCompleted = true; } if (args.Status == PropertyNames.AppliedAllActions) { appliedAllActions = true; } }; actionQueue.Discover(attachments.ToList()); SpinWait.SpinUntil(() => discoveryCompleted, 90000); Assert.IsTrue(discoveryCompleted, "Discovery failed to complete."); var options = new Dictionary<string, dynamic> { { PropertyNames.PdfFormat, PropertyValues.PdfA } }; var tasks = WorkshareTaskFactory.Create(attachments, options, null); actionQueue.ApplyTasks(tasks); SpinWait.SpinUntil(() => appliedAllActions, 120000); Assert.IsTrue(appliedAllActions, "Failed to apply all actions within the time limit"); var flattenedList = TestUtils.Flatten(zipAttachment.Children, new List<FileType>() { FileType.Email }); foreach (var item in flattenedList) { Assert.IsTrue(item.FileType == FileType.PDFDocument); } zipAttachment.Children.Clear(); VerifyFilesAreOfType(zipAttachment, FileType.PDFDocument); new Workshare.API.Cleaning.OfficeApplicationCacheControl().ReleaseOfficeApplications(); SpinWait.SpinUntil(TestUtils.HasOfficeShutDown, 60000); }