/// <summary> /// Add multiple files. The files are checked - if there are problems, abstract functions (that might present dialogs /// to the user) get called. /// </summary> /// <param name="files"> /// A list of files. If this contains a directory or files are not printable, an error message will be /// shown. /// </param> /// <returns>true, if all files are printable</returns> public bool AddFiles(IEnumerable <string> files) { var printerName = _printerHelper.GetApplicableclawPDFPrinter(_clawPdfPrinter); foreach (var f in files) { _printCommands.Add(new PrintCommand(f, printerName)); } var directories = _printCommands.FindAll(p => Directory.Exists(p.Filename)); if (directories.Count > 0) { DirectoriesNotSupportedHint(); return(false); } var unprintable = _printCommands.FindAll(p => !p.IsPrintable); if (unprintable.Any()) { UnprintableFilesHint(unprintable); return(false); } return(true); }
public void Group_WithPprintableFile_PrintReturnsTrue() { var printCommandGroup = new PrintCommandGroup(); printCommandGroup.ProcessWrapperFactory = new MockProcessWrapperFactory(true); const string printer = "SomePrinter"; printCommandGroup.Add(new PrintCommand(TempFileHelper.CreateTempFile("PrintCommandGroup", "test.txt"), printer)); Assert.IsTrue(printCommandGroup.PrintAll()); }
public void Group_WithUnprintableFile_PrintThrowsException() { var printCommandGroup = new PrintCommandGroup(); printCommandGroup.ProcessWrapperFactory = new MockProcessWrapperFactory(true); const string printer = "SomePrinter"; printCommandGroup.Add(new PrintCommand(TempFileHelper.CreateTempFile("PrintCommandGroup", "test.invalid"), printer)); Assert.Throws <InvalidOperationException>(() => printCommandGroup.PrintAll()); }
public void Group_WithManyFiles_PrintsEveryFile() { var printCommandGroup = new PrintCommandGroup(); var factory = new MockProcessWrapperFactory(true); printCommandGroup.ProcessWrapperFactory = factory; const string printer = "SomePrinter"; printCommandGroup.Add(new PrintCommand(TempFileHelper.CreateTempFile("PrintCommandGroup", "test1.txt"), printer)); printCommandGroup.Add(new PrintCommand(TempFileHelper.CreateTempFile("PrintCommandGroup", "test2.txt"), printer)); printCommandGroup.Add(new PrintCommand(TempFileHelper.CreateTempFile("PrintCommandGroup", "test3.txt"), printer)); printCommandGroup.PrintAll(); foreach (var mock in factory.CreatedMocks) { Assert.IsTrue(mock.WasStarted, "Print Process was not started for " + mock.StartInfo.FileName); } Assert.AreEqual(printCommandGroup.Count(), factory.CreatedMocks.Count); }
public void Group_WithManyFilesAndOneUnprintableFile_PrintThrowsExceptionWithoutPrintingOneFile() { var printCommandGroup = new PrintCommandGroup(); var factory = new MockProcessWrapperFactory(true); printCommandGroup.ProcessWrapperFactory = factory; const string printer = "SomePrinter"; printCommandGroup.Add(new PrintCommand(TempFileHelper.CreateTempFile("PrintCommandGroup", "test.txt"), printer)); printCommandGroup.Add(new PrintCommand(TempFileHelper.CreateTempFile("PrintCommandGroup", "test.invalid"), printer)); try { printCommandGroup.PrintAll(); } catch (InvalidOperationException) { } Assert.IsEmpty(factory.CreatedMocks); }