public void Publisher_AddDeviceThrowsWhenDisposed() { 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.AddDevice(rootDevice); }
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_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_DoesNotDisposeSharedCommsServer() { var server = new MockCommsServer(); server.IsShared = true; var publisher = new TestDevicePublisher(server); publisher.Dispose(); Assert.IsFalse(server.IsDisposed); }
public void Publisher_SearchResponse_RandomisesMxHeaderGreaterThan120() { var rootDevice = CreateValidRootDevice(); var server = new MockCommsServer(); using (var publisher = new TestDevicePublisher(server)) { publisher.SupportPnpRootDevice = false; publisher.AddDevice(rootDevice); ReceivedUdpData searchRequest = GetSearchRequestMessageWithCustomMXHeader(rootDevice.Udn, "125"); server.MockReceiveMessage(searchRequest); Assert.IsTrue(server.WaitForMockMessage(120000)); System.Threading.Thread.Sleep(500); var searchResponses = GetSentMessages(server.SentMessages); Assert.AreEqual(3, searchResponses.Count()); } }
public void Publisher_SearchResponse_NoResponseToBlankSearchTarget() { var rootDevice = CreateValidRootDevice(); var server = new MockCommsServer(); using (var publisher = new TestDevicePublisher(server)) { publisher.AddDevice(rootDevice); ReceivedUdpData searchRequest = GetSearchRequestMessage(String.Empty); server.MockReceiveMessage(searchRequest); server.WaitForMockMessage(1500); var searchResponses = GetSentMessages(server.SentMessages); Assert.AreEqual(0, searchResponses.Count()); } }
public void Publisher_SearchResponse_IgnoresDuplicateSearchRequest() { var rootDevice = CreateValidRootDevice(); var server = new MockCommsServer(); using (var publisher = new TestDevicePublisher(server)) { publisher.SupportPnpRootDevice = false; publisher.AddDevice(rootDevice); ReceivedUdpData searchRequest = GetSearchRequestMessage(SsdpConstants.UpnpDeviceTypeRootDevice); server.MockReceiveMessage(searchRequest); server.MockReceiveMessage(searchRequest); server.WaitForMockMessage(1500); System.Threading.Thread.Sleep(500); var searchResponses = GetSentMessages(server.SentMessages); Assert.AreEqual(0, searchResponses.Where((r) => !r.IsSuccessStatusCode).Count()); Assert.IsTrue(GetResponses(searchResponses, SsdpConstants.UpnpDeviceTypeRootDevice).Count() == 1); } }
public void Publisher_SearchResponse_AddCustomHeaders() { var rootDevice = CreateValidRootDevice(); var testHeader = new CustomHttpHeader("machinename", Environment.MachineName); rootDevice.CustomResponseHeaders.Add(testHeader); var server = new MockCommsServer(); using (var publisher = new TestDevicePublisher(server)) { publisher.SupportPnpRootDevice = false; publisher.AddDevice(rootDevice); ReceivedUdpData searchRequest = GetSearchRequestMessage(SsdpConstants.UpnpDeviceTypeRootDevice); server.MockReceiveMessage(searchRequest); server.WaitForMockMessage(1500); var searchResponses = GetSentMessages(server.SentMessages); Assert.AreEqual(0, searchResponses.Where((r) => !r.IsSuccessStatusCode).Count()); Assert.IsTrue(GetResponses(searchResponses, SsdpConstants.UpnpDeviceTypeRootDevice).Count() >= 1); Assert.IsTrue(GetResponses(searchResponses, SsdpConstants.PnpDeviceTypeRootDevice).Count() == 0); Assert.IsTrue(GetResponses(searchResponses, rootDevice.Udn).Count() >= 1); Assert.IsTrue(GetResponses(searchResponses, rootDevice.FullDeviceType).Count() >= 1); Assert.AreEqual(0, searchResponses.Where((r) => !r.Headers.GetValues("USN").First().StartsWith(rootDevice.Udn)).Count()); Assert.AreEqual(0, searchResponses.Where((r) => !r.Headers.GetValues(testHeader.Name).First().StartsWith(testHeader.Value)).Count()); } }
public void Publisher_RemoveDevice_ThrowsOnNullDevice() { var server = new MockCommsServer(); var publisher = new TestDevicePublisher(server); publisher.RemoveDevice(null); }
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); } }
public void Publisher_SearchResponse_SendsGrandchildResponses() { var rootDevice = CreateValidRootDevice(); var parentDevice = CreateValidEmbeddedDevice(rootDevice); rootDevice.AddDevice(parentDevice); var childDevice = CreateValidEmbeddedDevice(rootDevice); parentDevice.AddDevice(childDevice); var server = new MockCommsServer(); using (var publisher = new TestDevicePublisher(server)) { publisher.SupportPnpRootDevice = false; publisher.AddDevice(rootDevice); ReceivedUdpData searchRequest = GetSearchRequestMessage(childDevice.Udn); server.MockReceiveMessage(searchRequest); server.WaitForMockMessage(1500); System.Threading.Thread.Sleep(100); var searchResponses = GetSentMessages(server.SentMessages); var uuidResponses = GetResponses(searchResponses, childDevice.Udn); Assert.AreEqual(1, uuidResponses.Count()); } }
public void Publisher_SearchResponse_RespondsToUdnSearch() { var rootDevice = CreateValidRootDevice(); var server = new MockCommsServer(); using (var publisher = new TestDevicePublisher(server)) { publisher.AddDevice(rootDevice); ReceivedUdpData searchRequest = GetSearchRequestMessage(rootDevice.Udn); server.MockReceiveMessage(searchRequest); server.WaitForMockMessage(1500); System.Threading.Thread.Sleep(100); var searchResponses = GetSentMessages(server.SentMessages); Assert.AreEqual(0, searchResponses.Where((r) => !r.IsSuccessStatusCode).Count()); Assert.IsTrue(GetResponses(searchResponses, SsdpConstants.UpnpDeviceTypeRootDevice).Count() >= 1); Assert.IsTrue(GetResponses(searchResponses, SsdpConstants.PnpDeviceTypeRootDevice).Count() >= 1); Assert.IsTrue(GetResponses(searchResponses, rootDevice.Udn).Count() >= 1); Assert.IsTrue(GetResponses(searchResponses, rootDevice.FullDeviceType).Count() >= 1); Assert.AreEqual(0, searchResponses.Where((r) => !r.Headers.GetValues("USN").First().StartsWith(rootDevice.Udn)).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_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_AddDevice_DuplicateAddDoesNothing() { var rootDevice = CreateValidRootDevice(); var server = new MockCommsServer(); using (var publisher = new TestDevicePublisher(server)) { publisher.AddDevice(rootDevice); publisher.AddDevice(rootDevice); Assert.AreEqual(1, publisher.Devices.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_Constructor_ThrowsOnNullOSVersion() { 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, "TestOS", null); }
public void Publisher_SearchResponse_DoesNotRespondToRequestWithEmptyMXHeaderIfPnpSupportDisabled() { var rootDevice = CreateValidRootDevice(); var parentDevice = CreateValidEmbeddedDevice(rootDevice); rootDevice.AddDevice(parentDevice); var childDevice = CreateValidEmbeddedDevice(rootDevice); parentDevice.AddDevice(childDevice); var server = new MockCommsServer(); using (var publisher = new TestDevicePublisher(server)) { publisher.SupportPnpRootDevice = false; publisher.AddDevice(rootDevice); ReceivedUdpData searchRequest = GetSearchRequestMessageWithCustomMXHeader(childDevice.Udn, String.Empty); server.MockReceiveMessage(searchRequest); server.MockReceiveMessage(searchRequest); server.WaitForMockMessage(1500); System.Threading.Thread.Sleep(500); var searchResponses = GetSentMessages(server.SentMessages); var uuidResponses = GetResponses(searchResponses, childDevice.Udn); Assert.AreEqual(0, uuidResponses.Count()); } }
public void Publisher_DisposeSetsIsDisposed() { var server = new MockCommsServer(); var publisher = new TestDevicePublisher(server); publisher.Dispose(); Assert.IsTrue(publisher.IsDisposed); }
public void Publisher_SearchResponse_IgnoresNullMessageReceipt() { var rootDevice = CreateValidRootDevice(); var parentDevice = CreateValidEmbeddedDevice(rootDevice); rootDevice.AddDevice(parentDevice); var childDevice = CreateValidEmbeddedDevice(rootDevice); parentDevice.AddDevice(childDevice); var server = new MockCommsServer(); using (var publisher = new TestDevicePublisher(server)) { publisher.SupportPnpRootDevice = false; publisher.AddDevice(rootDevice); ReceivedUdpData searchRequest = GetSearchRequestMessage("ssdp:all"); searchRequest.Buffer = null; server.MockReceiveMessage(searchRequest); } }
public void Publisher_DisposesNonSharedCommsServer() { var server = new MockCommsServer(); var publisher = new TestDevicePublisher(server); publisher.AddDevice(CreateValidRootDevice()); publisher.Dispose(); Assert.IsTrue(server.IsDisposed); }
public void Publisher_SearchResponse_NoResponseWithMissngMXHeader() { var rootDevice = CreateValidRootDevice(); var server = new MockCommsServer(); using (var publisher = new TestDevicePublisher(server)) { publisher.SupportPnpRootDevice = false; publisher.AddDevice(rootDevice); ReceivedUdpData searchRequest = GetSearchRequestMessageWithoutMXHeader(SsdpConstants.UpnpDeviceTypeRootDevice); server.MockReceiveMessage(searchRequest); server.WaitForMockMessage(1500); var searchResponses = GetSentMessages(server.SentMessages); Assert.AreEqual(0, searchResponses.Count()); } }
public void Publisher_SearchResponse_NoResponseWithNonNumericMXHeader() { var rootDevice = CreateValidRootDevice(); var server = new MockCommsServer(); using (var publisher = new TestDevicePublisher(server)) { publisher.SupportPnpRootDevice = false; publisher.AddDevice(rootDevice); ReceivedUdpData searchRequest = GetSearchRequestMessageWithCustomMXHeader(rootDevice.Udn, "-1"); server.MockReceiveMessage(searchRequest); server.WaitForMockMessage(1500); var searchResponses = GetSentMessages(server.SentMessages); Assert.AreEqual(0, searchResponses.Count()); } }