コード例 #1
0
        public void ThenItShouldReturnTimeStamp()
        {
            Pubnub pubnub = new Pubnub(
                "demo",
                "demo",
                "",
                "",
                false
            );

            bool responseStatus = false;

            string strResponse = "";
            pubnub.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e) {
                if (e.PropertyName == "Time") {
                    strResponse = ((Pubnub)sender).Time[0].ToString();

                    responseStatus = true;
                }
            };

            pubnub.time();
            while (!responseStatus);

            Console.WriteLine (strResponse);
            Assert.AreNotEqual("0",strResponse);
        }
コード例 #2
0
        public void ThenItShouldReturnReceivedMessage()
        {
            Pubnub pubnub = new Pubnub(
                "demo",
                "demo",
                "",
                "",
                false
            );
            string channel = "hello_world";

            Common.deliveryStatus = false;

            pubnub.presence(channel, 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);
                }
                Assert.AreEqual(fields[2], "hello_world-pnpres");
            }
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
        public void IfHereNowIsCalledThenItShouldReturnInfo()
        {
            Pubnub pubnub = new Pubnub(
               "demo",
               "demo",
               "",
               "",
               false
               );
            string channel = "hello_world";

            bool responseStatus = false;
            List<object> lstHistory = null;

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

                if (e.PropertyName == "Here_Now")
                {
                    lstHistory = ((Pubnub)sender).Here_Now;

                    responseStatus = true;
                }
            };

            pubnub.here_now(channel);
            while (!responseStatus) ;

            string strResponse = "";
            if (lstHistory.Equals (null)) {
                Assert.Fail("Null response");
            }
            else
            {
                //Console.WriteLine(_message["text"]);
                foreach(object lst in lstHistory)
                {
                    strResponse = lst.ToString();
                    Console.WriteLine(strResponse);
                    Assert.IsNotEmpty(strResponse);
                }
                Dictionary<string, object> message = (Dictionary<string, object>)lstHistory[0];
                foreach(KeyValuePair<String, object> entry in message)
                {
                    Console.WriteLine("value:" + entry.Value + "  " + "key:" + entry.Key);
                }

                object[] objUuid = (object[])message["uuids"];
                foreach (object obj in objUuid)
                {
                    Console.WriteLine(obj.ToString());
                }
                //Assert.AreNotEqual(0, message["occupancy"]);
            }
        }
コード例 #6
0
        public void ThenItShouldGenerateUniqueIdentifier()
        {
            Pubnub pubnub = new Pubnub(
                "demo",
                "demo",
                "",
                "",
                false
            );

            Assert.IsNotNull(pubnub.generateGUID());
        }
コード例 #7
0
ファイル: Common.cs プロジェクト: crimsonred/pubnub-api
 public static long Timestamp(Pubnub pubnub)
 {
     deliveryStatus = false;
     pubnub.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
     {
         if (e.PropertyName == "Time")
         {
             deliveryStatus = true;
         }
     };
     pubnub.time();
     while (!deliveryStatus) ;
     return Convert.ToInt64(pubnub.Time[0].ToString());
 }
コード例 #8
0
        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));
        }
コード例 #9
0
        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);
                }
            }
        }
コード例 #10
0
        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));
        }
コード例 #11
0
        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);
                }
            }
        }
コード例 #12
0
        public void IfHereNowIsCalledThenItShouldReturnInfo()
        {
            Pubnub pubnub = new Pubnub(
               "demo",
               "demo",
               "",
               "",
               false
               );
            string channel = "hello_world";

            Common.deliveryStatus = false;

            pubnub.here_now(channel, 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 lst in fields)
                {
                    strResponse = lst.ToString();
                    Console.WriteLine(strResponse);
                    Assert.IsNotEmpty(strResponse);
                }
                Dictionary<string, object> message = (Dictionary<string, object>)fields[0];
                foreach(KeyValuePair<String, object> entry in message)
                {
                    Console.WriteLine("value:" + entry.Value + "  " + "key:" + entry.Key);
                }

                object[] objUuid = (object[])message["uuids"];
                foreach (object obj in objUuid)
                {
                    Console.WriteLine(obj.ToString());
                }
                //Assert.AreNotEqual(0, message["occupancy"]);
            }
        }
コード例 #13
0
        public void ThenItShouldReturnReceivedMessage()
        {
            Pubnub pubnub = new Pubnub(
                "demo",
                "demo",
                "",
                "",
                false
            );
            string channel = "hello_world";

            bool responseStatus = false;
            List<object> lstHistory = null;

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

                if (e.PropertyName == "Presence")
                {
                    lstHistory = ((Pubnub)sender).Presence;

                    responseStatus = true;
                }
            };

            pubnub.presence(channel);
            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);
                }
                Assert.AreEqual(lstHistory[2], "hello_world-pnpres");
            }
        }
コード例 #14
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);
        }
コード例 #15
0
        public void ThenItShouldReturnReceivedMessage()
        {
            string status = "";
            Pubnub pubnub = new Pubnub (
                   "demo",
                   "demo",
                   "",
                   "",
                   false);
            string channel = "hello_world";

            bool responseStatus = false;

            List<object> lstSubscribe = null;

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

                    responseStatus = true;
                }
            };

            pubnub.subscribe (channel);

            while (!responseStatus)
                ;

            string strResponse = "";
            Console.WriteLine (lstSubscribe);
            if (lstSubscribe.Equals (null)) {
                Assert.Fail("Null response");
            } else {
                foreach (object lst in lstSubscribe) {
                    strResponse = lst.ToString ();
                    Console.WriteLine (strResponse);
                    Assert.IsNotEmpty (strResponse);
                }
            }
        }
コード例 #16
0
        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);
        }
コード例 #17
0
        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);
            }
        }
コード例 #18
0
        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);
                }
            }
        }
コード例 #19
0
        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);
              }
              }
        }
コード例 #20
0
        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));
        }
コード例 #21
0
        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));
        }
コード例 #22
0
        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++;
                }
            }
        }
コード例 #23
0
        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));
        }