コード例 #1
0
        public async Task Should_Throw_NotEnoughBlackException_When_Not_Enough_Black()
        {
            var printBlack = new PrintBlackCommand(_content,
                                                   paperLevelIndicator: new EnoughPaperLevelStub(),
                                                   blackLevelIndicator: new NotEnoughBlackLevelStub());

            await printBlack.Execute();
        }
コード例 #2
0
        public async Task Should_Throw_NoContentToPrintException_When_Content_Is_Empty_Byte_Array()
        {
            var printBlack = new PrintBlackCommand(
                content: new byte[0],
                paperLevelIndicator: new EnoughPaperLevelStub(),
                blackLevelIndicator: new EnoughBlackLevelStub());

            await printBlack.Execute();
        }
コード例 #3
0
        public async Task Should_Notify_On_Finish_When_Subscribed_To_Channel_PrinterDotPrintedDotCommandId_Only_When_CommandId_Is_Correct()
        {
            Guid incorrectId = Guid.Empty;
            bool areEqual    = false;

            var fn = new FakePrinterNotifier();

            var printBlack = new PrintBlackCommand(_content,
                                                   paperLevelIndicator: new EnoughPaperLevelStub(),
                                                   blackLevelIndicator: new EnoughBlackLevelStub(),
                                                   notifier: fn);

            await fn.Subscribe((message) => areEqual = true, PrinterNotificationTypes.Printed);

            await printBlack.Execute();

            Assert.IsFalse(areEqual);
        }
コード例 #4
0
        public async Task Should_Notify_On_Finish_When_Subscribed_To_Channel_PrinterDotPrintedDotCommandId()
        {
            bool areEqual = false;

            var fn = new FakePrinterNotifier();

            var printBlack = new PrintBlackCommand(_content,
                                                   paperLevelIndicator: new EnoughPaperLevelStub(),
                                                   blackLevelIndicator: new EnoughBlackLevelStub(),
                                                   notifier: fn);

            await fn.Subscribe((message) => areEqual = message.Equals($"Document {printBlack.Id} printed"),
                               PrinterNotificationTypes.Printed,
                               correlationId : printBlack.Id);

            await printBlack.Execute();

            Assert.IsTrue(areEqual);
        }
コード例 #5
0
        public void Should_Throw_InvalidConfigurationException_For_IBlackLevelIndicator_When_Null()
        {
            bool areEqual = false;

            try
            {
                var printBlack = new PrintBlackCommand(_content,
                                                       paperLevelIndicator: new EnoughPaperLevelStub(),
                                                       blackLevelIndicator: null);
            }
            catch (InvalidConfigurationException ex)
            {
                areEqual = ex.Message.Equals("There is no implementation for Printer.Indicators.IBlackLevelIndicator");
            }
            finally
            {
                Assert.IsTrue(areEqual);
            }
        }
コード例 #6
0
        public async Task Should_Execute_PrintBlackCommand_Without_Errors_When_Configured_Correctly_And_All_Level_Indicators_Are_Sufficient()
        {
            bool isSuccess = true;

            var printBlack = new PrintBlackCommand(_content,
                                                   paperLevelIndicator: new EnoughPaperLevelStub(),
                                                   blackLevelIndicator: new EnoughBlackLevelStub());

            try
            {
                await printBlack.Execute();
            }
            catch (Exception)
            {
                isSuccess = false;
            }
            finally
            {
                Assert.IsTrue(isSuccess);
            }
        }
コード例 #7
0
        private static async Task Print(string content)
        {
            byte[] c = System.Text.Encoding.UTF8.GetBytes(content);

            IPaperLevelIndicator pli = _printerType == "p" ?
                                       new ComplexPaperLevelIndicator((Int32)Math.Ceiling((double)(c.Length / 100))) as IPaperLevelIndicator :
                                       new SimplePaperLevelIndicator() as IPaperLevelIndicator;
            IBlackLevelIndicator bli = new SimpleBlackLevelIndicator();
            IPrinterNotifier     n   = null;
            IPrintCommand        cmd;

            if (_notifie == true)
            {
                n = new RabbitMq(_config);
            }

            try
            {
                if (_printType == "c")
                {
                    IColorLevelIndicator cli = _printerType == "p" ?
                                               new ComplexColorLevelIndicator() as IColorLevelIndicator :
                                               new SimpleColorLevelIndicator() as IColorLevelIndicator;
                    cmd = new PrintColorCommand(content: c,
                                                paperLevelIndicator: pli,
                                                blackLevelIndicator: bli,
                                                colorLevelIndicator: cli,
                                                notifier: n);
                }
                else
                {
                    cmd = new PrintBlackCommand(content: c,
                                                paperLevelIndicator: pli,
                                                blackLevelIndicator: bli,
                                                notifier: n);
                }
                if (!(n is null))
                {
                    await n.Subscribe((msg) =>
                    {
                        if (_printType == "c")
                        {
                            ForegroundColor = ConsoleColor.Cyan;
                        }

                        WriteLine(msg);
                        ResetColor();
                    }, PrinterNotificationTypes.Printed, cmd.Id);
                }

                await cmd.Execute();
            }
            catch (CannotConnectToNotificationServiceException)
            {
                Write("Can not connect to notification service. Do you want to proceed? [y/n]: ");
                var key = ReadKey();
                Write(NewLine);
                if (key.Key == ConsoleKey.Y)
                {
                    _notifie = false;
                    await Print(content);
                }
            }
            catch (ApplicationException ex)
            {
                WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                ForegroundColor = ConsoleColor.Magenta;
                WriteLine(ex.Message);
                ResetColor();

                ConsoleKeyInfo key;
                do
                {
                    key = ReadKey(intercept: false);
                }while (key.Key == ConsoleKey.Enter);

                await ProcessInput("exit");
            }
            finally
            {
                _processing  = false;
                _printerType = null;
                _printType   = null;
                _notifie     = null;
                n?.Dispose();
                await ProcessInput(ReadLine());
            }
        }
コード例 #8
0
 public async Task PrintBlack(byte[] content)
 {
     var command = new PrintBlackCommand(content, _pli, _bli, _n);
     await command.Execute();
 }