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); }
/// <summary> /// Prints all files in the list. /// </summary> /// <returns>true, if all files could be printed</returns> public bool PrintAll() { if (string.IsNullOrEmpty(_clawPdfPrinter)) { _logger.Error("No clawPDF is installed."); return(false); } var printerHelper = new PrinterHelper(); var requiresDefaultPrinter = _printCommands.RequiresDefaultPrinter; var defaultPrinter = printerHelper.GetDefaultPrinter(); try { if (requiresDefaultPrinter) { if (SettingsHelper.Settings.ApplicationSettings.AskSwitchDefaultPrinter) { if (!QuerySwitchDefaultPrinter()) { return(false); } } PrinterHelper.SetDefaultPrinter(_clawPdfPrinter); } return(_printCommands.PrintAll()); } finally { if (requiresDefaultPrinter) { PrinterHelper.SetDefaultPrinter(defaultPrinter); } } }
public void Group_WithEmptyList_PrintReturnsTrue() { var printCommandGroup = new PrintCommandGroup(); Assert.IsTrue(printCommandGroup.PrintAll()); }