Esempio n. 1
0
        public void DeviceChangedTest()
        {
            using (DeviceMonitor monitor = new DeviceMonitor(this.Socket))
            {
                DeviceMonitorSink sink = new DeviceMonitorSink(monitor);

                Assert.AreEqual(0, monitor.Devices.Count);

                // Start the monitor, detect the initial device.
                base.RunTest(
                OkResponse,
                ResponseMessages("169.254.109.177:5555\toffline\n"),
                Requests("host:track-devices"),
                () =>
                {
                    monitor.Start();

                    Assert.AreEqual(1, monitor.Devices.Count);
                    Assert.AreEqual(DeviceState.Offline, monitor.Devices.ElementAt(0).State);
                    Assert.AreEqual(1, sink.ConnectedEvents.Count);
                    Assert.AreEqual(0, sink.ChangedEvents.Count);
                    Assert.AreEqual(0, sink.DisconnectedEvents.Count);
                });

                this.Socket.ResponseMessages.Clear();
                this.Socket.Responses.Clear();
                this.Socket.Requests.Clear();

                // Device disconnects
                var eventWaiter = sink.CreateEventSignal();

                base.RunTest(
                NoResponses,
                ResponseMessages("169.254.109.177:5555\tdevice\n"),
                Requests(),
                () =>
                {
                    eventWaiter.WaitOne(1000);

                    Assert.AreEqual(1, monitor.Devices.Count);
                    Assert.AreEqual(DeviceState.Online, monitor.Devices.ElementAt(0).State);
                    Assert.AreEqual(1, sink.ConnectedEvents.Count);
                    Assert.AreEqual(1, sink.ChangedEvents.Count);
                    Assert.AreEqual(0, sink.DisconnectedEvents.Count);
                    Assert.AreEqual("169.254.109.177:5555", sink.ChangedEvents[0].Device.Serial);
                });
            }
        }
Esempio n. 2
0
        public void DeviceDisconnectedTest()
        {
            this.Socket.WaitForNewData = true;

            using (DeviceMonitor monitor = new DeviceMonitor(this.Socket))
            {
                DeviceMonitorSink sink = new DeviceMonitorSink(monitor);

                Assert.Equal(0, monitor.Devices.Count);

                // Start the monitor, detect the initial device.
                base.RunTest(
                    OkResponse,
                    ResponseMessages("169.254.109.177:5555\tdevice\n"),
                    Requests("host:track-devices"),
                    () =>
                {
                    monitor.Start();

                    Assert.Equal(1, monitor.Devices.Count);
                    Assert.Single(sink.ConnectedEvents);
                    Assert.Empty(sink.ChangedEvents);
                    Assert.Empty(sink.DisconnectedEvents);
                });

                this.Socket.ResponseMessages.Clear();
                this.Socket.Responses.Clear();
                this.Socket.Requests.Clear();

                // Device disconnects
                var eventWaiter = sink.CreateEventSignal();

                base.RunTest(
                    NoResponses,
                    ResponseMessages(""),
                    Requests(),
                    () =>
                {
                    eventWaiter.WaitOne(1000);
                    Assert.Equal(0, monitor.Devices.Count);
                    Assert.Single(sink.ConnectedEvents);
                    Assert.Empty(sink.ChangedEvents);
                    Assert.Single(sink.DisconnectedEvents);
                    Assert.Equal("169.254.109.177:5555", sink.DisconnectedEvents[0].Device.Serial);
                });
            }
        }
Esempio n. 3
0
        public void StartInitialDeviceListTest()
        {
            using (DeviceMonitor monitor = new DeviceMonitor(this.Socket))
            {
                DeviceMonitorSink sink = new DeviceMonitorSink(monitor);

                Assert.AreEqual(0, monitor.Devices.Count);

                base.RunTest(
                OkResponse,
                ResponseMessages("169.254.109.177:5555\tdevice\n"),
                Requests("host:track-devices"),
                () =>
                {
                    monitor.Start();

                    Assert.AreEqual(1, monitor.Devices.Count);
                    Assert.AreEqual("169.254.109.177:5555", monitor.Devices.ElementAt(0).Serial);
                    Assert.AreEqual(1, sink.ConnectedEvents.Count);
                    Assert.AreEqual("169.254.109.177:5555", sink.ConnectedEvents[0].Device.Serial);
                    Assert.AreEqual(0, sink.ChangedEvents.Count);
                    Assert.AreEqual(0, sink.DisconnectedEvents.Count);
                });
            }
        }