public void Discover_ServiceInstance() { var service = new ServiceProfile("y", "_sdtest-2._udp", 1024); var done = new ManualResetEvent(false); var mdns = new MulticastService(); var sd = new ServiceDiscovery(mdns); mdns.NetworkInterfaceDiscovered += (s, e) => { sd.QueryServiceInstances(service.ServiceName); }; sd.ServiceInstanceDiscovered += (s, e) => { if (e.ServiceInstanceName == service.FullyQualifiedName) { Assert.IsNotNull(e.Message); done.Set(); } }; try { sd.Advertise(service); mdns.Start(); Assert.IsTrue(done.WaitOne(TimeSpan.FromSeconds(1)), "instance not found"); } finally { sd.Dispose(); mdns.Stop(); } }
public void Unadvertise() { var service = new ServiceProfile("z", "_sdtest-7._udp", 1024); var done = new ManualResetEvent(false); var mdns = new MulticastService(); var sd = new ServiceDiscovery(mdns); mdns.NetworkInterfaceDiscovered += (s, e) => sd.QueryAllServices(); sd.ServiceInstanceShutdown += (s, e) => { if (e.ServiceInstanceName == service.FullyQualifiedName) { done.Set(); } }; try { sd.Advertise(service); mdns.Start(); sd.Unadvertise(service); Assert.IsTrue(done.WaitOne(TimeSpan.FromSeconds(1)), "goodbye timeout"); } finally { sd.Dispose(); mdns.Stop(); } }
public void Discover_AllServices() { var service = new ServiceProfile("x", "_sdtest-2._udp", 1024); var done = new ManualResetEvent(false); var mdns = new MulticastService(); var sd = new ServiceDiscovery(mdns); mdns.NetworkInterfaceDiscovered += (s, e) => sd.QueryAllServices(); sd.ServiceDiscovered += (s, serviceName) => { if (serviceName == service.QualifiedServiceName) { done.Set(); } }; try { sd.Advertise(service); mdns.Start(); Assert.IsTrue(done.WaitOne(TimeSpan.FromSeconds(1)), "DNS-SD query timeout"); } finally { sd.Dispose(); mdns.Stop(); } }
public void Discover_ServiceInstance_WithAnswersContainingAdditionRecords() { var service = new ServiceProfile("y", "_sdtest-2._udp", 1024); var done = new ManualResetEvent(false); var mdns = new MulticastService(); var sd = new ServiceDiscovery(mdns) { AnswersContainsAdditionalRecords = true }; Message discovered = null; mdns.NetworkInterfaceDiscovered += (s, e) => { sd.QueryServiceInstances(service.ServiceName); }; sd.ServiceInstanceDiscovered += (s, e) => { if (e.ServiceInstanceName == service.FullyQualifiedName) { Assert.IsNotNull(e.Message); discovered = e.Message; done.Set(); } }; try { sd.Advertise(service); mdns.Start(); Assert.IsTrue(done.WaitOne(TimeSpan.FromSeconds(1)), "instance not found"); Assert.AreEqual(0, discovered.AdditionalRecords.Count); Assert.IsTrue(discovered.Answers.Count > 1); } finally { sd.Dispose(); mdns.Stop(); } }