コード例 #1
0
            public void Exception_For_NullHooks()
            {
                var settings = new FeigReaderSettings();

                Check.ThatCode(() => FeigReader.Create(settings, (ITransportHooks)null))
                .Throws <ArgumentNullException>();
            }
コード例 #2
0
            public void Success()
            {
                // act
                var hooks    = new Mock <ITransportHooks>();
                var settings = new FeigReaderSettings();

                var logger = LoggerFactory.Create(
                    builder => {
                    builder.SetMinimumLevel(LogLevel.Trace);
                    builder.AddSimpleConsole();
                }
                    )
                             .CreateLogger("Test");

                var reader = FeigReader.Create(settings, logger, hooks.Object);

                // assert
                Check.That(reader).IsInstanceOf <DefaultFeigReader>();

                var readerImpl = (DefaultFeigReader)reader;

                Check.That(readerImpl.Settings).Not.IsSameReferenceAs(settings);
                Check.That(readerImpl.Logger).IsSameReferenceAs(logger);
                Check.That(readerImpl.Transport).IsInstanceOf <DefaultFeigTransport>();

                var transportImpl = (DefaultFeigTransport)readerImpl.Transport;

                Check.That(transportImpl.Settings).Not.IsSameReferenceAs(settings.TransportSettings);

                Check.That(transportImpl.Logger).IsSameReferenceAs(logger).And.IsSameReferenceAs(readerImpl.Logger);
            }
        public void Construction_Copy()
        {
            // act
            var copy = new FeigReaderSettings {
                TransportSettings = new SerialTransportSettings {
                    PortName  = "COM3",
                    Baud      = 19200,
                    DataBits  = 7,
                    Parity    = Parity.Mark,
                    StopBits  = StopBits.Two,
                    Handshake = Handshake.RequestToSendXOnXOff,
                },
                Address  = 123,
                Timeout  = TimeSpan.FromMilliseconds(500),
                Protocol = FeigProtocol.Standard,
            };

            var settings = new FeigReaderSettings(copy);

            // assert
            Check.That(settings.TransportSettings.PortName).IsEqualTo("COM3");
            Check.That(settings.TransportSettings.Baud).IsEqualTo(19200);
            Check.That(settings.TransportSettings.DataBits).IsEqualTo(7);
            Check.That(settings.TransportSettings.Parity).IsEqualTo(Parity.Mark);
            Check.That(settings.TransportSettings.StopBits).IsEqualTo(StopBits.Two);
            Check.That(settings.TransportSettings.Handshake).IsEqualTo(Handshake.RequestToSendXOnXOff);
            Check.That(settings.Address).IsEqualTo(123);
            Check.That(settings.Timeout).IsEqualTo(TimeSpan.FromMilliseconds(500));
            Check.That(settings.Protocol).IsEqualTo(FeigProtocol.Standard);

            Check.That(settings.ToString())
            .IsEqualTo(
                "Transport: 'COM3,19200,7,Mark,Two,RequestToSendXOnXOff', Address: 123, Timeout: 500 ms, Protocol: Standard"
                );
        }
コード例 #4
0
        /// <summary>
        /// Initializes a new instance.
        /// </summary>
        ///
        /// <exception cref="ArgumentNullException">
        /// A null reference was passed to a method that did not accept it as a valid argument.</exception>
        public FeigReaderSettings(FeigReaderSettings settings)
        {
            Verify.NotNull(settings, nameof(settings));

            TransportSettings = new SerialTransportSettings(settings.TransportSettings);
            Address           = settings.Address;
            Timeout           = settings.Timeout;
            Protocol          = settings.Protocol;
        }
コード例 #5
0
        /// <summary>
        /// Creates a <see cref="IFeigReader"/> based on the supplied settings.
        /// </summary>
        ///
        /// <param name="settings">
        /// The settings used to create the reader.</param>
        /// <param name="logger">
        /// The logger used to log operations of transport and reader.</param>
        ///
        /// <exception cref="ArgumentNullException">
        /// A null reference was passed to a method that did not accept it as a valid argument.</exception>
        public static IFeigReader Create(FeigReaderSettings settings, ILogger logger)
        {
            Verify.NotNull(settings, nameof(settings));
            Verify.NotNull(logger, nameof(logger));

            var copy      = new FeigReaderSettings(settings);
            var transport = new DefaultFeigTransport(copy.TransportSettings, logger);

            return(new DefaultFeigReader(copy, transport, logger));
        }
コード例 #6
0
        /// <summary>
        /// Creates a <see cref="IFeigReader"/> based on the supplied settings.
        /// </summary>
        ///
        /// <param name="settings">
        /// The settings used to create the reader.</param>
        /// <param name="hooks">
        /// A hooks implementation being called for sent or received data.</param>
        ///
        /// <exception cref="ArgumentNullException">
        /// A null reference was passed to a method that did not accept it as a valid argument.</exception>
        public static IFeigReader Create(FeigReaderSettings settings, ITransportHooks hooks)
        {
            Verify.NotNull(settings, nameof(settings));
            Verify.NotNull(hooks, nameof(hooks));

            var copy      = new FeigReaderSettings(settings);
            var logger    = NullLogger.Instance;
            var transport = new DefaultFeigTransport(copy.TransportSettings, logger, hooks);

            return(new DefaultFeigReader(copy, transport, logger));
        }
        public void Construction_Defaults()
        {
            // act
            var settings = new FeigReaderSettings();

            // assert
            Check.That(settings.TransportSettings.PortName).IsEqualTo("COM1");
            Check.That(settings.TransportSettings.Baud).IsEqualTo(38400);
            Check.That(settings.TransportSettings.DataBits).IsEqualTo(8);
            Check.That(settings.TransportSettings.Parity).IsEqualTo(Parity.Even);
            Check.That(settings.TransportSettings.StopBits).IsEqualTo(StopBits.One);
            Check.That(settings.TransportSettings.Handshake).IsEqualTo(Handshake.None);
            Check.That(settings.Address).IsEqualTo(255);
            Check.That(settings.Timeout).IsEqualTo(TimeSpan.FromMilliseconds(1000));
            Check.That(settings.Protocol).IsEqualTo(FeigProtocol.Advanced);

            Check.That(settings.ToString())
            .IsEqualTo(
                "Transport: 'COM1,38400,8,Even,One,None', Address: 255, Timeout: 1000 ms, Protocol: Advanced"
                );
        }
コード例 #8
0
            public void Success()
            {
                // act
                var settings = new FeigReaderSettings();
                var reader   = FeigReader.Create(settings);

                // assert
                Check.That(reader).IsInstanceOf <DefaultFeigReader>();

                var readerImpl = (DefaultFeigReader)reader;

                Check.That(readerImpl.Settings).Not.IsSameReferenceAs(settings);
                Check.That(readerImpl.Logger).IsEqualTo(NullLogger.Instance);
                Check.That(readerImpl.Transport).IsInstanceOf <DefaultFeigTransport>();

                var transportImpl = (DefaultFeigTransport)readerImpl.Transport;

                Check.That(transportImpl.Settings).Not.IsSameReferenceAs(settings.TransportSettings);

                Check.That(transportImpl.Logger)
                .IsEqualTo(NullLogger.Instance)
                .And.IsSameReferenceAs(readerImpl.Logger);
            }