Esempio n. 1
0
        public void DeviceLocator_Notifications_DoesNotRaiseDeviceAvailableIfDisposed()
        {
            var server = new MockCommsServer();
            var deviceLocator = new MockDeviceLocator(server);
            DiscoveredSsdpDevice device = null;
            bool newlyDiscovered = false;

            var receivedNotification = false;
            using (var eventSignal = new System.Threading.AutoResetEvent(false))
            {
                deviceLocator.DeviceAvailable += (sender, args) =>
                {
                    device = args.DiscoveredDevice;
                    newlyDiscovered = args.IsNewlyDiscovered;
                    receivedNotification = true;
                };
                deviceLocator.StartListeningForNotifications();

                server.MockReceiveBroadcast(GetMockAliveNotification());
                server.Dispose();
                eventSignal.WaitOne(1000);
            }

            Assert.IsFalse(receivedNotification);
        }
Esempio n. 2
0
        public void DeviceLocator_Notifications_IgnoresNonNotifyRequest()
        {
            var server                  = new MockCommsServer();
            var deviceLocator           = new MockDeviceLocator(server);
            var receivedNotification    = false;
            DiscoveredSsdpDevice device = null;
            bool expired                = false;

            deviceLocator.DeviceUnavailable += (sender, args) =>
            {
                device  = args.DiscoveredDevice;
                expired = args.Expired;
                receivedNotification = true;
            };
            deviceLocator.StartListeningForNotifications();

            server.MockReceiveBroadcast(GetMockNonNotifyRequest());
            server.WaitForMessageToProcess(10000);
            server.Dispose();

            Assert.IsFalse(receivedNotification);
        }
Esempio n. 3
0
        public void DeviceLocator_SearchAsync_AllowsZeroSearchTime()
        {
            var server = new MockCommsServer();
            var deviceLocator = new MockDeviceLocator(server);

            string searchTarget = "ssdp:all";
            var t = deviceLocator.SearchAsync(searchTarget, TimeSpan.Zero);
            t.GetAwaiter().GetResult();
            server.Dispose();
            deviceLocator.Dispose();
        }
Esempio n. 4
0
        public void DeviceLocator_Notifications_IgnoresNonNotifyRequest()
        {
            var server = new MockCommsServer();
            var deviceLocator = new MockDeviceLocator(server);
            var receivedNotification = false;
            DiscoveredSsdpDevice device = null;
            bool expired = false;

            deviceLocator.DeviceUnavailable += (sender, args) =>
            {
                device = args.DiscoveredDevice;
                expired = args.Expired;
                receivedNotification = true;
            };
            deviceLocator.StartListeningForNotifications();

            server.MockReceiveBroadcast(GetMockNonNotifyRequest());
            server.WaitForMessageToProcess(10000);
            server.Dispose();

            Assert.IsFalse(receivedNotification);
        }