示例#1
0
        public void ZebraZC3_ConnectToUsbPrinter_ConnectionSuccess()
        {
            using (ShimsContext.Create())
            {
                // Arrange
                ZebraSdk.Printer.Discovery.Fakes.ShimDiscoveredPrinter.AllInstances.AddressGet          = @this => "SomeFunnyAddress";
                ZebraSdk.Printer.Discovery.Fakes.ShimDiscoveredPrinter.AllInstances.DiscoveryDataMapGet = @this => new Dictionary <string, string>()
                {
                    { "SERIAL_NUMBER", "aaabbbb111222ccc" },
                    { "MFG", "Zebra Technologies" },
                    { "MODEL", "ZTC ZC350" }
                };
                var conn       = Substitute.For <ZebraSdk.Comm.Connection>();
                var usbPrinter = Substitute.For <ZebraSdk.Printer.Discovery.DiscoveredUsbPrinter>("symbolicName1");
                usbPrinter.GetConnection().Returns(conn);

                var zebraPrinter = Substitute.For <ZebraSdk.Card.Printer.ZebraCardPrinter>();
                ZebraSdk.Card.Printer.Fakes.ShimZebraCardPrinterFactory.GetInstanceConnection = (shimConn) =>
                {
                    return(zebraPrinter);
                };

                ZebraZC3 zebraZC3 = new ZebraZC3(usbPrinter);

                // Act
                var respCode = zebraZC3.Connect();

                // Assert
                usbPrinter.Received(1).GetConnection();
                conn.Received(1).Open();
                respCode.Should().Be(0, because: "Sucessful response code from the printer is code=0");
            }
        }
示例#2
0
        public void ZebraZC3_ConnectToUsbPrinter_ZebraCardPrinterFactoryGetInstanceException()
        {
            using (ShimsContext.Create())
            {
                // Arrange
                ZebraSdk.Printer.Discovery.Fakes.ShimDiscoveredPrinter.AllInstances.AddressGet          = @this => "SomeFunnyAddress";
                ZebraSdk.Printer.Discovery.Fakes.ShimDiscoveredPrinter.AllInstances.DiscoveryDataMapGet = @this => new Dictionary <string, string>()
                {
                    { "SERIAL_NUMBER", "aaabbbb111222ccc" },
                    { "MFG", "Zebra Technologies" },
                    { "MODEL", "ZTC ZC350" }
                };
                var conn = Substitute.For <ZebraSdk.Comm.Connection>();

                var usbPrinter = Substitute.For <ZebraSdk.Printer.Discovery.DiscoveredUsbPrinter>("symbolicName1");
                usbPrinter.GetConnection().Returns(conn);

                var zebraPrinter = Substitute.For <ZebraSdk.Card.Printer.ZebraCardPrinter>();
                ZebraSdk.Card.Printer.Fakes.ShimZebraCardPrinterFactory.GetInstanceConnection = (shimConn) =>
                {
                    throw new Exception();
                };

                ZebraZC3 zebraZC3 = new ZebraZC3(usbPrinter);

                Exception expectedEx = null;
                short?    respCode   = null;

                // Act
                try
                {
                    respCode = zebraZC3.Connect();
                }
                catch (Exception ex)
                {
                    expectedEx = ex;
                }

                // Assert
                usbPrinter.Received(1).GetConnection();
                conn.Received(1).Open();
                respCode.Should().BeNull(because: "ZebraCardPrinterFactory.GetInstance threw exception which must be cause by calling code. No response code should have been returned");
                expectedEx.Should().NotBeNull(because: "ZebraCardPrinterFactory.GetInstance threw exception and should not have been swallowed");
            }
        }