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_ThrowsOnNullDevice() { var server = new MockCommsServer(); var publisher = new TestDevicePublisher(server); publisher.RemoveDevice(null); }
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_RemoveDeviceThrowsWhenDisposed() { var rootDevice = new SsdpRootDevice() { FriendlyName = "Basic Device 1", Manufacturer = "Test Manufacturer", ManufacturerUrl = new Uri("http://testmanufacturer.com"), ModelDescription = "A test model device", ModelName = "Test Model", ModelNumber = "Model #1234", ModelUrl = new Uri("http://modelurl.com"), SerialNumber = "SN-123", Uuid = System.Guid.NewGuid().ToString(), Location = new Uri("http://testdevice:1700/xml") }; var server = new MockCommsServer(); var publisher = new TestDevicePublisher(server); publisher.Dispose(); publisher.RemoveDevice(rootDevice); }