public void RegisterBusListenerTest()
        {
            BusAttachment service = new BusAttachment("service", true, 4);

            service.Start();
            service.ConnectAsync(connectSpec).AsTask().Wait();
            service.RequestName("org.alljoyn.service", (byte)RequestNameType.DBUS_NAME_DO_NOT_QUEUE);
            service.BindSessionPort(78, new ushort[1], new SessionOpts(TrafficType.TRAFFIC_MESSAGES, false,
                                                                       ProximityType.PROXIMITY_ANY, TransportMaskType.TRANSPORT_ANY), new SessionPortListener(service));
            service.AdvertiseName("org.alljoyn.service", TransportMaskType.TRANSPORT_ANY);

            BusAttachment   bus = new BusAttachment("buslistenertest", true, 4);
            BusListenerTest bl  = new BusListenerTest(bus);

            bus.RegisterBusListener(bl.bl);
            listenerRegistered.WaitOne();
            bus.Start();
            bus.ConnectAsync(connectSpec).AsTask().Wait();
            bus.RequestName("org.alljoyn.buslistener", (byte)RequestNameType.DBUS_NAME_DO_NOT_QUEUE);
            nameOwnerChanged.WaitOne();
            bus.FindAdvertisedName("org.alljoyn.service");
            foundAdvertisedName.WaitOne();
            service.CancelAdvertiseName("org.alljoyn.service", TransportMaskType.TRANSPORT_ANY);
            lostAdvertisedName.WaitOne();
            bus.CancelFindAdvertisedName("org.alljoyn.service");
            bus.UnregisterBusListener(bl.bl);
            listenerUnregistered.WaitOne();
            bus.DisconnectAsync(connectSpec).AsTask().Wait();
            // BUGBUG: Don't receive the BusDisconnected signal (this will wait indefinitely)
            //busDisconnected.WaitOne();
            bus.StopAsync().AsTask().Wait();
            // BUGBUG: Don't receive the BusStopping signal (this will wait indefinitely)
            //busStopping.WaitOne();
        }
        public void RegisterBusListenerTest()
        {
            BusAttachment service = new BusAttachment("service", true, 4);
            service.Start();
            service.ConnectAsync(connectSpec).AsTask().Wait();
            service.RequestName("org.alljoyn.service", (byte)RequestNameType.DBUS_NAME_DO_NOT_QUEUE);
            service.BindSessionPort(78, new ushort[1], new SessionOpts(TrafficType.TRAFFIC_MESSAGES, false, 
                ProximityType.PROXIMITY_ANY, TransportMaskType.TRANSPORT_ANY), new SessionPortListener(service));
            service.AdvertiseName("org.alljoyn.service", TransportMaskType.TRANSPORT_ANY);

            BusAttachment bus = new BusAttachment("buslistenertest", true, 4);
            BusListenerTest bl = new BusListenerTest(bus);
            bus.RegisterBusListener(bl.bl);
            listenerRegistered.WaitOne();
            bus.Start();
            bus.ConnectAsync(connectSpec).AsTask().Wait();
            bus.RequestName("org.alljoyn.buslistener", (byte)RequestNameType.DBUS_NAME_DO_NOT_QUEUE);
            nameOwnerChanged.WaitOne();
            bus.FindAdvertisedName("org.alljoyn.service");
            foundAdvertisedName.WaitOne();
            service.CancelAdvertiseName("org.alljoyn.service", TransportMaskType.TRANSPORT_ANY);
            lostAdvertisedName.WaitOne();
            bus.CancelFindAdvertisedName("org.alljoyn.service");
            bus.UnregisterBusListener(bl.bl);
            listenerUnregistered.WaitOne();
            bus.DisconnectAsync(connectSpec).AsTask().Wait();
            // BUGBUG: Don't receive the BusDisconnected signal (this will wait indefinitely)
            //busDisconnected.WaitOne();
            bus.StopAsync().AsTask().Wait();
            // BUGBUG: Don't receive the BusStopping signal (this will wait indefinitely)
            //busStopping.WaitOne();
        }
        public void AdvertisingTest()
        {
            BusAttachment bus = new BusAttachment("advertise", true, 4);

            bus.Start();
            bus.ConnectAsync(connectSpec).AsTask().Wait();

            BusAttachment        clientConsumer = new BusAttachment("clientConsumer", true, 4);
            AdvertiseBusListener bl             = new AdvertiseBusListener(clientConsumer);

            clientConsumer.Start();
            clientConsumer.ConnectAsync(connectSpec).AsTask().Wait();
            clientConsumer.FindAdvertisedName("org.alljoyn.one");
            clientConsumer.FindAdvertisedName("org.alljoyn.two");
            clientConsumer.FindAdvertisedName("org.alljoyn.three");
            clientConsumer.FindAdvertisedName("org.alljoyn.four");

            byte   flags = (byte)RequestNameType.DBUS_NAME_DO_NOT_QUEUE;
            string name1 = "org.alljoyn.one";
            string name2 = "org.alljoyn.two";
            string name3 = "org.alljoyn.three";
            string name4 = "org.alljoyn.four";

            bus.RequestName(name1, flags);
            bus.RequestName(name2, flags);
            bus.RequestName(name3, flags);
            bus.RequestName(name4, flags);

            bus.AdvertiseName(name1, TransportMaskType.TRANSPORT_ANY);
            bus.AdvertiseName(name2, TransportMaskType.TRANSPORT_ANY);
            bus.AdvertiseName(name3, TransportMaskType.TRANSPORT_ANY);
            bus.AdvertiseName(name4, TransportMaskType.TRANSPORT_ANY);

            gotAllNames.WaitOne();

            lock (bl.FoundNames)
            {
                Assert.IsTrue(bl.FoundNames.Contains(name1));
                Assert.IsTrue(bl.FoundNames.Contains(name2));
                Assert.IsTrue(bl.FoundNames.Contains(name3));
                Assert.IsTrue(bl.FoundNames.Contains(name4));
            }

            gotAllNames.Reset();

            bus.CancelAdvertiseName(name1, TransportMaskType.TRANSPORT_ANY);
            bus.CancelAdvertiseName(name2, TransportMaskType.TRANSPORT_ANY);
            bus.CancelAdvertiseName(name3, TransportMaskType.TRANSPORT_ANY);
            bus.CancelAdvertiseName(name4, TransportMaskType.TRANSPORT_ANY);

            gotAllNames.WaitOne();

            lock (bl.LostNames)
            {
                Assert.IsTrue(bl.LostNames.Contains(name1));
                Assert.IsTrue(bl.LostNames.Contains(name2));
                Assert.IsTrue(bl.LostNames.Contains(name3));
                Assert.IsTrue(bl.LostNames.Contains(name4));
            }

            // TODO: Make sure we're not still receiving advertisements for the names
        }
        public void AdvertisingTest()
        {
            BusAttachment bus = new BusAttachment("advertise", true, 4);
            bus.Start();
            bus.ConnectAsync(connectSpec).AsTask().Wait();

            BusAttachment clientConsumer = new BusAttachment("clientConsumer", true, 4);
            AdvertiseBusListener bl = new AdvertiseBusListener(clientConsumer);
            clientConsumer.Start();
            clientConsumer.ConnectAsync(connectSpec).AsTask().Wait();
            clientConsumer.FindAdvertisedName("org.alljoyn.one");
            clientConsumer.FindAdvertisedName("org.alljoyn.two");
            clientConsumer.FindAdvertisedName("org.alljoyn.three");
            clientConsumer.FindAdvertisedName("org.alljoyn.four");

            byte flags = (byte)RequestNameType.DBUS_NAME_DO_NOT_QUEUE;
            string name1 = "org.alljoyn.one";
            string name2 = "org.alljoyn.two";
            string name3 = "org.alljoyn.three";
            string name4 = "org.alljoyn.four";

            bus.RequestName(name1, flags);
            bus.RequestName(name2, flags);
            bus.RequestName(name3, flags);
            bus.RequestName(name4, flags);

            bus.AdvertiseName(name1, TransportMaskType.TRANSPORT_ANY);
            bus.AdvertiseName(name2, TransportMaskType.TRANSPORT_ANY);
            bus.AdvertiseName(name3, TransportMaskType.TRANSPORT_ANY);
            bus.AdvertiseName(name4, TransportMaskType.TRANSPORT_ANY);

            gotAllNames.WaitOne();

            lock (bl.FoundNames)
            {
                Assert.IsTrue(bl.FoundNames.Contains(name1));
                Assert.IsTrue(bl.FoundNames.Contains(name2));
                Assert.IsTrue(bl.FoundNames.Contains(name3));
                Assert.IsTrue(bl.FoundNames.Contains(name4));
            }

            gotAllNames.Reset();

            bus.CancelAdvertiseName(name1, TransportMaskType.TRANSPORT_ANY);
            bus.CancelAdvertiseName(name2, TransportMaskType.TRANSPORT_ANY);
            bus.CancelAdvertiseName(name3, TransportMaskType.TRANSPORT_ANY);
            bus.CancelAdvertiseName(name4, TransportMaskType.TRANSPORT_ANY);

            gotAllNames.WaitOne();

            lock (bl.LostNames)
            {
                Assert.IsTrue(bl.LostNames.Contains(name1));
                Assert.IsTrue(bl.LostNames.Contains(name2));
                Assert.IsTrue(bl.LostNames.Contains(name3));
                Assert.IsTrue(bl.LostNames.Contains(name4));
            }

            // TODO: Make sure we're not still receiving advertisements for the names
        }