Exemplo n.º 1
0
        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());
        }
Exemplo n.º 2
0
        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());
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        /// <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);
                }
            }
        }
Exemplo n.º 6
0
        public void Group_WithEmptyList_PrintReturnsTrue()
        {
            var printCommandGroup = new PrintCommandGroup();

            Assert.IsTrue(printCommandGroup.PrintAll());
        }