Inheritance: WoopsaDynamicClientObject, IDisposable
        public void TestWoopsaDynamicNotification()
        {
            TestObjectServer objectServer = new TestObjectServer();
            using (WoopsaServer server = new WoopsaServer(objectServer))
            {
                // Solution with dynamic client
                using (dynamic dynamicClient = new WoopsaDynamicClient("http://localhost/woopsa"))
                {
                    int channel = dynamicClient.SubscriptionService.CreateSubscriptionChannel(QUEUE_SIZE);
                    // Subscription for a valid variable
                    dynamicClient.SubscriptionService.RegisterSubscription(channel,
                       WoopsaValue.WoopsaRelativeLink("/Votes"), TimeSpan.FromMilliseconds(MONITOR_INTERVAL),
                       TimeSpan.FromMilliseconds(PUBLISH_INTERVAL));

                    Stopwatch watch = new Stopwatch();
                    WoopsaValue lastNotifications;
                    WoopsaJsonData jsonData;
                    int lastNotificationId;
                    watch.Start();
                    do
                    {
                        lastNotifications = dynamicClient.SubscriptionService.WaitNotification(channel, 0);
                        Assert.AreEqual(lastNotifications.Type, WoopsaValueType.JsonData);
                        jsonData = lastNotifications.JsonData;
                        if (watch.ElapsedMilliseconds > 1000)
                            Assert.Fail("Timeout without receveiving any notification");
                    }
                    while (jsonData.Length == 0);
                    lastNotificationId = jsonData[jsonData.Length - 1]["Id"];
                    Assert.AreEqual(lastNotificationId, 1);
                    // Get again the same notification
                    lastNotifications = dynamicClient.SubscriptionService.WaitNotification(channel, 0);
                    jsonData = lastNotifications.JsonData;
                    Assert.IsTrue(jsonData.IsArray);
                    Assert.AreEqual(jsonData.Length, 1);
                    Assert.IsTrue(jsonData[0].IsDictionary);
                    lastNotificationId = jsonData[jsonData.Length - 1]["Id"];
                    Assert.AreEqual(lastNotificationId, 1);
                    // Generate a new notification
                    objectServer.Votes++;
                    Thread.Sleep(PUBLISH_INTERVAL * 10);
                    // Check we have now 2
                    lastNotifications = dynamicClient.SubscriptionService.WaitNotification(channel, 0);
                    jsonData = lastNotifications.JsonData;
                    Assert.IsTrue(jsonData.IsArray);
                    Assert.AreEqual(jsonData.Length, 2);
                    Assert.IsTrue(jsonData[0].IsDictionary);
                    lastNotificationId = jsonData[jsonData.Length - 1]["Id"];
                    Assert.AreEqual(lastNotificationId, 2);
                    // Check we can remove 1 and still have 1
                    lastNotifications = dynamicClient.SubscriptionService.WaitNotification(channel, 1);
                    jsonData = lastNotifications.JsonData;
                    Assert.AreEqual(jsonData.Length, 1);
                    lastNotificationId = jsonData[jsonData.Length - 1]["Id"];
                    Assert.AreEqual(lastNotificationId, 2);
                    // Enable the code below to test the wait of the timeout when they are 0 notifications pending
                    /*
                    // Check we can remove 1 and have 0. This takes 5 seconds (we wait the timeout)
                    lastNotifications = dynamicClient.SubscriptionService.WaitNotification(channel, lastNotificationId);
                    jsonData = lastNotifications.JsonData;
                    Assert.AreEqual(jsonData.Length, 0);
                    */
                }
            }
        }
        public void TestWoopsaDynamicNotificationUnexistingProperty()
        {
            TestObjectServer objectServer = new TestObjectServer();
            using (WoopsaServer server = new WoopsaServer(objectServer))
            {
                // Solution with dynamic client
                using (dynamic dynamicClient = new WoopsaDynamicClient("http://localhost/woopsa"))
                {
                    int channel = dynamicClient.SubscriptionService.CreateSubscriptionChannel(QUEUE_SIZE);
                    // Subscription for an nonexistent variable (should work)
                    dynamicClient.SubscriptionService.RegisterSubscription(channel,
                        WoopsaValue.WoopsaRelativeLink("/Vote"), TimeSpan.FromMilliseconds(MONITOR_INTERVAL),
                        TimeSpan.FromMilliseconds(PUBLISH_INTERVAL));

                    Stopwatch watch = new Stopwatch();
                    WoopsaValue lastNotifications;
                    WoopsaJsonData jsonData;
                    int lastNotificationId;
                    watch.Start();
                    do
                    {
                        lastNotifications = dynamicClient.SubscriptionService.WaitNotification(channel, 0);
                        Assert.AreEqual(lastNotifications.Type, WoopsaValueType.JsonData);
                        jsonData = lastNotifications.JsonData;
                        if (watch.ElapsedMilliseconds > 1000)
                            Assert.Fail("Timeout without receveiving any notification");
                    }
                    while (jsonData.Length == 0);
                    lastNotificationId = jsonData[jsonData.Length - 1]["Id"];
                    Assert.AreEqual(lastNotificationId, 1);
                    // Get again the same notification
                    lastNotifications = dynamicClient.SubscriptionService.WaitNotification(channel, 0);
                    jsonData = lastNotifications.JsonData;
                    Assert.IsTrue(jsonData.IsArray);
                    Assert.AreEqual(jsonData.Length, 1);
                    Assert.IsTrue(jsonData[0].IsDictionary);
                    lastNotificationId = jsonData[jsonData.Length - 1]["Id"];
                    Assert.AreEqual(lastNotificationId, 1);
                }
            }
        }
 public void TestWoopsaServerPerformance()
 {
     TestObjectServer objectServer = new TestObjectServer();
     using (WoopsaServer server = new WoopsaServer(objectServer))
     {
         using (dynamic dynamicClient = new WoopsaDynamicClient("http://localhost/woopsa"))
         {
             Stopwatch watch = new Stopwatch();
             watch.Start();
             dynamicClient.Votes = 0;
             Console.WriteLine("First invocation duration : {0} ms", watch.Elapsed.TotalMilliseconds);
             int i = 0;
             watch.Restart();
             while (watch.Elapsed < TimeSpan.FromSeconds(1))
             {
                 dynamicClient.Votes = i;
                 Assert.AreEqual(objectServer.Votes, i);
                 Assert.AreEqual((int)dynamicClient.Votes, i);
                 i++;
             }
             Console.WriteLine("Invocation duration : {0} ms", watch.Elapsed.TotalMilliseconds / 2 / i);
             // TODO : Votes.Change does not work as Votes is a WoopsaValue does not contain Change !?!
             //				dynamicClient.Votes.Change += new EventHandler<WoopsaNotificationEventArgs>((o, e) => Console.WriteLine("Value : {0}", e.Value.ToInt32()));
             //		Thread.Sleep(100);
             //	dynamicClient.Votes = 15;
             //			WoopsaClient client = new WoopsaClient("http://localhost/woopsa");
             //				int votes = client.Properties.ByName("Votes").Value.ToInt32();
             //				client.Properties.ByName("Votes");
         }
     }
 }