示例#1
0
        public void EventReceived_Paired_TriggersPairedEvent()
        {
            // Setup
            var channel = new Mock <IChannelListener>();

            var deviceListener = DeviceListener.Create(channel.Object);

            PairedEventArgs actualEventArgs = null;

            deviceListener.Paired += (_, args) => actualEventArgs = args;

            var myoHandle      = new IntPtr(12345);
            var timestamp      = DateTime.UtcNow;
            var routeEventArgs = new RouteMyoEventArgs(
                myoHandle,
                new IntPtr(123),
                MyoEventType.Paired,
                timestamp);

            // Execute
            channel.Raise(x => x.EventReceived += null, routeEventArgs);

            // Assert
            Assert.NotNull(actualEventArgs);
            Assert.Equal(myoHandle, actualEventArgs.MyoHandle);
            Assert.Equal(timestamp, actualEventArgs.Timestamp);
        }
示例#2
0
        /// <summary>
        /// Creates a new <see cref="IHub"/> instance.
        /// </summary>
        /// <param name="channelListener">The channel listener.</param>
        /// <returns>A new <see cref="IHub"/> instance.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when the channel listener is null.</exception>
        public static IHub Create(IChannelListener channelListener)
        {
            Contract.Requires <ArgumentNullException>(channelListener != null, "channelListener");
            Contract.Ensures(Contract.Result <IHub>() != null);

            return(new Hub(DeviceListener.Create(channelListener)));
        }
示例#3
0
        public void EventReceived_EmgData_DoesNotTriggerPairedEvent()
        {
            // Setup
            var channel = new Mock <IChannelListener>();

            var deviceListener = DeviceListener.Create(channel.Object);

            var gotPairedEvent = false;

            deviceListener.Paired += (_, __) => gotPairedEvent = true;

            var routeEventArgs = new RouteMyoEventArgs(
                new IntPtr(123),
                new IntPtr(123),
                MyoEventType.Emg,
                DateTime.UtcNow);

            // Execute
            channel.Raise(x => x.EventReceived += null, routeEventArgs);

            // Assert
            Assert.False(
                gotPairedEvent,
                "Not expecting to get the paired event.");
        }
示例#4
0
        public void Create_ValidParameters_NewInstance()
        {
            // Setup
            var channel = new Mock <IChannelListener>();

            // Execute
            var result = DeviceListener.Create(channel.Object);

            // Assert
            Assert.NotNull(result);
        }
示例#5
0
        public void GetChannelListener_ValidState_SameInstanceAsConstructor()
        {
            // Setup
            var channel        = new Mock <IChannelListener>();
            var deviceListener = DeviceListener.Create(channel.Object);

            // Execute
            var result = deviceListener.ChannelListener;

            // Assert
            Assert.Equal(channel.Object, result);
        }
示例#6
0
        public void Create_NullChannelListener_ThrowsNullArgumentException()
        {
            // Setup

            // Execute
            Assert.ThrowsDelegate method = () => DeviceListener.Create(null);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(method);

            Assert.Equal("channelListener", exception.ParamName);
        }
示例#7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Hub"/> class.
 /// </summary>
 /// <param name="channelListener">The channel listener.</param>
 /// <exception cref="System.ArgumentNullException">Thrown when the channel listener is null.</exception>
 protected Hub(IChannelListener channelListener)
     : this(DeviceListener.Create(channelListener))
 {
     Contract.Requires <ArgumentNullException>(channelListener != null, "channelListener");
 }
示例#8
0
 /// <summary>
 /// Creates a new <see cref="IHub"/> instance.
 /// </summary>
 /// <param name="channelListener">The channel listener.</param>
 /// <returns>A new <see cref="IHub"/> instance.</returns>
 /// <exception cref="System.ArgumentNullException">Thrown when the channel listener is null.</exception>
 public static IHub Create(IChannelListener channelListener)
 {
     return(new Hub(DeviceListener.Create(channelListener)));
 }
示例#9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Hub"/> class.
 /// </summary>
 /// <param name="channelListener">The channel listener.</param>
 /// <exception cref="System.ArgumentNullException">Thrown when the channel listener is null.</exception>
 protected Hub(IChannelListener channelListener)
     : this(DeviceListener.Create(channelListener))
 {
 }