Ejemplo n.º 1
0
        public void ZebraZC3_GetMagEncoder_ConnectNotCalledBeforeMethodUsed()
        {
            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       usbPrinter        = Substitute.For <ZebraSdk.Printer.Discovery.DiscoveredUsbPrinter>("symbolicName1");
                var       zebraZC3          = new ZebraZC3(usbPrinter);
                Exception receivedException = null;

                // Act
                try
                {
                    var hasMagEncoder = zebraZC3.HasMagEncoder();
                }
                catch (Exception ex)
                {
                    receivedException = ex;
                }

                // Assert
                usbPrinter.Received(0).GetConnection();
                receivedException.Should().NotBeNull(because: "The method should check that Connect was called before trying to anything");
                receivedException.Message.Should().Be("Device not connected! Method may only be used after device has successful Connect().");
            }
        }
Ejemplo n.º 2
0
        public void ZebraZC3_GetMagEncoder_ReturnsFalse()
        {
            using (ShimsContext.Create())
            {
                // Arrange
                var conn         = Substitute.For <ZebraSdk.Comm.Connection>();
                var errorFactory = Substitute.For <Error.IZebraErrorFactory>();

                var zebraPrinter = Substitute.For <ZebraSdk.Card.Printer.ZebraCardPrinter>();
                zebraPrinter.SetConnection(conn);
                zebraPrinter.HasMagneticEncoder().Returns(false);

                ZebraZC3 zebraZC3 = new ZebraZC3(conn, zebraPrinter, errorFactory);

                // Act
                var hasMagEncoder = zebraZC3.HasMagEncoder();

                // Assert
                zebraPrinter.Received(1).HasMagneticEncoder();
                hasMagEncoder.Should().BeFalse(because: "ZebraCardPrinter does not have a magnetic encoder installed, which returns false when checked. Therefor our method must also send back false.");
            }
        }