public void TransferServiceInfo()
        {
            var publishInfo = new ServiceInfo();

            publishInfo.Name     = "Pubtest";
            publishInfo.Port     = 9999;
            publishInfo.Priority = 10;
            publishInfo.Weight   = 10;
            publishInfo.Flags.Add("TestFlag");
            publishInfo.Data["TestData"] = "TestValue";

            ServiceInfo recvInfo = null;

            var service = new ConnectedServiceMock("10.99.99.99");

            using (var publisher = new ServicePublisher(service))
            {
                var watcher = new ServiceWatchManager(service);
                publisher.AddService("_pubtest._tcp.local", publishInfo);
                publisher.Start();
                var watch = watcher.WatchService("_pubtest._tcp.local", (nic, x) => recvInfo = x);
                watch.Start();
                Assert.AreEqual(publishInfo.Name, recvInfo.Name);
                Assert.AreEqual(publishInfo.Port, recvInfo.Port);
                Assert.AreEqual(publishInfo.Priority, recvInfo.Priority);
                Assert.AreEqual(publishInfo.Weight, recvInfo.Weight);
                Assert.AreEqual(publishInfo.Flags[0], recvInfo.Flags[0]);
                Assert.AreEqual(publishInfo.Data["TestData"], recvInfo.Data["TestData"]);
                Assert.AreEqual(IPAddress.Parse("10.99.99.99"), recvInfo.IP4Address);
            }

            Assert.IsFalse(service.Running);
        }
Пример #2
0
        public void TestWatchServiceSendsRequestPacket()
        {
            string testServiceLookup = "scooby.doo.local";
            var    mockCore          = new Mock <IServiceCore>();

            mockCore.Setup(x => x.Connected).Returns(true);
            var    thing         = new ServiceWatchManager(mockCore.Object);
            Packet requestPacket = null;

            mockCore.Setup(x => x.SendPacket(It.IsAny <Packet>())).Callback <Packet>(x => requestPacket = x).Verifiable();

            var watcher = thing.WatchService(testServiceLookup, (nic, info) => { });

            watcher.Start();
            var ptr = requestPacket.Queries.Select(x => x.Record).Where(x => x.RecordType == 12).First();

            Assert.AreEqual(1, ptr.Class);
            Assert.AreEqual(testServiceLookup, ptr.Name);
        }
Пример #3
0
        public void TestServiceWatchManagerCallback()
        {
            var         mockCore    = new Mock <IServiceCore>();
            var         thing       = new ServiceWatchManager(mockCore.Object);
            ServiceInfo serviceInfo = null;

            thing.WatchService("scooby.doo.local", (net, info) =>
            {
                serviceInfo = info;
            });
            var testPacket = BuildResponsePacket();

            mockCore.Raise(x => x.PacketReceived += null, testPacket, new IPEndPoint(IPAddress.Parse("192.168.1.1"), 5353));

            Assert.AreEqual("Treats", serviceInfo.Name);
            Assert.AreEqual("scooby.doo.local", serviceInfo.Protocol);
            Assert.AreEqual(9999, serviceInfo.Port);
            Assert.AreEqual(0, serviceInfo.Weight);
            Assert.AreEqual(0, serviceInfo.Priority);
            Assert.AreEqual(IPAddress.Parse("192.168.1.1"), serviceInfo.IP4Address);
            Assert.AreEqual(IPAddress.Parse("fe80::20c:29ff:fe0d:e789"), serviceInfo.IP6Address);
        }