public void DeviceLocator_Notifications_HandlesByeByeDuringSearch() { var server = new MockCommsServer(); var deviceLocator = new MockDeviceLocator(server); DiscoveredSsdpDevice device = null; var receivedNotification = false; using (var eventSignal = new System.Threading.AutoResetEvent(false)) { deviceLocator.DeviceUnavailable += (sender, args) => { device = args.DiscoveredDevice; receivedNotification = true; eventSignal.Set(); }; deviceLocator.StartListeningForNotifications(); server.MockReceiveBroadcast(GetMockAliveNotification()); server.WaitForMessageToProcess(10000); var t = deviceLocator.SearchAsync(TimeSpan.FromSeconds(3)); System.Threading.Thread.Sleep(500); server.MockReceiveBroadcast(GetMockByeByeNotification()); eventSignal.WaitOne(10000); var results = t.GetAwaiter().GetResult(); Assert.IsNotNull(results); Assert.IsFalse(results.Any()); } Assert.IsTrue(receivedNotification); Assert.IsNotNull(device); }
public void DeviceLocator_Notifications_DoesNotRaiseDeviceUnavailableWithUnmatchedNotificationFilter() { var publishedDevice = CreateDeviceTree(); var server = new MockCommsServer(); var deviceLocator = new MockDeviceLocator(server); var discoveredDevices = new List <DiscoveredSsdpDevice>(); using (var eventSignal = new System.Threading.AutoResetEvent(false)) { deviceLocator.DeviceUnavailable += (sender, args) => { discoveredDevices.Add(args.DiscoveredDevice); eventSignal.Set(); }; deviceLocator.NotificationFilter = "uuid:" + Guid.NewGuid().ToString(); deviceLocator.StartListeningForNotifications(); server.MockReceiveBroadcast(GetMockByeByeNotification(publishedDevice)); eventSignal.WaitOne(1000); server.MockReceiveBroadcast(GetMockByeByeNotification(publishedDevice.Devices.First().Devices.First())); eventSignal.WaitOne(1000); server.MockReceiveBroadcast(GetMockByeByeNotification(publishedDevice.Devices.First())); eventSignal.WaitOne(1000); } Assert.IsFalse(discoveredDevices.Any()); }
public void DeviceLocator_Notifications_RaisesDeviceUnavailableWithMatchedNotificationFilter() { var publishedDevice = CreateDeviceTree(); var server = new MockCommsServer(); var deviceLocator = new MockDeviceLocator(server); var discoveredDevices = new List <DiscoveredSsdpDevice>(); using (var eventSignal = new System.Threading.ManualResetEvent(false)) { deviceLocator.DeviceUnavailable += (sender, args) => { discoveredDevices.Add(args.DiscoveredDevice); eventSignal.Set(); }; deviceLocator.NotificationFilter = publishedDevice.Devices.First().Udn; deviceLocator.StartListeningForNotifications(); server.MockReceiveBroadcast(GetMockByeByeNotification(publishedDevice)); server.WaitForMessageToProcess(10000); server.MockReceiveBroadcast(GetMockByeByeNotification(publishedDevice.Devices.First().Devices.First())); server.WaitForMessageToProcess(10000); server.MockReceiveBroadcast(GetMockByeByeNotification(publishedDevice.Devices.First())); server.WaitForMessageToProcess(10000); eventSignal.WaitOne(10000); } Assert.IsTrue(discoveredDevices.Any()); Assert.IsFalse(discoveredDevices.Any((d) => { return(!d.Usn.StartsWith(publishedDevice.Devices.First().Udn)); })); }
public void DeviceLocator_Notifications_ReceivesByeByeNotificationsForKnownDevice() { var server = new MockCommsServer(); var deviceLocator = new MockDeviceLocator(server); var receivedNotification = false; DiscoveredSsdpDevice device = null; bool expired = false; using (var eventSignal = new System.Threading.AutoResetEvent(false)) { deviceLocator.DeviceUnavailable += (sender, args) => { device = args.DiscoveredDevice; expired = args.Expired; receivedNotification = true; eventSignal.Set(); }; deviceLocator.StartListeningForNotifications(); server.MockReceiveBroadcast(GetMockAliveNotification()); server.WaitForMessageToProcess(10000); server.MockReceiveBroadcast(GetMockByeByeNotification()); eventSignal.WaitOne(10000); } Assert.IsTrue(receivedNotification); Assert.IsNotNull(device); Assert.IsFalse(expired); }
public void DeviceLocator_SearchAsync_ReturnsCachedDevices() { 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; eventSignal.Set(); }; deviceLocator.StartListeningForNotifications(); server.MockReceiveBroadcast(GetMockAliveNotification()); eventSignal.WaitOne(10000); Assert.IsTrue(receivedNotification); var results = deviceLocator.SearchAsync(TimeSpan.Zero).GetAwaiter().GetResult(); Assert.IsNotNull(results); Assert.IsTrue(results.Any()); Assert.IsTrue(results.First().Usn == device.Usn); } }
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); }
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); }
public void DeviceLocator_SearchAsync_FiltersNotificationsDuringSearch() { var server = new MockCommsServer(); var deviceLocator = new MockDeviceLocator(server); var publishedDevice = CreateDeviceTree(); var publishedDevice2 = CreateDeviceTree(); deviceLocator.NotificationFilter = publishedDevice.Udn; deviceLocator.StartListeningForNotifications(); 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; eventSignal.Set(); }; var task = deviceLocator.SearchAsync(publishedDevice.Udn); server.MockReceiveBroadcast(GetMockAliveNotification(publishedDevice2)); server.WaitForMessageToProcess(5000); eventSignal.Reset(); server.MockReceiveBroadcast(GetMockAliveNotification(publishedDevice)); server.WaitForMessageToProcess(5000); eventSignal.WaitOne(10000); Assert.IsTrue(receivedNotification); var results = task.GetAwaiter().GetResult(); Assert.IsNotNull(results); Assert.AreEqual(1, results.Count()); Assert.IsTrue(results.First().Usn == device.Usn); } }
public void DeviceLocator_Notifications_SubsequentNotificationsUpdatesSearchResults() { var publishedDevice = CreateDeviceTree(); var server = new MockCommsServer(); using (var deviceLocator = new MockDeviceLocator(server)) { var discoveredDevices = new List <DiscoveredSsdpDevice>(); using (var signal = new System.Threading.AutoResetEvent(false)) { deviceLocator.DeviceAvailable += (sender, args) => { discoveredDevices.Add(args.DiscoveredDevice); signal.Set(); }; deviceLocator.StartListeningForNotifications(); server.MockReceiveBroadcast(GetMockAliveNotification(publishedDevice)); signal.WaitOne(10000); var updatedDevice = CreateDeviceTree(); updatedDevice.Uuid = publishedDevice.Uuid; updatedDevice.Location = new Uri("http://somewhereelse:1701"); updatedDevice.CacheLifetime = TimeSpan.FromDays(365); server.MockReceiveBroadcast(GetMockAliveNotification(updatedDevice)); signal.WaitOne(10000); } var first = discoveredDevices.First(); var second = discoveredDevices.Last(); Assert.IsTrue(discoveredDevices.Any()); Assert.AreNotEqual(first.DescriptionLocation, second.DescriptionLocation); Assert.AreNotEqual(first.CacheLifetime, second.CacheLifetime); Assert.AreEqual(second.CacheLifetime, TimeSpan.FromDays(365)); Assert.AreEqual(second.DescriptionLocation, new Uri("http://somewhereelse:1701")); } }
public void DeviceLocator_Notifications_SubsequentNotificationsUpdatesCachedCacheTime() { var publishedDevice = CreateDeviceTree(); var server = new MockCommsServer(); var deviceLocator = new MockDeviceLocator(server); var discoveredDevices = new List <DiscoveredSsdpDevice>(); using (var signal = new System.Threading.AutoResetEvent(false)) { deviceLocator.DeviceAvailable += (sender, args) => { discoveredDevices.Add(args.DiscoveredDevice); signal.Set(); }; deviceLocator.StartListeningForNotifications(); server.MockReceiveBroadcast(GetMockAliveNotification(publishedDevice)); signal.WaitOne(10000); var t = deviceLocator.SearchAsync(TimeSpan.FromSeconds(5)); var updatedDevice = CreateDeviceTree(); updatedDevice.Uuid = publishedDevice.Uuid; updatedDevice.CacheLifetime = TimeSpan.FromDays(365); server.MockReceiveBroadcast(GetMockAliveNotification(updatedDevice)); signal.WaitOne(10000); var results = t.GetAwaiter().GetResult(); Assert.IsNotNull(results); Assert.IsTrue(results.Any()); Assert.AreEqual(String.Format("{0}::{1}", publishedDevice.Udn, publishedDevice.FullDeviceType), discoveredDevices.Last().Usn); var first = discoveredDevices.First(); var second = discoveredDevices.Last(); Assert.AreNotEqual(first.CacheLifetime, second.CacheLifetime); Assert.AreEqual(second.CacheLifetime, TimeSpan.FromDays(365)); } }
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); }
public void DeviceLocator_Notifications_StopListeningNoLongerReceivesNotifications() { var server = new MockCommsServer(); var deviceLocator = new MockDeviceLocator(server); deviceLocator.StartListeningForNotifications(); deviceLocator.StopListeningForNotifications(); var receivedNotification = false; using (var eventSignal = new System.Threading.AutoResetEvent(false)) { deviceLocator.DeviceAvailable += (sender, args) => { receivedNotification = true; eventSignal.Set(); }; server.MockReceiveBroadcast(GetMockAliveNotification()); eventSignal.WaitOne(1000); } Assert.IsFalse(receivedNotification); }
public void DeviceLocator_SearchAsync_FiltersNotificationsDuringSearch() { var server = new MockCommsServer(); var deviceLocator = new MockDeviceLocator(server); var publishedDevice = CreateDeviceTree(); var publishedDevice2 = CreateDeviceTree(); deviceLocator.NotificationFilter = publishedDevice.Udn; deviceLocator.StartListeningForNotifications(); 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; eventSignal.Set(); }; var task = deviceLocator.SearchAsync(publishedDevice.Udn); server.MockReceiveBroadcast(GetMockAliveNotification(publishedDevice2)); server.WaitForMessageToProcess(5000); eventSignal.Reset(); server.MockReceiveBroadcast(GetMockAliveNotification(publishedDevice)); server.WaitForMessageToProcess(5000); eventSignal.WaitOne(10000); Assert.IsTrue(receivedNotification); var results = task.GetAwaiter().GetResult(); Assert.IsNotNull(results); Assert.AreEqual(1, results.Count()); Assert.IsTrue(results.First().Usn == device.Usn); } }
public void DeviceLocator_Notifications_SubsequentNotificationsUpdatesSearchResults() { var publishedDevice = CreateDeviceTree(); var server = new MockCommsServer(); using (var deviceLocator = new MockDeviceLocator(server)) { var discoveredDevices = new List<DiscoveredSsdpDevice>(); using (var signal = new System.Threading.AutoResetEvent(false)) { deviceLocator.DeviceAvailable += (sender, args) => { discoveredDevices.Add(args.DiscoveredDevice); signal.Set(); }; deviceLocator.StartListeningForNotifications(); server.MockReceiveBroadcast(GetMockAliveNotification(publishedDevice)); signal.WaitOne(10000); var updatedDevice = CreateDeviceTree(); updatedDevice.Uuid = publishedDevice.Uuid; updatedDevice.Location = new Uri("http://somewhereelse:1701"); updatedDevice.CacheLifetime = TimeSpan.FromDays(365); server.MockReceiveBroadcast(GetMockAliveNotification(updatedDevice)); signal.WaitOne(10000); } var first = discoveredDevices.First(); var second = discoveredDevices.Last(); Assert.IsTrue(discoveredDevices.Any()); Assert.AreNotEqual(first.DescriptionLocation, second.DescriptionLocation); Assert.AreNotEqual(first.CacheLifetime, second.CacheLifetime); Assert.AreEqual(second.CacheLifetime, TimeSpan.FromDays(365)); Assert.AreEqual(second.DescriptionLocation, new Uri("http://somewhereelse:1701")); } }
public void DeviceLocator_Notifications_SubsequentNotificationsUpdatesCachedDescriptionLocation() { var publishedDevice = CreateDeviceTree(); var server = new MockCommsServer(); var deviceLocator = new MockDeviceLocator(server); var discoveredDevices = new List<DiscoveredSsdpDevice>(); using (var signal = new System.Threading.AutoResetEvent(false)) { deviceLocator.DeviceAvailable += (sender, args) => { discoveredDevices.Add(args.DiscoveredDevice); signal.Set(); }; deviceLocator.StartListeningForNotifications(); server.MockReceiveBroadcast(GetMockAliveNotification(publishedDevice)); signal.WaitOne(10000); var t = deviceLocator.SearchAsync(TimeSpan.FromSeconds(5)); var updatedDevice = CreateDeviceTree(); updatedDevice.Uuid = publishedDevice.Uuid; updatedDevice.Location = new Uri("http://somewhereelse:1701"); server.MockReceiveBroadcast(GetMockAliveNotification(updatedDevice)); signal.WaitOne(10000); var results = t.GetAwaiter().GetResult(); Assert.IsNotNull(results); Assert.IsTrue(results.Any()); Assert.AreEqual(String.Format("{0}::{1}", publishedDevice.Udn, publishedDevice.FullDeviceType), discoveredDevices.Last().Usn); var first = discoveredDevices.First(); var second = discoveredDevices.Last(); Assert.AreNotEqual(first.DescriptionLocation, second.DescriptionLocation); Assert.AreEqual(second.DescriptionLocation, new Uri("http://somewhereelse:1701")); } }
public void DeviceLocator_Notifications_StopListeningNoLongerReceivesNotifications() { var server = new MockCommsServer(); var deviceLocator = new MockDeviceLocator(server); deviceLocator.StartListeningForNotifications(); deviceLocator.StopListeningForNotifications(); var receivedNotification = false; using (var eventSignal = new System.Threading.AutoResetEvent(false)) { deviceLocator.DeviceAvailable += (sender, args) => { receivedNotification = true; eventSignal.Set(); }; server.MockReceiveBroadcast(GetMockAliveNotification()); eventSignal.WaitOne(1000); } Assert.IsFalse(receivedNotification); }
public void DeviceLocator_Notifications_ReceivesByeByeNotificationsForUnknownDevice() { var server = new MockCommsServer(); var deviceLocator = new MockDeviceLocator(server); var receivedNotification = false; DiscoveredSsdpDevice device = null; bool expired = false; using (var eventSignal = new System.Threading.AutoResetEvent(false)) { deviceLocator.DeviceUnavailable += (sender, args) => { device = args.DiscoveredDevice; expired = args.Expired; receivedNotification = true; eventSignal.Set(); }; deviceLocator.StartListeningForNotifications(); server.MockReceiveBroadcast(GetMockByeByeNotification()); eventSignal.WaitOne(10000); } Assert.IsTrue(receivedNotification); Assert.IsNotNull(device); Assert.IsFalse(expired); }
public void DeviceLocator_Notifications_RaisesDeviceAvailableWithMatchedNotificationFilter() { var publishedDevice = CreateDeviceTree(); var server = new MockCommsServer(); var deviceLocator = new MockDeviceLocator(server); var discoveredDevices = new List<DiscoveredSsdpDevice>(); using (var eventSignal = new System.Threading.AutoResetEvent(false)) { deviceLocator.DeviceAvailable += (sender, args) => { discoveredDevices.Add(args.DiscoveredDevice); eventSignal.Set(); }; deviceLocator.NotificationFilter = "uuid: " + System.Guid.NewGuid().ToString(); deviceLocator.StartListeningForNotifications(); server.MockReceiveBroadcast(GetMockAliveNotification(publishedDevice)); eventSignal.WaitOne(1000); server.MockReceiveBroadcast(GetMockAliveNotification(publishedDevice.Devices.First())); eventSignal.WaitOne(1000); server.MockReceiveBroadcast(GetMockAliveNotification(publishedDevice.Devices.First().Devices.First())); eventSignal.WaitOne(1000); } Assert.IsFalse(discoveredDevices.Any()); }
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); }
public void DeviceLocator_SearchAsync_ReturnsCachedDevices() { 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; eventSignal.Set(); }; deviceLocator.StartListeningForNotifications(); server.MockReceiveBroadcast(GetMockAliveNotification()); eventSignal.WaitOne(10000); Assert.IsTrue(receivedNotification); var results = deviceLocator.SearchAsync(TimeSpan.Zero).GetAwaiter().GetResult(); Assert.IsNotNull(results); Assert.IsTrue(results.Any()); Assert.IsTrue(results.First().Usn == device.Usn); } }
public void DeviceLocator_Notifications_DoesNotRaiseDeviceAvailableWithUnmatchedNotificationFilter() { var publishedDevice = CreateDeviceTree(); var server = new MockCommsServer(); var deviceLocator = new MockDeviceLocator(server); var discoveredDevices = new List<DiscoveredSsdpDevice>(); using (var eventSignal = new System.Threading.AutoResetEvent(false)) { deviceLocator.DeviceAvailable += (sender, args) => { discoveredDevices.Add(args.DiscoveredDevice); eventSignal.Set(); }; deviceLocator.NotificationFilter = publishedDevice.Devices.First().Udn; deviceLocator.StartListeningForNotifications(); server.MockReceiveBroadcast(GetMockAliveNotification(publishedDevice)); eventSignal.WaitOne(1000); server.MockReceiveBroadcast(GetMockAliveNotification(publishedDevice.Devices.First())); eventSignal.WaitOne(1000); server.MockReceiveBroadcast(GetMockAliveNotification(publishedDevice.Devices.First().Devices.First())); eventSignal.WaitOne(1000); } Assert.IsTrue(discoveredDevices.Any()); Assert.IsFalse(discoveredDevices.Any((d) => { return !d.Usn.StartsWith(publishedDevice.Devices.First().Udn); })); }
public void DeviceLocator_Notifications_HandlesByeByeDuringSearch() { var server = new MockCommsServer(); var deviceLocator = new MockDeviceLocator(server); DiscoveredSsdpDevice device = null; var receivedNotification = false; using (var eventSignal = new System.Threading.AutoResetEvent(false)) { deviceLocator.DeviceUnavailable += (sender, args) => { device = args.DiscoveredDevice; receivedNotification = true; eventSignal.Set(); }; deviceLocator.StartListeningForNotifications(); server.MockReceiveBroadcast(GetMockAliveNotification()); server.WaitForMessageToProcess(10000); var t = deviceLocator.SearchAsync(TimeSpan.FromSeconds(3)); System.Threading.Thread.Sleep(500); server.MockReceiveBroadcast(GetMockByeByeNotification()); eventSignal.WaitOne(10000); var results = t.GetAwaiter().GetResult(); Assert.IsNotNull(results); Assert.IsFalse(results.Any()); } Assert.IsTrue(receivedNotification); Assert.IsNotNull(device); }