コード例 #1
0
        public MainWindowModel(IDeviceEventReceiverFactory deviceEventReceiverFactory)
        {
            if (deviceEventReceiverFactory == null)
            {
                throw new ArgumentNullException(nameof(deviceEventReceiverFactory));
            }

            _deviceEventReceiverFactory = deviceEventReceiverFactory;
        }
コード例 #2
0
        public void Start_WhenConnectingStateChanges_StateChangedHandlerInvoked()
        {
            IDeviceEventReceiver        eventReceiverFake        = CreateDeviceEventReceiverFake(null);
            IDeviceEventReceiverFactory eventReceiverFactoryFake = CreateDeviceEventReceiverFactoryFake(eventReceiverFake);

            var autoResetEvent = new AutoResetEvent(false);
            var model          = new MainWindowModel(eventReceiverFactoryFake);

            model.ConnectionStateChanged += (sender, @event) => autoResetEvent.Set();
            model.Start(CreateConnectionParametersFake());

            Assert.IsTrue(autoResetEvent.WaitOne(TestWaitTimeoutMs));
        }
コード例 #3
0
        public void Stop_ConnectionEstablishedThenAborted_StoppedEventHandlerInvoked()
        {
            IDeviceEventReceiver        eventReceiverFake        = CreateDeviceEventReceiverFake(null);
            IDeviceEventReceiverFactory eventReceiverFactoryFake = CreateDeviceEventReceiverFactoryFake(eventReceiverFake);

            var autoResetEvent = new AutoResetEvent(false);
            var model          = new MainWindowModel(eventReceiverFactoryFake);

            model.Stopped += (sender, args) => autoResetEvent.Set();
            model.Start(CreateConnectionParametersFake());
            Thread.Sleep(500);
            model.Stop();

            Assert.IsTrue(autoResetEvent.WaitOne(TestWaitTimeoutMs));
        }
コード例 #4
0
        public void Start_ConnectionEstablishedAndEventIsReceived_EventReceivedHandlerInvoked()
        {
            var patternEvent = new DeviceEvent("test");
            IDeviceEventReceiver        eventReceiverFake        = CreateDeviceEventReceiverFake(patternEvent);
            IDeviceEventReceiverFactory eventReceiverFactoryFake = CreateDeviceEventReceiverFactoryFake(eventReceiverFake);

            var         autoResetEvent = new AutoResetEvent(false);
            DeviceEvent currentEvent   = null;
            var         model          = new MainWindowModel(eventReceiverFactoryFake);

            model.EventReceived += (sender, @event) =>
            {
                currentEvent = @event;
                autoResetEvent.Set();
            };
            model.Start(CreateConnectionParametersFake());

            Assert.IsTrue(autoResetEvent.WaitOne(TestWaitTimeoutMs));
            Assert.AreSame(patternEvent, currentEvent);
        }