public void Publisher_AddDevice_AddChildSendsNotifications() { var rootDevice = CreateValidRootDevice(); var server = new MockCommsServer(); using (var publisher = new TestDevicePublisher(server)) { publisher.SupportPnpRootDevice = true; publisher.AddDevice(rootDevice); server.WaitForMockBroadcast(10000); System.Threading.Thread.Sleep(100); Assert.IsTrue(server.SentBroadcasts.Any()); server.SentBroadcasts.Clear(); var embeddedDevice = CreateValidEmbeddedDevice(rootDevice); rootDevice.AddDevice(embeddedDevice); server.WaitForMockBroadcast(10000); System.Threading.Thread.Sleep(100); Assert.IsTrue(server.SentBroadcasts.Any()); var sentMessages = GetAllSentBroadcasts(server); var aliveNotifications = GetNotificationsByType(sentMessages, "ssdp:alive"); var deviceTypeNotifications = GetNotificationsForSearchTarget(aliveNotifications, embeddedDevice.FullDeviceType); var udnNotifications = GetNotificationsForSearchTarget(aliveNotifications, embeddedDevice.Udn); var rootDeviceNotificationsForEmbeddedDevice = GetNotificationsForSearchTarget(aliveNotifications, SsdpConstants.UpnpDeviceTypeRootDevice).Where((n) => { return n.Headers.GetValues("USN").First() == embeddedDevice.Udn + "::" + embeddedDevice.FullDeviceType; }); Assert.IsTrue(deviceTypeNotifications.Count() >= 1); Assert.IsTrue(udnNotifications.Count() >= 1); Assert.AreEqual(0, rootDeviceNotificationsForEmbeddedDevice.Count()); } }
public void Publisher_RemoveLastCachableDeviceStopsPeriodicAliveNotifications() { var rootDevice = CreateValidRootDevice(); rootDevice.CacheLifetime = TimeSpan.FromMinutes(1); var server = new MockCommsServer(); using (var publisher = new TestDevicePublisher(server)) { publisher.AddDevice(rootDevice); server.WaitForMockBroadcast(10000); System.Threading.Thread.Sleep(100); Assert.IsTrue(server.SentBroadcasts.Any()); publisher.RemoveDevice(rootDevice); server.SentBroadcasts.Clear(); server.WaitForMockBroadcast(35000); var sentMessages = GetAllSentBroadcasts(server); Assert.AreEqual(0, sentMessages.Count()); } }
public void Publisher_RemoveDevice_SendsRootUpnpByeByeNotification() { var rootDevice = CreateValidRootDevice(); rootDevice.CacheLifetime = TimeSpan.FromMinutes(1); var server = new MockCommsServer(); using (var publisher = new TestDevicePublisher(server)) { publisher.SupportPnpRootDevice = false; publisher.AddDevice(rootDevice); server.WaitForMockBroadcast(10000); System.Threading.Thread.Sleep(100); Assert.IsTrue(server.SentBroadcasts.Any()); server.SentBroadcasts.Clear(); publisher.RemoveDevice(rootDevice); var sentMessages = GetAllSentBroadcasts(server); var byebyeNotifications = GetNotificationsByType(sentMessages, "ssdp:byebye"); var upnpRootDeviceNotifications = GetNotificationsForSearchTarget(byebyeNotifications, SsdpConstants.UpnpDeviceTypeRootDevice); var pnpRootDeviceNotifications = GetNotificationsForSearchTarget(byebyeNotifications, SsdpConstants.PnpDeviceTypeRootDevice); Assert.AreEqual(0, publisher.Devices.Count()); Assert.IsTrue(upnpRootDeviceNotifications.Count() >= 1); Assert.AreEqual(0, pnpRootDeviceNotifications.Count()); } }
public void Publisher_RemoveDevice_RemoveTreeSendsGrandchildNotifications() { var rootDevice = CreateValidRootDevice(); var parentDevice = CreateValidEmbeddedDevice(rootDevice); rootDevice.AddDevice(parentDevice); var embeddedDevice = CreateValidEmbeddedDevice(rootDevice); parentDevice.AddDevice(embeddedDevice); var server = new MockCommsServer(); using (var publisher = new TestDevicePublisher(server)) { publisher.AddDevice(rootDevice); server.WaitForMockBroadcast(10000); System.Threading.Thread.Sleep(100); Assert.IsTrue(server.SentBroadcasts.Any()); server.SentBroadcasts.Clear(); publisher.RemoveDevice(rootDevice); var sentMessages = GetAllSentBroadcasts(server); var byebyeNotifications = GetNotificationsByType(sentMessages, "ssdp:byebye"); var udnRootDeviceNotifications = GetNotificationsForSearchTarget(byebyeNotifications, embeddedDevice.Udn); var deviceTypeRootDeviceNotifications = GetNotificationsForSearchTarget(byebyeNotifications, String.Format("urn:{0}", embeddedDevice.FullDeviceType)); Assert.IsTrue(udnRootDeviceNotifications.Count() >= 1); Assert.IsTrue(deviceTypeRootDeviceNotifications.Count() >= 1); } }
public void Publisher_RemoveDevice_BroadcastsByeByeUdnNotification() { var rootDevice = CreateValidRootDevice(); rootDevice.CacheLifetime = TimeSpan.FromMinutes(1); var server = new MockCommsServer(); using (var publisher = new TestDevicePublisher(server)) { publisher.AddDevice(rootDevice); server.WaitForMockBroadcast(10000); System.Threading.Thread.Sleep(100); Assert.IsTrue(server.SentBroadcasts.Any()); server.SentBroadcasts.Clear(); publisher.RemoveDevice(rootDevice); var sentMessages = GetAllSentBroadcasts(server); var byebyeNotifications = GetNotificationsByType(sentMessages, "ssdp:byebye"); var udnRootDeviceNotifications = GetNotificationsForSearchTarget(byebyeNotifications, rootDevice.Udn); Assert.IsTrue(udnRootDeviceNotifications.Count() >= 1); } }
public void Publisher_AddDevice_BroadcastsUdnNotification() { var rootDevice = CreateValidRootDevice(); var server = new MockCommsServer(); using (var publisher = new TestDevicePublisher(server)) { publisher.SupportPnpRootDevice = true; publisher.AddDevice(rootDevice); server.WaitForMockBroadcast(10000); //Initial signal is just for first broadcast, //wait for others to be sent. System.Threading.Thread.Sleep(100); Assert.IsTrue(server.SentBroadcasts.Any()); var sentMessages = GetAllSentBroadcasts(server); var aliveNotifications = GetNotificationsByType(sentMessages, "ssdp:alive"); var udnDeviceNotifications = GetNotificationsForSearchTarget(aliveNotifications, rootDevice.Udn); Assert.IsTrue(udnDeviceNotifications.Count() >= 1); } }
public void Publisher_AddDevice_BroadcastsRootUpnpAliveNotification() { var rootDevice = CreateValidRootDevice(); var server = new MockCommsServer(); using (var publisher = new TestDevicePublisher(server)) { publisher.SupportPnpRootDevice = false; publisher.AddDevice(rootDevice); server.WaitForMockBroadcast(10000); System.Threading.Thread.Sleep(100); Assert.IsTrue(server.SentBroadcasts.Any()); var sentMessages = GetAllSentBroadcasts(server); var aliveNotifications = GetNotificationsByType(sentMessages, "ssdp:alive"); var upnpRootDeviceNotifications = GetNotificationsForSearchTarget(aliveNotifications, SsdpConstants.UpnpDeviceTypeRootDevice); var pnpRootDeviceNotifications = GetNotificationsForSearchTarget(aliveNotifications, SsdpConstants.PnpDeviceTypeRootDevice); Assert.AreEqual(1, publisher.Devices.Count()); Assert.IsTrue(upnpRootDeviceNotifications.Count() >= 1); Assert.AreEqual(0, pnpRootDeviceNotifications.Count()); } }
public void Publisher_AddDevice_BroadcastsDeviceTypeAliveNotification() { var rootDevice = CreateValidRootDevice(); var server = new MockCommsServer(); using (var publisher = new TestDevicePublisher(server)) { publisher.SupportPnpRootDevice = true; publisher.AddDevice(rootDevice); server.WaitForMockBroadcast(10000); System.Threading.Thread.Sleep(100); Assert.IsTrue(server.SentBroadcasts.Any()); var sentMessages = GetAllSentBroadcasts(server); var aliveNotifications = GetNotificationsByType(sentMessages, "ssdp:alive"); var deviceTypeNotifications = GetNotificationsForSearchTarget(aliveNotifications, rootDevice.FullDeviceType); Assert.IsTrue(deviceTypeNotifications.Count() >= 1); } }