Beispiel #1
0
        public void DoPrintJob_SuccessfulRunThrough()
        {
            // Arrange
            var printJobDetails = new PrintJob()
            {
                ApplicationOptions = new AppOptions[0],
                MustReturnCardData = false,
                PrintJobId         = "IndigoTest",
                ProductFields      = new ProductField[]
                {
                    new ProductField {
                        Deleted = false, Editable = false, Font = "Arial", FontColourRGB = 100, FontSize = 12, Height = 10, Label = "lbl", MappedName = "mpd",
                        MaxSize = 25, Name = "name", Printable = true, PrintSide = 0, ProductPrintFieldTypeId = 0, Value = Encoding.UTF8.GetBytes("SomeText"), Width = 23, X = 50, Y = 60
                    }
                }
            };
            var printJobresp = new Response <PrintJob>(true, "All good", printJobDetails, "sessionStr");

            var cardPrinting = Substitute.For <ICardPrinting>();

            cardPrinting.GetPrintJob(new Token(), new PrinterInfo()).ReturnsForAnyArgs(printJobresp);

            var cardPrintDetails = Substitute.For <ICardPrintDetails>();

            var printerDetailFactory = Substitute.For <IPrinterDetailFactory>();

            printerDetailFactory.Populate(new ProductField[0]).ReturnsForAnyArgs(cardPrintDetails);

            var printer = Substitute.For <IPrinter>();

            printer.Print("productBin", cardPrintDetails).ReturnsForAnyArgs(PrinterCodes.Success);
            printer.PrinterDetailFactory().Returns(printerDetailFactory);

            var cardPrintLogic = new CardPrintingLogic(cardPrinting, printer);

            var uiHandler = Substitute.For <UiUpdateEventHandler>();

            cardPrintLogic.UiUpdate += uiHandler;

            // Act
            cardPrintLogic.DoPrintJob();

            // Assert
            cardPrinting.ReceivedWithAnyArgs(1).GetPrintJob(new Token(), new PrinterInfo());
            printer.Received(1).Connect();
            printer.ReceivedWithAnyArgs(1).SetDeviceSettings(new Dictionary <string, string>());
            printer.Received(1).PrinterDetailFactory();
            printerDetailFactory.ReceivedWithAnyArgs(1).Populate(new ProductField[0]);
            printer.ReceivedWithAnyArgs(1).Print("productBin", cardPrintDetails);
            cardPrinting.ReceivedWithAnyArgs(1).PrintingComplete(new Token(), new CardData());
            cardPrinting.ReceivedWithAnyArgs(1).PrinterAnalytics(new Token());
            printer.Received(1).Disconnect();
            printer.Received(1).Dispose();

            uiHandler.ReceivedWithAnyArgs(4).Invoke(uiHandler, "", false, false, null);
        }
        public void DoPrintTest(object obj)
        {
            if (obj is IPrinter)
            {
                var printer = (IPrinter)obj;
                var ui      = TaskScheduler.FromCurrentSynchronizationContext();

                //TestPinOperations testPinOperations = new TestPinOperations(this);
                // NativeAppClient client = new NativeAppClient(StartupProperties.URL);
                TestPrintingOperations testPrintOps = new TestPrintingOperations();

                var cardPrintLogic = new CardPrintingLogic(testPrintOps, printer);
                cardPrintLogic.UiUpdate += new UiUpdateEventHandler(OnUiUpdate);

                CancellationTokenSource cts = new CancellationTokenSource();

                Task.Factory.StartNew(() =>
                {
                    try
                    {
                        cardPrintLogic.DoPrintJob();
                    }
                    catch (System.ServiceModel.EndpointNotFoundException enfex)
                    {
                        Error = enfex.Message;
                    }
                    catch (Exception ex)
                    {
                        Error = String.Format("{0}{1}{2}", ex.Message, Environment.NewLine, ex.ToString());
                    }
                    finally
                    {
                        printer.Dispose();
                    }
                },
                                      cancellationToken: CancellationToken.None,
                                      creationOptions: TaskCreationOptions.None,
                                      scheduler: TaskScheduler.Default)
                .ContinueWith(manifest =>
                {
                    CommandManager.InvalidateRequerySuggested();
                }, TaskScheduler.FromCurrentSynchronizationContext());
                //.ContinueWith(task =>
                //{

                //}, TaskContinuationOptions.NotOnFaulted);
            }
        }