Example #1
0
        public void PrinterConnectAndSetup_PrinterConnectsSuccessfully_PopulatedTokenReturned()
        {
            // Arrange
            IndigoDesktopApp.StartupProperties.Token = "StartupToken";
            var printingWebService = Substitute.For <ICardPrinting>();
            var printer            = Substitute.For <IPrinter>();

            printer.Connect().Returns(PrinterCodes.Success);
            printer.DeviceId.Returns("TheDeviceId");

            var cardPrintLogic = new CardPrintingLogic(printingWebService, printer);
            var validToken     = new Token
            {
                DeviceID    = "TheDeviceId",
                Session     = "StartupToken",
                Workstation = Environment.MachineName
            };

            // Act
            Token  token = null;
            string additionalInfo;
            var    success = cardPrintLogic.PrinterConnectAndSetup(out token, out additionalInfo);

            // Assert
            success.Should().BeTrue(because: "The printer object returned that it had connected successfully");
            token.Should().BeEquivalentTo(validToken);
        }
Example #2
0
        public void PrinterConnectAndSetup_PrinterDoesNotConnectSuccessfully_ShouldNotSubscribeToDeviceNotificationEvent()
        {
            // Arrange
            var printingWebService = Substitute.For <ICardPrinting>();

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

            printer.Connect().Returns(PrinterCodes.ConnectFailed);

            var cardPrintLogic = new CardPrintingLogic(printingWebService, printer);
            var uiHandler      = Substitute.For <UiUpdateEventHandler>();

            cardPrintLogic.UiUpdate += uiHandler;
            EventArgs args = new EventArgs();

            // Act
            Token  token = null;
            string additionalInfo;
            var    success = cardPrintLogic.PrinterConnectAndSetup(out token, out additionalInfo);

            //parameters: object sender, string message, bool isCritical, EventArgs e
            printer.OnDeviceNotifcation += Raise.Event <DeviceNotificationEventHandler>(printer, "TheMessage", false, args);

            // Assert
            success.Should().BeFalse(because: "The printer object returned that it had connected unsuccessfully");
            uiHandler.DidNotReceive().Invoke(printer, "TheMessage", false, false, args);
        }
Example #3
0
        public void PrinterConnectAndSetup_PrinterConnectsSuccessfully()
        {
            // Arrange
            var printingWebService = Substitute.For <ICardPrinting>();
            var printer            = Substitute.For <IPrinter>();

            printer.Connect().Returns(PrinterCodes.Success);

            var cardPrintLogic = new CardPrintingLogic(printingWebService, printer);

            // Act
            Token  token = null;
            string additionalInfo;
            var    success = cardPrintLogic.PrinterConnectAndSetup(out token, out additionalInfo);

            // Assert
            success.Should().BeTrue(because: "The printer object returned that it had connected successfully");
        }
Example #4
0
        public void PrinterConnectAndSetup_PrinterDoesNotConnectsSuccessfully_NullTokenReturned()
        {
            // Arrange
            IndigoDesktopApp.StartupProperties.Token = "StartupToken";
            var printingWebService = Substitute.For <ICardPrinting>();
            var printer            = Substitute.For <IPrinter>();

            printer.Connect().Returns(PrinterCodes.ConnectFailed);
            printer.DeviceId.Returns("TheDeviceId");

            var cardPrintLogic = new CardPrintingLogic(printingWebService, printer);

            // Act
            Token  token = null;
            string additionalInfo;
            var    success = cardPrintLogic.PrinterConnectAndSetup(out token, out additionalInfo);

            // Assert
            success.Should().BeFalse(because: "The printer object returned that it had connected unsuccessfully");
            token.Should().BeNull(because: "Token could not be populated as printer did not connect");
        }