public static void DetailedHistory_Decrypted_Example()
        {
            Pubnub pubnub = new Pubnub(
                    "demo",
                    "demo",
                    "",
                    "",
                    false);
            string channel = "my_channel";
            pubnub.CIPHER_KEY = "enigma";
            string msg = "Test Message";

            Common.deliveryStatus = false;
            pubnub.publish(channel, msg, Common.DisplayReturnMessage);
            while (!Common.deliveryStatus) ;

            Common.deliveryStatus = false;
            pubnub.detailedHistory(channel, 1, Common.DisplayReturnMessage);
            while (!Common.deliveryStatus) ;
            Console.WriteLine("\n*********** DetailedHistory Messages Received*********** ");

            if (Common.objResponse.Equals(null))
            {
              Assert.Fail("Null response");
            }
            else
            {
                IList<object> fields = Common.objResponse as IList<object>;
                Console.WriteLine("fields[0]: " + fields[0]);
                Console.WriteLine("fields[1]: " + fields[1]);
                Assert.AreEqual(fields[0], msg);
            }
        }
        public void NullMessage()
        {
            Pubnub pubnub = new Pubnub(
                "demo",
                "demo",
                "",
                "",
                false
            );
            string channel = "hello_world";
            string message = null;

            bool deliveryStatus = false;

            string strSent = "";
            string strOne = "";
            //Add a PropertyChanged event handler
            pubnub.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                if (e.PropertyName == "Publish")
                {
                    strSent = ((Pubnub)sender).Publish[1].ToString();
                    strOne = ((Pubnub)sender).Publish[0].ToString();
                    Console.WriteLine(strSent);
                    Console.WriteLine(strOne);
                    deliveryStatus = true;
                }
            };

            pubnub.publish(channel, message);
            //wait till the response is received from the server
            while (!deliveryStatus) ;
            Assert.AreEqual("Sent", strSent);
            Assert.AreEqual("1", strOne);
        }
        public void IfSSLNotProvidedThenDefaultShouldBeFalse()
        {
            Pubnub pubnub = new Pubnub(
                "demo",
                "demo",
                ""
            );
            string channel = "hello_world";
            string message = "Pubnub API Usage Example";

            pubnub.PropertyChanged += new PropertyChangedEventHandler(Pubnub_PropertyChanged);

            Assert.AreEqual(true, pubnub.publish(channel, message));
        }
        public void ItShouldReturnDetailedHistory()
        {
            Pubnub pubnub = new Pubnub(
                "demo",
                "demo",
                "",
                "",
                false
            );
            string channel = "hello_world";

            //pubnub.PropertyChanged += new PropertyChangedEventHandler(Pubnub_PropertyChanged);

            //publish a test message.
            pubnub.publish (channel, "Test message");
            bool responseStatus = false;

            object objHistory = null;

            pubnub.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e) {

                if (e.PropertyName == "DetailedHistory")
                {
                    objHistory = ((Pubnub)sender).DetailedHistory;

                    responseStatus = true;
                }
            };

            pubnub.detailedHistory(channel, 1);

            while (!responseStatus) ;

            string strResponse = "";
            if (objHistory.Equals (null)) {
                Assert.Fail("Null response");
            }
            else
            {
                List<object> fields = (List<object>)objHistory;

                foreach(object lst in fields)
                {
                    strResponse = lst.ToString();
                    Console.WriteLine(strResponse);
                    Assert.IsNotEmpty(strResponse);
                }
            }
        }
        public void NullShouldBeTreatedAsEmpty()
        {
            Pubnub pubnub = new Pubnub(
                null,
                "demo",
                null,
                null,
                false
            );
            string channel = "my/channel";
            string message = "Pubnub API Usage Example";

            pubnub.PropertyChanged += new PropertyChangedEventHandler(Pubnub_PropertyChanged);

            Assert.AreEqual(false, pubnub.publish(channel, message));
        }
        public void ThenItShouldReturnHistoryMessages()
        {
            Pubnub pubnub = new Pubnub (
                "demo",
                "demo",
                "",
                "",
                false
            );
            string channel = "hello_world";
            bool responseStatus = false;
            //publish a test message.
            pubnub.publish (channel, "Test message");

            List<object> lstHistory = null;

            pubnub.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e) {
                if (e.PropertyName == "History")
                {
                    lstHistory = ((Pubnub)sender).History;

                    responseStatus = true;
                }
            };

            pubnub.history(channel, 1);

            while (!responseStatus) ;

            string strResponse = "";
            if (lstHistory.Equals (null)) {
                Assert.Fail("Null response");
            }
            else
            {
                foreach(object lst in lstHistory)
                {
                    strResponse = lst.ToString();
                    Console.WriteLine(strResponse);
                    Assert.IsNotEmpty(strResponse);
                }
            }
        }
Example #7
0
        public void PublishAndHistory()
        {
            //demo init
            Pubnub pubnub = new Pubnub(
                    "demo",
                    "demo",
                    "",
                    "",
                    false);
            //cipher key
            pubnub.CIPHER_KEY = "enigma";
            //channel
            string channel = "hello_world";
            //string message
            string strMsg = "yay!";
            //publish the message
            pubnub.publish(channel, strMsg);

            bool deliveryStatus = false;

            string strResponse = "empty";
            //create an event handler for the proertyChanged event.
            //This will be called when we get a response from the server
            pubnub.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                if (e.PropertyName == "DetailedHistory")
                {
                    Console.WriteLine("\n*********** DetailedHistory Messages *********** ");
                    List<object> lstResponse  = (List<object>)((Pubnub)sender).DetailedHistory;
                    strResponse = lstResponse[0].ToString();
                    deliveryStatus = true;
                }
            };

            pubnub.detailedHistory(channel, 1);
            //wait till the deliveryStatus is true.
            //the variable is modified on the PropertyChanged event
            while (!deliveryStatus) ;

            Assert.AreEqual(strMsg, strResponse);
        }
        public void NullMessage()
        {
            Pubnub pubnub = new Pubnub(
                "demo",
                "demo",
                "",
                "",
                false
            );
            string channel = "hello_world";
            string message = null;

            Common.deliveryStatus = false;

            pubnub.publish(channel, message, Common.DisplayReturnMessage);
            //wait till the response is received from the server
            while (!Common.deliveryStatus) ;
            IList<object> fields = Common.objResponse as IList<object>;
            string strSent = fields[1].ToString();
            string strOne = fields[0].ToString();
            Assert.AreEqual("Sent", strSent);
            Assert.AreEqual("1", strOne);
        }
        public static void TestEncryptedHistory()
        {
            Pubnub pubnub = new Pubnub(
                    "demo",
                    "demo",
                    "",
                    "",
                    false);
            string channel = "my_channel";

            Common.deliveryStatus = false;
            string message = "Pubnub API Usage Example - Publish";
            pubnub.CIPHER_KEY = "enigma";

            pubnub.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                if (e.PropertyName == "History")
                {
                    Console.WriteLine("\n*********** History Messages *********** ");
                    Common.deliveryStatus = true;
                }
            };
            Common.deliveryStatus = false;
            pubnub.publish(channel, message, Common.DisplayReturnMessage);
            while (!Common.deliveryStatus) ;

            Common.deliveryStatus = false;
            pubnub.history(channel, 1);
            while (!Common.deliveryStatus) ;
            if (pubnub.History[0].Equals (null)) {
                Assert.Fail("Null response");
            }
            else
            {
                Assert.AreEqual(pubnub.History[0], message);
            }
        }
        public static void DetailedHistory_Example()
        {
            Pubnub pubnub = new Pubnub(
                    "demo",
                    "demo",
                    "",
                    "",
                    false);
            string channel = "my_channel";
            pubnub.CIPHER_KEY = "";
            string msg = "Test Message";
            Common.deliveryStatus = false;
            pubnub.publish(channel, msg, Common.DisplayReturnMessage);
            while (!Common.deliveryStatus) ;

            Common.deliveryStatus = false;
            pubnub.detailedHistory(channel, 10, Common.DisplayReturnMessage);
            while (!Common.deliveryStatus) ;
            Console.WriteLine("\n*********** DetailedHistory Messages Received*********** ");

            if (Common.objResponse.Equals(null))
            {
              Assert.Fail("Null response");
            }
            else
            {
                IList<object> fields = Common.objResponse as IList<object>;

                foreach (object item in fields)
                {
                    string strResponse = item.ToString();
                    Console.WriteLine(String.Format("resp:{0}", strResponse));
                    Assert.IsNotEmpty(strResponse);
                }
            }
        }
        public void ThenSecretKeyShouldBeProvidedOptionally()
        {
            Pubnub pubnub = new Pubnub(
                "demo",
                "demo"
            );
            string channel = "my/channel";
            string message = "Pubnub API Usage Example";

            pubnub.PropertyChanged += new PropertyChangedEventHandler(Pubnub_PropertyChanged);

            Assert.AreEqual(true, pubnub.publish(channel, message));

            pubnub.SECRET_KEY = "key";
            Assert.AreEqual(true, pubnub.publish(channel, message));
        }
        public void ThenPublishKeyShouldNotBeEmptyAfterOverriden()
        {
            Pubnub pubnub = new Pubnub(
                "",
                "demo",
                "",
                "",
                false
            );
            string channel = "my/channel";
            string message = "Pubnub API Usage Example";

            pubnub.PropertyChanged += new PropertyChangedEventHandler(Pubnub_PropertyChanged);

            Assert.AreEqual(false, pubnub.publish(channel, message));
        }
        public void ThenPublishKeyShouldBeOverriden()
        {
            Pubnub pubnub = new Pubnub(
                "",
                "demo",
                "",
                "",
                false
            );
            string channel = "my/channel";
            string message = "Pubnub API Usage Example";

            //pubnub.PropertyChanged += new PropertyChangedEventHandler(Pubnub_PropertyChanged);

            pubnub.PUBLISH_KEY = "demo";
            Assert.AreEqual(true, pubnub.publish(channel, message, Common.DisplayReturnMessage));
        }
        public static void TestEncryptedDetailedHistory()
        {
            Pubnub pubnub = new Pubnub(
                    "demo",
                    "demo",
                    "",
                    "",
                    false);
            string channel = "my_channel";
            pubnub.CIPHER_KEY = "enigma";

            int total_msg = 10;
            long starttime = Common.Timestamp(pubnub);
            Dictionary<long, string> inputs = new Dictionary<long, string>();
            for (int i = 0; i < total_msg / 2; i++)
            {
                string msg = i.ToString();
                pubnub.publish(channel, msg, Common.DisplayReturnMessage);
                //long t = Timestamp();
                //inputs.Add(t, msg);
                Console.WriteLine("Message # " + i.ToString() + " published");
            }

            long midtime = Common.Timestamp(pubnub);
            for (int i = total_msg / 2; i < total_msg; i++)
            {
                string msg = i.ToString();
                pubnub.publish(channel, msg, Common.DisplayReturnMessage);
                //long t = Timestamp();
                //inputs.Add(t, msg);
                Console.WriteLine("Message # " + i.ToString() + " published");
            }

            long endtime = Common.Timestamp(pubnub);
            while (!Common.deliveryStatus) ;

            pubnub.detailedHistory(channel, total_msg, Common.DisplayReturnMessage);
            Common.deliveryStatus = false;
            while (!Common.deliveryStatus) ;
            Console.WriteLine("\n*********** DetailedHistory Messages Received*********** ");
            string strResponse = "";
            if (Common.objResponse.Equals(null))
            {
              Assert.Fail("Null response");
            }
            else
            {
                IList<object> fields = Common.objResponse as IList<object>;
                int j = 0;
                foreach (object item in fields)
                {
                    strResponse = item.ToString();
                    Console.WriteLine(String.Format("resp:{0} :: j: {1}", strResponse, j));
                    if(j<total_msg)
                        Assert.AreEqual(j.ToString(), strResponse);
                    j++;
                }
            }
        }
        public void ItShouldReturnDetailedHistory()
        {
            Pubnub pubnub = new Pubnub(
                    "demo",
                    "demo",
                    "",
                    "",
                    false
              );
              string channel = "hello_world";

              //pubnub.PropertyChanged += new PropertyChangedEventHandler(Pubnub_PropertyChanged);

              Common.deliveryStatus = false;
              //publish a test message.
              pubnub.publish(channel, "Test message", Common.DisplayReturnMessage);

              while (!Common.deliveryStatus)
            ;

              Common.deliveryStatus = false;
              pubnub.detailedHistory(channel, 1, Common.DisplayReturnMessage);
              while (!Common.deliveryStatus)
            ;

              string strResponse = "";
              if (Common.objResponse.Equals(null))
            {
              Assert.Fail("Null response");
            } else
              {
                IList<object> fields = Common.objResponse as IList<object>;
                foreach (object item in fields)
                  {
                    strResponse = item.ToString();
                    Console.WriteLine(strResponse);
                    Assert.IsNotEmpty(strResponse);
              }
              }
        }