Exemplo n.º 1
0
        void SubscribePublishAndParse (string message, Pubnub pubnub, Common common, string channel)
        {
            Random r = new Random ();
            channel = "hello_world_sub" + r.Next (1000);

            pubnub.Subscribe<string> (channel, common.DisplayReturnMessage, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy); 
            Thread.Sleep (5000);

            pubnub.Publish (channel, message, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy);

            common.WaitForResponse ();

            if (common.Response != null) {
                object[] deserializedMessage = Common.Deserialize<object[]> (common.Response.ToString ());
                if (deserializedMessage != null) {
                    Assert.True (message.Equals (deserializedMessage [0].ToString ()));
                } else {
                    Assert.Fail ("Test not successful");
                }
            } else {
                Assert.Fail ("No response");
            }
            common.DeliveryStatus = false;
            common.Response = null;

            pubnub.Unsubscribe<string> (channel, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);

            common.WaitForResponse (20);

            pubnub.EndPendingRequests ();

        }
        public void ItShouldReturnDetailedHistoryNoStore ()
        {
            Pubnub pubnub = new Pubnub (
                Common.PublishKey,
                Common.SubscribeKey,
                "",
                "",
                false
            );
            string channel = "hello_world_de1";
            string message = "Test Message No Store";

            Common common = new Common ();
            common.DeliveryStatus = false;
            common.Response = null;

            pubnub.PubnubUnitTest = common.CreateUnitTestInstance ("WhenDetailedHistoryIsRequested", "ItShouldReturnDetailedHistory");

            //publish a test message. 
            pubnub.Publish (channel, message, false, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);

            common.WaitForResponse ();

            common.DeliveryStatus = false;
            common.Response = null;
            //Thread.Sleep (2000);
            pubnub.DetailedHistory<string> (channel, 1, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);
            common.WaitForResponse ();

            ParseResponseNoStore (common.Response.ToString(), message);
            pubnub.EndPendingRequests ();
        }
    public void ThenShouldReturnUnsubscribedMessage()
    {
      Pubnub pubnub = new Pubnub("demo", "demo", "", "", false);
      
      Common common = new Common();
      common.DeliveryStatus = false;
      common.Response = null;
      
      pubnub.PubnubUnitTest = common.CreateUnitTestInstance("WhenUnsubscribedToAChannel", "ThenShouldReturnUnsubscribedMessage");
      
      string channel = "hello_world";

      pubnub.Subscribe<string>(channel, common.DisplayReturnMessageDummy, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);

      common.WaitForResponse();
      common.DeliveryStatus = false;
      common.Response = null;

      pubnub.Unsubscribe<string>(channel, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);
      common.WaitForResponse();

      if (common.Response.ToString().Contains ("Unsubscribed from")) {
        Console.WriteLine("Response:" + common.Response);
		Assert.NotNull(common.Response);
      }
      else
      {
		Assert.Fail("ThenShouldReturnUnsubscribedMessage failed");
      }    
    }
    public void ItShouldReturnDetailedHistory()
    {
      Pubnub pubnub = new Pubnub(
        "demo",
        "demo",
        "",
        "",
        false
        );
      string channel = "hello_world";
      string message = "Test Message";
      
      Common common = new Common();
      common.DeliveryStatus = false;
      common.Response = null;

      pubnub.PubnubUnitTest = common.CreateUnitTestInstance("WhenDetailedHistoryIsRequested" ,"ItShouldReturnDetailedHistory");
      
      //publish a test message. 
      pubnub.Publish(channel, message, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);
      
      common.WaitForResponse();

      common.DeliveryStatus = false;
      common.Response = null;
      pubnub.DetailedHistory(channel, 1, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);
      common.WaitForResponse();

      ParseResponse(common.Response, 0, 0, message);
    }
Exemplo n.º 5
0
        public void ThenItShouldReturnTimeStamp()
        {
            Pubnub pubnub = new Pubnub(
                "demo",
                "demo",
                "",
                "",
                false
            );

            Common common = new Common();
            common.DeliveryStatus = false;
            common.Response = null;

            pubnub.PubnubUnitTest = common.CreateUnitTestInstance("WhenGetRequestServerTime", "ThenItShouldReturnTimeStamp");;
            
            string response = "";

            pubnub.Time(common.DisplayReturnMessage, common.DisplayReturnMessageDummy);
           
            common.WaitForResponse();

            IList<object> fields = common.Response as IList<object>;
            response = fields[0].ToString();
            Console.WriteLine("Response:" + response);
			Assert.False(("0").Equals(response));
        }
        public void NullMessage()
        {
            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                                "",
                                "",
                                false
                            );
            string channel = "hello_world";
            string message = null;

            Common common = new Common();
            common.DeliveryStatus = false;
            common.Response = null;

            pubnub.Publish(channel, message, common.DisplayReturnMessage, common.DisplayReturnMessage);
            //wait till the response is received from the server
            common.WaitForResponse();
            if (common.Response != null)
                {
                    IList<object> fields = common.Response as IList<object>;
                    string sent = fields [1].ToString();
                    string one = fields [0].ToString();
                    Assert.AreEqual("Sent", sent);
                    Assert.AreEqual("1", one);
                } else
                {
                    Assert.Fail("Null response");
                }
        }
 public void ThenItShouldReturnSuccessCodeAndInfoForEncryptedComplexMessage2()
 {
     Pubnub pubnub = new Pubnub(
         Common.PublishKey,
         Common.SubscribeKey,
                       "",
                       "enigma",
                       false
                   );
     string channel = "hello_world";
     object message = new PubnubDemoObject();
   
     Common common = new Common();
   
     pubnub.PubnubUnitTest = common.CreateUnitTestInstance("WhenAMessageIsPublished", "ThenItShouldReturnSuccessCodeAndInfoForEncryptedComplexMessage2");
   
     common.DeliveryStatus = false;
     common.Response = null;
   
     pubnub.Publish(channel, message, common.DisplayReturnMessage, common.DisplayReturnMessage);
     //wait till the response is received from the server
     common.WaitForResponse();
     if (common.Response != null)
         {
             IList<object> fields = common.Response as IList<object>;
             string sent = fields [1].ToString();
             string one = fields [0].ToString();
             Assert.AreEqual("Sent", sent);
             Assert.AreEqual("1", one);
         } else
         {
             Assert.Fail("Null response");
         }
 }
Exemplo n.º 8
0
        public void ThenNonExistentChannelShouldReturnNotSubscribed ()
        {
            Pubnub pubnub = new Pubnub (Common.PublishKey,
                          Common.SubscribeKey, "", "", false);

            Common common = new Common ();
            common.DeliveryStatus = false;
            common.Response = null;
      
            pubnub.PubnubUnitTest = common.CreateUnitTestInstance ("WhenUnsubscribedToAChannel", "ThenNonExistentChannelShouldReturnNotSubscribed");
      
            string channel = "hello_world";
      
            pubnub.Unsubscribe<string> (channel, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy, common.DisplayReturnMessage);

            common.WaitForResponse ();

            Console.WriteLine ("Response:" + common.Response);
            if (common.Response.ToString ().ToLower ().Contains ("not subscribed")) {
                Assert.Pass ();
            } else {
                Assert.Fail ();
            }
            pubnub.EndPendingRequests ();
        }
Exemplo n.º 9
0
        public void ThenItShouldReturnTimeStampSSL ()
        {
            Pubnub pubnub = new Pubnub (
                                Common.PublishKey,
                                Common.SubscribeKey,
                                "",
                                "",
                                true
                            );

            Common common = new Common ();
            common.DeliveryStatus = false;
            common.Response = null;

            pubnub.PubnubUnitTest = common.CreateUnitTestInstance ("WhenGetRequestServerTime", "ThenItShouldReturnTimeStamp");
            ;

            string response = "";

            pubnub.Time (common.DisplayReturnMessage, common.DisplayReturnMessageDummy);

            common.WaitForResponse ();

            IList<object> fields = common.Response as IList<object>;
            response = fields [0].ToString ();
            Console.WriteLine ("Response:" + response);
            Assert.AreNotEqual ("0", response);
            pubnub.EndPendingRequests ();
        }
Exemplo n.º 10
0
        //[Test]
        public void ThenMultiSubscribeShouldReturnConnectStatus()
        {
            Pubnub pubnub = new Pubnub(Common.PublishKey,
                                       Common.SubscribeKey,
                                       "", "", false);

            Common common = new Common();

            common.DeliveryStatus = false;
            common.Response       = null;

            pubnub.PubnubUnitTest = common.CreateUnitTestInstance("WhenSubscribedToAChannel", "ThenMultiSubscribeShouldReturnConnectStatus");

            string channel1 = "testChannel1";

            pubnub.Subscribe <string> (channel1, common.DisplayReturnMessageDummy, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);

            common.WaitForResponse();

            bool receivedChannel1ConnectMessage = ParseResponse(common.Response);

            common.DeliveryStatus = false;
            common.Response       = null;

            string channel2 = "testChannel2";

            pubnub.Subscribe <string> (channel2, common.DisplayReturnMessageDummy, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);
            common.WaitForResponse();

            bool receivedChannel2ConnectMessage = ParseResponse(common.Response);

            if (receivedChannel1ConnectMessage && receivedChannel2ConnectMessage)
            {
                Assert.Pass("Connected and status code received");
            }
            else
            {
                Assert.Fail("Test failed");
            }
        }
Exemplo n.º 11
0
        public void SetAndDeleteGlobalState()
        {
            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                "",
                "",
                false
                );
            string channel = "testChannel4";

            pubnub.SetLocalUserState(channel, "testkey", "testval");
            pubnub.SetLocalUserState(channel, "testkey2", "testval2");
            Common common = new Common();

            pubnub.SetUserState <string> (channel, pubnub.GetLocalUserState(channel), common.DisplayReturnMessage, common.DisplayErrorMessage);
            common.WaitForResponse(30);
            common.DeliveryStatus = false;
            common.Response       = null;

            pubnub.GetUserState <string> (channel, common.DisplayReturnMessage, common.DisplayErrorMessage);
            common.WaitForResponse(30);

            pubnub.SetLocalUserState(channel, "testkey2", null);
            common.DeliveryStatus = false;
            common.Response       = null;

            pubnub.SetUserState <string> (channel, pubnub.GetLocalUserState(channel), common.DisplayReturnMessage, common.DisplayErrorMessage);
            Console.WriteLine("pubnub.GetLocalUserState:" + pubnub.GetLocalUserState(channel));

            common.WaitForResponse(30);
            Console.WriteLine("Response SetUserState:" + common.Response.ToString());
            common.DeliveryStatus = false;
            common.Response       = null;
            Thread.Sleep(5000);
            pubnub.GetUserState <string> (channel, common.DisplayReturnMessage, common.DisplayErrorMessage);
            common.WaitForResponse(30);
            Console.WriteLine("Response GetUserState:" + common.Response.ToString());
            Assert.True(common.Response.ToString().Contains("{\"testkey\":\"testval\"}"));
        }
Exemplo n.º 12
0
        void SubscribePublishAndParseComplex(Pubnub pubnub, Common common, string channel)
        {
            CustomClass message = new CustomClass ();

            pubnub.Subscribe<string> (channel, common.DisplayReturnMessage, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy);
            Thread.Sleep (1500);

            pubnub.Publish (channel, (object)message, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy);

            common.WaitForResponse ();

            if (common.Response != null) {
                Console.WriteLine ("response:" + common.Response.ToString ());
                object[] fields = Common.Deserialize<object[]> (common.Response.ToString ());

                if (fields [0] != null) {
                    var myObjectArray = (from item in fields
                        select item as object).ToArray ();

                    CustomClass cc = new CustomClass ();

                    //If the custom class is serialized with jsonfx the response is received as a dictionary and
                    //on deserialization with Newtonsoft.Json we get an error.
                    //As a work around we parse the dictionary object.
                    var dict = myObjectArray [0] as IDictionary;

                    if ((dict != null) && (dict.Count > 1)) {
                        cc.foo = (string)dict ["foo"];
                        cc.bar = (int[])dict ["bar"];
                    } else {
                        Type valueType = myObjectArray [0].GetType();
                        var expectedType = typeof(System.Dynamic.ExpandoObject);
                        if (expectedType.IsAssignableFrom (valueType)) {
                            dynamic x = myObjectArray [0];
                            cc.foo = x.foo;
                            cc.bar = x.bar;
                        } else {
                            cc = Common.Deserialize<CustomClass> (myObjectArray [0].ToString ());
                        }
                    }
                    if (cc.bar.SequenceEqual (message.bar) && cc.foo.Equals (message.foo)) {
                        Assert.True (true, "Complex message test successful");
                    } else {
                        Assert.Fail ("Complex message test not successful");
                    }
                } else {
                    Assert.Fail ("No response");
                }
            } else {
                Assert.Fail ("No response");
            }
        }
Exemplo n.º 13
0
        public void ThenItShouldReturnReceivedMessage()
        {
            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                "",
                "",
                false
                );
            string channel = "hello_world2";
            Common common  = new Common();

            common.DeliveryStatus = false;
            common.Response       = null;

            pubnub.PubnubUnitTest = common.CreateUnitTestInstance("WhenAClientIsPresented", "ThenPresenceShouldReturnReceivedMessage");

            pubnub.Presence <string> (channel, common.DisplayReturnMessage, common.DisplayReturnMessage, common.DisplayErrorMessage);
            Thread.Sleep(1500);
            Common commonSubscribe = new Common();

            common.DeliveryStatus = false;
            common.Response       = null;

            pubnub.Subscribe <string> (channel, commonSubscribe.DisplayReturnMessage, commonSubscribe.DisplayReturnMessage, commonSubscribe.DisplayErrorMessage);

            commonSubscribe.DeliveryStatus = false;
            commonSubscribe.Response       = null;

            common.WaitForResponse(30);

            string response = "";

            if (common.Response == null)
            {
                Assert.Fail("Null response");
            }
            else
            {
                //IList<object> responseFields = common.Response as IList<object>;
                object[] serializedMessage = pubnub.JsonPluggableLibrary.DeserializeToListOfObject(common.Response.ToString()).ToArray();

                /*foreach (object item in responseFields) {
                 *  response = item.ToString ();
                 *  Console.WriteLine ("Response:" + response);
                 *  //Assert.IsNotEmpty(strResponse);
                 * }
                 * Assert.True (("hello_world").Equals (responseFields [2]));*/
                Assert.True(("hello_world2").Equals(serializedMessage [2]));
            }
            pubnub.EndPendingRequests();
        }
Exemplo n.º 14
0
        public void SetAndGetGlobalState()
        {
            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                "sec-c-NGVlNmRkYjAtY2Q1OS00OWM2LWE4NzktNzM5YzIxNGQxZjg3",
                "",
                false
                );
            string channel = "testChannel3";
            //pubnub.SetLocalUserState(channel, "testkey", "testval");

            Common common = new Common();

            pubnub.SetUserState <string> (channel, "{\"testkey\":\"testval\"}", common.DisplayReturnMessage, common.DisplayErrorMessage);
            common.WaitForResponse(30);

            pubnub.GetUserState <string> (channel, common.DisplayReturnMessage, common.DisplayErrorMessage);
            common.WaitForResponse(30);

            Assert.True(common.Response.ToString().Contains("{\"testkey\":\"testval\"}"));
        }
Exemplo n.º 15
0
        //[Test]
        public void ThenItShouldReturnSuccessCodeAndInfoForComplexMessage2()
        {
            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                "",
                "",
                false
                );
            string channel = "hello_world";
            object message = new PubnubDemoObject();
            //object message = new CustomClass2();

            string json   = Common.Serialize(message);
            Common common = new Common();

            pubnub.PubnubUnitTest = common.CreateUnitTestInstance("WhenAMessageIsPublished", "ThenItShouldReturnSuccessCodeAndInfoForComplexMessage2");
            DeliveryStatus        = false;
            pubnub.Publish <string> (channel, message, DisplayReturnMessage, DisplayErrorMessage);
            //wait till the response is received from the server
            common.WaitForResponse();
            //while (!DeliveryStatus)
            //;
            if (common.Response != null)
            {
                IList <object> fields = common.Response as IList <object>;
                string         sent   = fields [1].ToString();
                string         one    = fields [0].ToString();
                Assert.AreEqual("Sent", sent);
                Assert.AreEqual("1", one);
            }
            else
            {
                Assert.Fail("Null response");
            }

            /*if (Response != null) {
             #if(!UNITY_ANDROID)
             *              IList<object> fields = Response as IList<object>;
             #else
             *              UnityEngine.Debug.Log ("cm2: " + Response.ToString ());
             *              IList<object> fields = Response as IList<object>;
             #endif
             *              string sent = fields [1].ToString ();
             *              string one = fields [0].ToString ();
             *              Assert.AreEqual ("Sent", sent);
             *              Assert.AreEqual ("1", one);
             * } else {
             *              Assert.Fail ("Null response");
             * }*/
        }
Exemplo n.º 16
0
        public void ThenItShouldReturnReceivedMessageSSL()
        {
            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                "",
                "",
                true
                );
            string channel = "hello_world3";
            Common common  = new Common();

            common.DeliveryStatus = false;
            common.Response       = null;

            pubnub.PubnubUnitTest = common.CreateUnitTestInstance("WhenAClientIsPresented", "ThenPresenceShouldReturnReceivedMessage");

            pubnub.Presence <string> (channel, common.DisplayReturnMessage, common.DisplayReturnMessage, common.DisplayErrorMessage);
            Thread.Sleep(500);
            Common commonSubscribe = new Common();

            common.DeliveryStatus = false;
            common.Response       = null;

            pubnub.Subscribe <string> (channel, commonSubscribe.DisplayReturnMessage, commonSubscribe.DisplayReturnMessage, commonSubscribe.DisplayErrorMessage);

            commonSubscribe.DeliveryStatus = false;
            commonSubscribe.Response       = null;


            common.WaitForResponse(30);

            string response = "";

            if (common.Response == null)
            {
                Assert.Fail("Null response");
            }
            else
            {
                //IList<object> responseFields = common.Response as IList<object>;
                object[] responseFields = Common.Deserialize <object[]> (common.Response.ToString());
                foreach (object item in responseFields)
                {
                    response = item.ToString();
                    Console.WriteLine("Response:" + response);
                }
                Assert.AreEqual(channel, responseFields [2]);
            }
            pubnub.EndPendingRequests();
        }
        void SubscribePublishAndParse(string message, Pubnub pubnub, Common common, string channel)
        {
            Random r = new Random();

            channel = "hello_world_sub" + r.Next(1000);

            pubnub.Subscribe <string> (channel, common.DisplayReturnMessage, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy);
            Thread.Sleep(2500);

            pubnub.Publish(channel, message, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy);

            common.WaitForResponse(35);

            if (common.Response != null)
            {
                object[] deserializedMessage = Common.Deserialize <object[]> (common.Response.ToString());
                if (deserializedMessage != null)
                {
                    Assert.True(message.Equals(deserializedMessage [0].ToString()));
                }
                else
                {
                    Assert.Fail("Test not successful");
                }
            }
            else
            {
                Assert.Fail("No response");
            }
            common.DeliveryStatus = false;
            common.Response       = null;

            pubnub.Unsubscribe <string> (channel, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);

            common.WaitForResponse(20);

            pubnub.EndPendingRequests();
        }
Exemplo n.º 18
0
        //[Test]
        public void ThenItShouldReturnSuccessCodeAndInfoForEncryptedComplexMessage2()
        {
            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                "",
                "enigma",
                false
                );
            string channel = "hello_world";
            //pubnub.NonSubscribeTimeout = int.Parse (operationTimeoutInSeconds);
            object message = new PubnubDemoObject();

            Common common = new Common();

            pubnub.PubnubUnitTest = common.CreateUnitTestInstance("WhenAMessageIsPublished", "ThenItShouldReturnSuccessCodeAndInfoForEncryptedComplexMessage2");

            common.DeliveryStatus = false;
            common.Response       = null;

            pubnub.Publish(channel, message, common.DisplayReturnMessage, common.DisplayReturnMessage);
            //wait till the response is received from the server

            common.WaitForResponse();
            //while (!DeliveryStatus)
            ;
            //UnityEngine.Debug.Log ("IN:ThenItShouldReturnSuccessCodeAndInfoForEncryptedComplexMessage2");
            if (common.Response != null)
            {
                IList <object> fields = common.Response as IList <object>;
                string         sent   = fields [1].ToString();
                string         one    = fields [0].ToString();
                Assert.AreEqual("Sent", sent);
                Assert.AreEqual("1", one);
            }
            else
            {
                Assert.Fail("Null response");
            }

            /*if (ResponseECM2 != null) {
             *              IList<object> fields = ResponseECM2 as IList<object>;
             *              string sent = fields [1].ToString ();
             *              string one = fields [0].ToString ();
             *              Assert.AreEqual ("Sent", sent);
             *              Assert.AreEqual ("1", one);
             * } else {
             *              Assert.Fail ("Null response");
             * }*/
        }
Exemplo n.º 19
0
        public void TestPresenceHeartbeat()
        {
            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                "",
                "",
                false
                );
            string channel = "testChannel6";

            Common common = new Common();

            pubnub.Presence <string> (channel, common.DisplayReturnMessage, common.DisplayReturnMessage, common.DisplayErrorMessage);
            common.WaitForResponse();

            Common commonSubscribe = new Common();

            pubnub.Subscribe <string> (channel, commonSubscribe.DisplayReturnMessage, commonSubscribe.DisplayReturnMessage, commonSubscribe.DisplayErrorMessage);
            commonSubscribe.WaitForResponse();

            common.DeliveryStatus = false;
            common.Response       = null;
            common.WaitForResponse();

            common.DeliveryStatus = false;
            common.Response       = null;
            common.WaitForResponse(pubnub.PresenceHeartbeat + 3);

            if (common.Response == null)
            {
                Assert.True(true, "Test passed");
            }
            else
            {
                if (common.Response.ToString().Contains("timeout") &&
                    common.Response.ToString().Contains(channel))
                {
                    Assert.Fail("Test failed: timed out");
                }
                else
                {
                    Console.WriteLine("response:" + common.Response.ToString());
                    Assert.True(true, "Test passed");
                }
            }
            pubnub.Unsubscribe <string> (channel, commonSubscribe.DisplayReturnMessageDummy, commonSubscribe.DisplayReturnMessageDummy, commonSubscribe.DisplayReturnMessageDummy, commonSubscribe.DisplayReturnMessageDummy);
            pubnub.EndPendingRequests();
        }
        public void TestUnsubscribePresenceSSL()
        {
            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                "",
                "",
                true
                );
            string channel = "hello_world3";
            Common common  = new Common();

            common.DeliveryStatus = false;
            common.Response       = null;

            pubnub.PubnubUnitTest = common.CreateUnitTestInstance("WhenAClientIsPresented", "ThenPresenceShouldReturnReceivedMessage");

            pubnub.Presence <string>(channel, common.DisplayReturnMessage, common.DisplayReturnMessage, common.DisplayErrorMessage);
            Thread.Sleep(3000);
            Common commonSubscribe = new Common();

            common.DeliveryStatus = false;
            common.Response       = null;

            pubnub.Subscribe <string>(channel, commonSubscribe.DisplayReturnMessage, commonSubscribe.DisplayReturnMessage, commonSubscribe.DisplayErrorMessage);

            commonSubscribe.DeliveryStatus = false;
            commonSubscribe.Response       = null;


            common.WaitForResponse(30);

            string response = "";

            if (common.Response == null)
            {
                Assert.Fail("Null response");
            }
            else
            {
                //IList<object> responseFields = common.Response as IList<object>;
                object[] responseFields = Common.Deserialize <object[]>(common.Response.ToString());
                if (channel.Equals(responseFields [2]))
                {
                    Unsub(common, pubnub, channel);
                }
            }
        }
        public void SendMultipleIntMessages (int messageStart, int messageEnd, string channel, Pubnub pubnub)
        {
            Common common = new Common ();
            common.DeliveryStatus = false;
            common.Response = null;   

            for (int i = messageStart; i < messageEnd; i++) {
                common.DeliveryStatus = false;
                string msg = i.ToString ();
                pubnub.Publish (channel, msg, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);

                common.WaitForResponse ();

                Console.WriteLine ("Message # " + i.ToString () + " published");
            }
        }
Exemplo n.º 22
0
        public void TestWhereNow()
        {
            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                "",
                "",
                false
                );
            Common common = new Common();

            common.DeliveryStatus = false;
            common.Response       = null;

            string channel  = "testChannel7";
            string testname = "IfHereNowIsCalledWithState";

            Common commonSubscribe = new Common();

            pubnub.Subscribe <string> (channel, commonSubscribe.DisplayReturnMessage, commonSubscribe.DisplayReturnMessage, commonSubscribe.DisplayErrorMessage);
            commonSubscribe.WaitForResponse();

            Thread.Sleep(5000);

            pubnub.WhereNow <string> ("", common.DisplayReturnMessage, common.DisplayErrorMessage);
            common.WaitForResponse();

            if (common.Response.Equals(null))
            {
                Assert.Fail("Null response");
            }
            else
            {
                if (common.Response.ToString().Contains(pubnub.SessionUUID) &&
                    common.Response.ToString().Contains(channel))
                {
                    Assert.True(true, "Test passed:" + testname);
                }
                else
                {
                    Console.WriteLine("response:" + common.Response.ToString());
                    Assert.Fail("Test failed:" + testname);
                }
            }
            pubnub.Unsubscribe <string> (channel, commonSubscribe.DisplayReturnMessageDummy, commonSubscribe.DisplayReturnMessageDummy, commonSubscribe.DisplayReturnMessageDummy, commonSubscribe.DisplayReturnMessageDummy);
            pubnub.EndPendingRequests();
        }
Exemplo n.º 23
0
        //[Test]
        public void ThenItShouldReturnSuccessCodeAndInfoForComplexMessage2WithSsl()
        {
            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                "",
                "",
                true
                );
            string channel = "hello_world";
            object message = new PubnubDemoObject();
            //object message = new CustomClass2();

            string json   = Common.Serialize(message);
            Common common = new Common();

            pubnub.PubnubUnitTest = common.CreateUnitTestInstance("WhenAMessageIsPublished", "ThenItShouldReturnSuccessCodeAndInfoForComplexMessage2WithSsl");

            common.DeliveryStatus = false;
            common.Response       = null;

            pubnub.Publish(channel, message, common.DisplayReturnMessage, common.DisplayReturnMessage);
            //wait till the response is received from the server
            common.WaitForResponse();
            if (common.Response != null)
            {
                IList <object> fields = common.Response as IList <object>;
                string         sent   = fields [1].ToString();
                string         one    = fields [0].ToString();
                Assert.AreEqual("Sent", sent);
                Assert.AreEqual("1", one);
            }
            else
            {
                Assert.Fail("Null response");
            }

            /*if (ResponseECM2Ssl != null) {
             *              IList<object> fields = ResponseECM2Ssl as IList<object>;
             *              string sent = fields [1].ToString ();
             *              string one = fields [0].ToString ();
             *              Assert.AreEqual ("Sent", sent);
             *              Assert.AreEqual ("1", one);
             * } else {
             *              Assert.Fail ("Null response");
             * }*/
        }
Exemplo n.º 24
0
        public void ThenItShouldReturnReceivedMessage()
        {
            Pubnub pubnub = new Pubnub(
                "demo",
                "demo",
                "",
                "",
                false
                );
            string channel        = "hello_world";
            Common commonPresence = new Common();

            commonPresence.DeliveryStatus = false;
            commonPresence.Response       = null;

            pubnub.PubnubUnitTest = commonPresence.CreateUnitTestInstance("WhenAClientIsPresented", "ThenPresenceShouldReturnReceivedMessage");

            pubnub.Presence(channel, commonPresence.DisplayReturnMessage, commonPresence.DisplayReturnMessageDummy, commonPresence.DisplayReturnMessageDummy);

            Common commonSubscribe = new Common();

            commonSubscribe.DeliveryStatus = false;
            commonSubscribe.Response       = null;

            pubnub.Subscribe(channel, commonSubscribe.DisplayReturnMessage, commonSubscribe.DisplayReturnMessageDummy, commonPresence.DisplayReturnMessageDummy);
            //while (!commonSubscribe.DeliveryStatus) ;

            commonPresence.WaitForResponse(30);

            string response = "";

            if (commonPresence.Response == null)
            {
                Assert.Fail("Null response");
            }
            else
            {
                IList <object> responseFields = commonPresence.Response as IList <object>;
                foreach (object item in responseFields)
                {
                    response = item.ToString();
                    Console.WriteLine("Response:" + response);
                    //Assert.IsNotEmpty(strResponse);
                }
                Assert.AreEqual("hello_world", responseFields[2]);
            }
        }
Exemplo n.º 25
0
        public void ThenItShouldReturnReceivedMessage()
        {
            Pubnub pubnub = new Pubnub(
                "demo",
                "demo",
                "",
                "",
                false);
            string channel = "hello_world";

            Common common = new Common();

            common.DeliveryStatus = false;
            common.Response       = null;

            pubnub.PubnubUnitTest = common.CreateUnitTestInstance("WhenSubscribedToAChannel", "ThenSubscribeShouldReturnReceivedMessage");

            pubnub.Subscribe(channel, common.DisplayReturnMessage, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy);
            Thread.Sleep(3000);

            string message = "Test Message";

            pubnub.Publish(channel, message, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy);

            //cm.deliveryStatus = false;
            common.WaitForResponse();
            if (common.Response != null)
            {
                IList <object> fields = common.Response as IList <object>;

                if (fields [0] != null)
                {
                    var myObjectArray = (from item in fields select item as object).ToArray();
                    Console.WriteLine("Response:" + myObjectArray[0].ToString());
                    Assert.True((message).Equals(myObjectArray[0].ToString()));
                }
                else
                {
                    Assert.Fail("No response");
                }
            }
            else
            {
                Assert.Fail("No response");
            }
        }
Exemplo n.º 26
0
        public void IfHereNowIsCalledThenItShouldReturnInfo()
        {
            Pubnub pubnub = new Pubnub(
               "demo",
               "demo",
               "",
               "",
               false
           );
            Common common = new Common();
            common.DeliveryStatus = false;
            common.Response = null;
            
            HereNow(pubnub, "IfHereNowIsCalledThenItShouldReturnInfo", common.DisplayReturnMessage);
            common.WaitForResponse();

            ParseResponse(common.Response);
        }
Exemplo n.º 27
0
        public void SendMultipleIntMessages(int messageStart, int messageEnd, string channel, Pubnub pubnub)
        {
            Common common = new Common();

            common.DeliveryStatus = false;
            common.Response       = null;

            for (int i = messageStart; i < messageEnd; i++)
            {
                common.DeliveryStatus = false;
                string msg = i.ToString();
                pubnub.Publish(channel, msg, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);

                common.WaitForResponse();

                Console.WriteLine("Message # " + i.ToString() + " published");
            }
        }
Exemplo n.º 28
0
        public void ThenItShouldReturnReceivedMessageSSL()
        {
            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                "",
                "",
                true
                );
            string channel = "hello_world3";
            Common common  = new Common();

            common.DeliveryStatus = false;
            common.Response       = null;

            pubnub.PubnubUnitTest = common.CreateUnitTestInstance("WhenAClientIsPresented", "ThenPresenceShouldReturnReceivedMessage");

            pubnub.Presence <string> (channel, common.DisplayReturnMessage, common.DisplayReturnMessage, common.DisplayErrorMessage);
            Thread.Sleep(1500);
            Common commonSubscribe = new Common();

            common.DeliveryStatus = false;
            common.Response       = null;

            pubnub.Subscribe <string> (channel, commonSubscribe.DisplayReturnMessage, commonSubscribe.DisplayReturnMessage, commonSubscribe.DisplayErrorMessage);

            commonSubscribe.DeliveryStatus = false;
            commonSubscribe.Response       = null;

            common.WaitForResponse(30);

            string response = "";

            if (common.Response == null)
            {
                Assert.Fail("Null response");
            }
            else
            {
                object[] serializedMessage = pubnub.JsonPluggableLibrary.DeserializeToListOfObject(common.Response.ToString()).ToArray();
                Assert.True(channel.Equals(serializedMessage [2]));
            }
            pubnub.EndPendingRequests();
        }
Exemplo n.º 29
0
        public void ThenItShouldReturnReceivedMessage()
        {
            Pubnub pubnub = new Pubnub(
              "demo",
              "demo",
              "",
              "",
              false
              );
            string channel = "hello_world";
            Common commonPresence = new Common();
            commonPresence.DeliveryStatus = false;
            commonPresence.Response = null;
            
            pubnub.PubnubUnitTest = commonPresence.CreateUnitTestInstance("WhenAClientIsPresented", "ThenPresenceShouldReturnReceivedMessage");
            
            pubnub.Presence(channel, commonPresence.DisplayReturnMessage, commonPresence.DisplayReturnMessageDummy, commonPresence.DisplayReturnMessageDummy);
            
            Common commonSubscribe = new Common();
            commonSubscribe.DeliveryStatus = false;
            commonSubscribe.Response = null;
            
            pubnub.Subscribe(channel, commonSubscribe.DisplayReturnMessage, commonSubscribe.DisplayReturnMessageDummy, commonPresence.DisplayReturnMessageDummy);
            //while (!commonSubscribe.DeliveryStatus) ;
            
            commonPresence.WaitForResponse(30);
            
            string response = "";
            if (commonPresence.Response == null) {
              Assert.Fail("Null response");
            }
            else
            {
              IList<object> responseFields = commonPresence.Response as IList<object>;
              foreach (object item in responseFields)
              {
                response = item.ToString();
                Console.WriteLine("Response:" + response);
                //Assert.IsNotEmpty(strResponse);
              }
			  Assert.True (("hello_world").Equals(responseFields[2]));
            }
        }
Exemplo n.º 30
0
        void HereNow(Pubnub pubnub, string unitTestCaseName,
                     Action <object> userCallback)
        {
            Random r       = new Random();
            string channel = "hello_world_hn" + r.Next(100);

            Common commonSubscribe = new Common();

            pubnub.Subscribe <string> (channel, commonSubscribe.DisplayReturnMessage, commonSubscribe.DisplayReturnMessage, commonSubscribe.DisplayErrorMessage);

            commonSubscribe.DeliveryStatus = false;
            commonSubscribe.Response       = null;

            commonSubscribe.WaitForResponse(45);
            Thread.Sleep(500);
            pubnub.HereNow(channel, userCallback, userCallback);

            //pubnub.Unsubscribe<string>(channel, commonSubscribe.DisplayReturnMessageDummy, commonSubscribe.DisplayReturnMessageDummy, commonSubscribe.DisplayReturnMessageDummy, commonSubscribe.DisplayReturnMessageDummy);
        }
Exemplo n.º 31
0
        public void IfHereNowIsCalledThenItShouldReturnInfo()
        {
            Pubnub pubnub = new Pubnub(
                "demo",
                "demo",
                "",
                "",
                false
                );
            Common common = new Common();

            common.DeliveryStatus = false;
            common.Response       = null;

            HereNow(pubnub, "IfHereNowIsCalledThenItShouldReturnInfo", common.DisplayReturnMessage);
            common.WaitForResponse();

            ParseResponse(common.Response);
        }
Exemplo n.º 32
0
        public void IfHereNowIsCalledThenItShouldReturnInfoSSL()
        {
            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                "",
                "",
                true
                );
            Common common = new Common();

            common.DeliveryStatus = false;
            common.Response       = null;

            HereNow(pubnub, "IfHereNowIsCalledThenItShouldReturnInfo", common.DisplayReturnMessage, common.DisplayReturnMessage);
            common.WaitForResponse();

            ParseResponse(common.Response, pubnub);
        }
Exemplo n.º 33
0
        public void IfHereNowIsCalledThenItShouldReturnInfoCipherSecretSSL()
        {
            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                "secret",
                "enigma",
                false
                );
            Common common = new Common();

            common.DeliveryStatus = false;
            common.Response       = null;

            HereNow(pubnub, "IfHereNowIsCalledThenItShouldReturnInfo", common.DisplayReturnMessage, common.DisplayReturnMessage);
            common.WaitForResponse();

            ParseResponse(common.Response, pubnub);
            pubnub.EndPendingRequests();
        }
        void SubscribePublishAndParse (string message, Pubnub pubnub, Common common, string channel)
        {
            pubnub.Subscribe<string> (channel, common.DisplayReturnMessage, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy); 
            Thread.Sleep (1500);

            pubnub.Publish (channel, message, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy);

            common.WaitForResponse ();

            if (common.Response != null) {
                object[] deserializedMessage = Common.Deserialize<object[]> (common.Response.ToString ());
                if (deserializedMessage != null) {
                    Assert.True (message.Equals(deserializedMessage [0].ToString ()));
                } else {
                    Assert.Fail ("Test not successful");
                }
            } else {
                Assert.Fail ("No response");
            }
        }
Exemplo n.º 35
0
        //[Test]
        public void ThenSubscriberShouldBeAbleToReceiveManyMessages()
        {
            Pubnub pubnub = new Pubnub(Common.PublishKey,
                                       Common.SubscribeKey,
                                       "", "", false);

            Common common = new Common();

            common.DeliveryStatus = false;
            common.Response       = null;

            //pubnub.PubnubUnitTest = common.CreateUnitTestInstance("WhenSubscribedToAChannel", "ThenSubscriberShouldBeAbleToReceiveManyMessages");

            string channel = "testChannel";

            pubnub.Subscribe <string> (channel, common.DisplayReturnMessage, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy);
            Thread.Sleep(1500);

            int iPassCount = 0;

            for (int i = 0; i < 10; i++)
            {
                string message = "Test Message " + i;
                pubnub.Publish(channel, message, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy);
                Console.WriteLine(string.Format("Sent {0}", message));

                common.WaitForResponse();

                if (common.Response.ToString().Contains(message))
                {
                    iPassCount++;
                    Console.WriteLine(string.Format("Received {0}", message));
                }
                //}
                common.DeliveryStatus = false;
                common.Response       = null;
            }
            Console.WriteLine(string.Format("passcount {0}", iPassCount));
            Assert.True(iPassCount >= 10);
            pubnub.EndPendingRequests();
        }
Exemplo n.º 36
0
        public void IfHereNowIsCalledWithState()
        {
            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                "",
                "",
                false
                );
            Common common = new Common();

            common.DeliveryStatus = false;
            common.Response       = null;

            string channel  = "testChannel";
            string testname = "IfHereNowIsCalledWithState";

            HereNowWithState <string>(pubnub, channel, testname, common.DisplayReturnMessage, common.DisplayErrorMessage);
            common.WaitForResponse();

            ParseResponseWithState(common.Response, pubnub.GetLocalUserState(channel), testname);
        }
Exemplo n.º 37
0
        public void ThenDuplicateChannelShouldReturnAlreadySubscribed()
        {
            Pubnub pubnub = new Pubnub (Common.PublishKey,
                Common.SubscribeKey,
                 "", "", false);

            Common common = new Common ();
            common.DeliveryStatus = false;
            common.Response = null;

            pubnub.PubnubUnitTest = common.CreateUnitTestInstance ("WhenSubscribedToAChannel", "ThenDuplicateChannelShouldReturnAlreadySubscribed");

            string channel = "testChannel";

            pubnub.Subscribe<string> (channel, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy);
            Thread.Sleep (100);

            pubnub.Subscribe<string> (channel, common.DisplayReturnMessage, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy);
            common.WaitForResponse ();

            Assert.True (common.Response.ToString ().Contains ("already subscribed"));
        }
Exemplo n.º 38
0
        private void Unsub(Common common, Pubnub pubnub, string channel)
        {
            Common commonUnsubscribe = new Common();

            common.DeliveryStatus = false;
            common.Response       = null;
            Thread.Sleep(2000);
            pubnub.Unsubscribe <string> (channel, commonUnsubscribe.DisplayReturnMessageDummy, commonUnsubscribe.DisplayReturnMessageDummy, commonUnsubscribe.DisplayReturnMessage, common.DisplayReturnMessageDummy);

            common.WaitForResponse(20);
            string response = "";

            if (common.Response == null)
            {
                Assert.Fail("Null response");
            }
            else
            {
                object[] responseFields2 = Common.Deserialize <object[]> (common.Response.ToString());
                Type     valueType       = responseFields2 [0].GetType();
                var      expectedType    = typeof(System.Dynamic.ExpandoObject);
                if (expectedType.IsAssignableFrom(valueType))
                {
                    dynamic x = responseFields2 [0];
                    Console.WriteLine(x.action);
                    Assert.True(channel.Equals(responseFields2 [2]) && x.action.Contains("leave"));
                }
                else
                {
                    foreach (object item in responseFields2)
                    {
                        response = item.ToString();
                        Console.WriteLine("Response:" + response);
                    }
                    Assert.True(channel.Equals(responseFields2 [2]) && responseFields2 [0].ToString().Contains("leave"));
                }
            }
            pubnub.EndPendingRequests();
        }
Exemplo n.º 39
0
        public void ThenItShouldReturnSuccessCodeAndInfoForComplexMessage2WithSsl()
        {
            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                "",
                "",
                true
                );
            string channel = "hello_world";
            object message = new PubnubDemoObject();
            //object message = new CustomClass2();

            string json   = Common.Serialize(message);
            Common common = new Common();

            pubnub.PubnubUnitTest = common.CreateUnitTestInstance("WhenAMessageIsPublished", "ThenItShouldReturnSuccessCodeAndInfoForComplexMessage2WithSsl");

            common.DeliveryStatus = false;
            common.Response       = null;

            pubnub.Publish(channel, message, common.DisplayReturnMessage, common.DisplayReturnMessage);
            //wait till the response is received from the server
            common.WaitForResponse(45);
            if (common.Response != null)
            {
                Console.WriteLine(" common.Response" + common.Response);
                IList <object> fields = common.Response as IList <object>;
                string         sent   = fields [1].ToString();
                string         one    = fields [0].ToString();
                Assert.True(("Sent").Equals(sent));
                Assert.True(("1").Equals(one));
            }
            else
            {
                Assert.Fail("Null response");
            }
            pubnub.EndPendingRequests();
        }
Exemplo n.º 40
0
        public void ThenItShouldReturnSuccessCodeAndInfoWhenEncryptedAndSecretKeyed()
        {
            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                "secret",
                "enigma",
                false
                );
            string channel = "hello_world";
            string message = "Pubnub API Usage Example";

            Common common = new Common();

            pubnub.PubnubUnitTest = common.CreateUnitTestInstance("WhenAMessageIsPublished", "ThenItShouldReturnSuccessCodeAndInfoWhenEncryptedAndSecretKeyed");

            common.DeliveryStatus = false;
            common.Response       = null;

            pubnub.Publish(channel, message, common.DisplayReturnMessage, common.DisplayReturnMessage);
            //wait till the response is received from the server
            common.WaitForResponse();
            if (common.Response != null)
            {
                Console.WriteLine(common.Response.ToString());
                IList <object> fields = common.Response as IList <object>;
                string         sent   = fields [1].ToString();
                string         one    = fields [0].ToString();
                Assert.True(("Sent").Equals(sent));
                Assert.True(("1").Equals(one));
            }
            else
            {
                Assert.Fail("Null response");
            }
            pubnub.EndPendingRequests();
        }
Exemplo n.º 41
0
        public void ThenItShouldReturnSuccessCodeAndInfoForEncryptedComplexMessage2()
        {
            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                "",
                "enigma",
                false
                );
            string channel = "hello_world";
            object message = new PubnubDemoObject();

            Common common = new Common();

            pubnub.PubnubUnitTest = common.CreateUnitTestInstance("WhenAMessageIsPublished", "ThenItShouldReturnSuccessCodeAndInfoForEncryptedComplexMessage2");

            common.DeliveryStatus = false;
            common.Response       = null;

            pubnub.Publish(channel, message, common.DisplayReturnMessage, common.DisplayReturnMessage);
            //wait till the response is received from the server
            common.WaitForResponse();
            if (common.Response != null)
            {
                IList <object> fields = common.Response as IList <object>;
                string         sent   = fields [1].ToString();
                string         one    = fields [0].ToString();
                Assert.AreEqual("Sent", sent);
                Assert.AreEqual("1", one);
            }
            else
            {
                Assert.Fail("Null response");
            }
            pubnub.EndPendingRequests();
        }
Exemplo n.º 42
0
        public void ThenSubscribeShouldReturnConnectStatus()
        {
            Pubnub pubnub = new Pubnub (Common.PublishKey,
                Common.SubscribeKey,
                 "", "", false);

            Common common = new Common ();
            common.DeliveryStatus = false;
            common.Response = null;

            pubnub.PubnubUnitTest = common.CreateUnitTestInstance ("WhenSubscribedToAChannel", "ThenSubscribeShouldReturnConnectStatus");

            string channel = "hello_world";

            pubnub.Subscribe<string> (channel, common.DisplayReturnMessageDummy, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);

            common.WaitForResponse ();

            if (ParseResponse (common.Response)) {
                Assert.True (true, "Connected and status code received");
            } else {
                Assert.Fail ("Test failed");
            }
        }
Exemplo n.º 43
0
        public void IfHereNowIsCalledWithState()
        {
            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                "",
                "",
                false
                );
            Common common = new Common();

            common.DeliveryStatus = false;
            common.Response       = null;

            string channel  = "testChannelhn1";
            string testname = "IfHereNowIsCalledWithState";

            HereNowWithState <string> (pubnub, channel, testname, common.DisplayReturnMessage, common.DisplayErrorMessage);
            common.WaitForResponse();

            ParseResponseWithState(common.Response, "{\"testkey\":\"testval\"}", testname);
            pubnub.Unsubscribe <string> (channel, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy);
            pubnub.EndPendingRequests();
        }
        public void TestEncryptedDetailedHistorySSL ()
        {
            Pubnub pubnub = new Pubnub (
                          Common.PublishKey,
                          Common.SubscribeKey,
                          "",
                          "enigma",
                          true);
            string channel = "hello_world_de15";

            int totalMessages = 10;

            Common common = new Common ();
            common.DeliveryStatus = false;
            common.Response = null;

            long starttime = common.Timestamp (pubnub);

            SendMultipleIntMessages (0, totalMessages, channel, pubnub);

            long midtime = common.Timestamp (pubnub);

            SendMultipleIntMessages (totalMessages, totalMessages / 2, channel, pubnub);

            long endtime = common.Timestamp (pubnub);
            common.WaitForResponse ();

            pubnub.PubnubUnitTest = common.CreateUnitTestInstance ("WhenDetailedHistoryIsRequested", "TestEncryptedDetailedHistory");

            common.Response = null;
            common.DeliveryStatus = false;
            Thread.Sleep (1000);
            pubnub.DetailedHistory (channel, totalMessages, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);

            common.WaitForResponse ();
            Console.WriteLine ("\n*********** DetailedHistory Messages Received*********** ");

            ParseResponse (common.Response, 0, totalMessages, "");
            pubnub.EndPendingRequests ();
        }
        public void TestUnencryptedSecretDetailedHistoryParams ()
        {
            Pubnub pubnub = new Pubnub (
                          Common.PublishKey,
                          Common.SubscribeKey,
                          Common.SecretKey,
                          "",
                          false);

            string channel = "hello_world_de5";

            int totalMessages = 10;

            Common common = new Common ();
            common.DeliveryStatus = false;
            common.Response = null;        

            long starttime = common.Timestamp (pubnub);

            SendMultipleIntMessages (0, totalMessages / 2, channel, pubnub);

            long midtime = common.Timestamp (pubnub);

            SendMultipleIntMessages (totalMessages / 2, totalMessages, channel, pubnub);

            long endtime = common.Timestamp (pubnub);

            pubnub.PubnubUnitTest = common.CreateUnitTestInstance ("WhenDetailedHistoryIsRequested", "TestUnencryptedSecretDetailedHistoryParams1");

            common.DeliveryStatus = false;
            common.Response = null;
            Console.WriteLine ("DetailedHistory with start & end");
            Thread.Sleep (1000);
            pubnub.DetailedHistory (channel, starttime, midtime, totalMessages / 2, true, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);

            common.WaitForResponse ();

            Console.WriteLine ("DetailedHistory with start & reverse = true");

            ParseResponse (common.Response, 0, totalMessages / 2, "");

            pubnub.PubnubUnitTest = common.CreateUnitTestInstance ("WhenDetailedHistoryIsRequested", "TestUnencryptedSecretDetailedHistoryParams2");

            common.DeliveryStatus = false;
            common.Response = null;
            Thread.Sleep (1000);
            pubnub.DetailedHistory (channel, midtime, -1, totalMessages / 2, true, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);

            common.WaitForResponse ();

            Console.WriteLine ("DetailedHistory with start & reverse = false");

            ParseResponse (common.Response, totalMessages / 2, totalMessages, "");

            pubnub.PubnubUnitTest = common.CreateUnitTestInstance ("WhenDetailedHistoryIsRequested", "TestUnencryptedSecretDetailedHistoryParams3");

            common.DeliveryStatus = false;
            common.Response = null;
            Thread.Sleep (1000);
            pubnub.DetailedHistory (channel, midtime, -1, totalMessages / 2, false, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);

            common.WaitForResponse ();

            Console.WriteLine ("\n******* DetailedHistory Messages Received ******* ");

            ParseResponse (common.Response, 0, totalMessages / 2, "");
            pubnub.EndPendingRequests ();
        }
        public void DetailedHistoryDecryptedExample ()
        {
            Pubnub pubnub = new Pubnub (
                          Common.PublishKey,
                          Common.SubscribeKey,
                          "",
                          "enigma",
                          false);
            string channel = "hello_world_de3";

            string message = "Test Message";

            Common common = new Common ();
            common.DeliveryStatus = false;
            common.Response = null;

            pubnub.Publish (channel, message, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);
            common.WaitForResponse ();

            pubnub.PubnubUnitTest = common.CreateUnitTestInstance ("WhenDetailedHistoryIsRequested", "DetailedHistoryDecryptedExample");

            common.DeliveryStatus = false;
            common.Response = null;
            Thread.Sleep (1000);
            pubnub.DetailedHistory (channel, 1, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);

            common.WaitForResponse ();
            Console.WriteLine ("\n*********** DetailedHistory Messages Received*********** ");

            ParseResponse (common.Response, 0, 0, message);
            pubnub.EndPendingRequests ();
        }
    public void TestUnencryptedDetailedHistory()
    {
      Pubnub pubnub = new Pubnub(
        "demo",
        "demo",
        "",
        "",
        false);

      string channel = "hello_world";
      int totalMessages = 10;
      
      Common common = new Common();
      common.DeliveryStatus = false;
      common.Response = null;

      long starttime = common.Timestamp(pubnub);

      SendMultipleIntMessages(0, totalMessages/2, channel, pubnub);

      long midtime = common.Timestamp(pubnub);

      SendMultipleIntMessages(totalMessages/2, totalMessages, channel, pubnub);

      long endtime = common.Timestamp(pubnub);
      common.WaitForResponse();
      
      pubnub.PubnubUnitTest = common.CreateUnitTestInstance("WhenDetailedHistoryIsRequested", "TestUnencryptedDetailedHistory");

      common.DeliveryStatus = false;
      common.Response = null;
      
      pubnub.DetailedHistory(channel, totalMessages, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);
      common.WaitForResponse();
      
      Console.WriteLine("\n******* DetailedHistory Messages Received ******* ");

      ParseResponse(common.Response, 0, totalMessages, "");
    } 
				//[Test]
                public void TestUnsubscribePresenceSSL()
                {
                    Pubnub pubnub = new Pubnub(
						Common.PublishKey,
						Common.SubscribeKey,                        
						"",
                        "",
                        true
                    );
                    string channel = "hello_world3";
                    Common common = new Common();
                    common.DeliveryStatus = false;
                    common.Response = null;

                    pubnub.PubnubUnitTest = common.CreateUnitTestInstance("WhenAClientIsPresented", "ThenPresenceShouldReturnReceivedMessage");

                    pubnub.Presence<string>(channel, common.DisplayReturnMessage, common.DisplayReturnMessage, common.DisplayErrorMessage);
					common.WaitForResponse();
                    Common commonSubscribe = new Common();
                    common.DeliveryStatus = false;
                    common.Response = null;

                    pubnub.Subscribe<string>(channel, commonSubscribe.DisplayReturnMessage, commonSubscribe.DisplayReturnMessage, commonSubscribe.DisplayErrorMessage);

                    commonSubscribe.DeliveryStatus = false;
                    commonSubscribe.Response = null;


                    common.WaitForResponse();

                    string response = "";
                    if (common.Response == null)
                    {
                        Assert.Fail("Null response");
                    } else
                    {
                        //IList<object> responseFields = common.Response as IList<object>;
                        object[] responseFields = Common.Deserialize<object[]>(common.Response.ToString());
                        if (channel.Equals(responseFields [2]))
                        {
                            Unsub(common, pubnub, channel);
                        }
                    }
                }
Exemplo n.º 49
0
        //[Test]
        public void ThenMultiSubscribeShouldReturnConnectStatusSSL ()
        {
            Pubnub pubnub = new Pubnub (Common.PublishKey,
                                Common.SubscribeKey,
                                "", "", true);

            Common common = new Common ();
            common.DeliveryStatus = false;
            common.Response = null;

            pubnub.PubnubUnitTest = common.CreateUnitTestInstance ("WhenSubscribedToAChannel", "ThenMultiSubscribeShouldReturnConnectStatus");

            string channel1 = "testChannel1";
            pubnub.Subscribe<string> (channel1, common.DisplayReturnMessageDummy, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);

            common.WaitForResponse ();

            bool receivedChannel1ConnectMessage = ParseResponse (common.Response);
            common.DeliveryStatus = false;
            common.Response = null;

            string channel2 = "testChannel2";
            pubnub.Subscribe<string> (channel2, common.DisplayReturnMessageDummy, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);
            common.WaitForResponse (); 

            bool receivedChannel2ConnectMessage = ParseResponse (common.Response);

            if (receivedChannel1ConnectMessage && receivedChannel2ConnectMessage) {
                Assert.Pass ("Connected and status code received");
            } else {
                Assert.Fail ("Test failed");
            }
        }
Exemplo n.º 50
0
        public void ThenSubscribeShouldReturnConnectStatus ()
        {
            Pubnub pubnub = new Pubnub (Common.PublishKey,
                                Common.SubscribeKey,
                                "", "", false);

            Common common = new Common ();
            common.DeliveryStatus = false;
            common.Response = null;

            pubnub.PubnubUnitTest = common.CreateUnitTestInstance ("WhenSubscribedToAChannel", "ThenSubscribeShouldReturnConnectStatus");

            string channel = "hello_world";

            pubnub.Subscribe<string> (channel, common.DisplayReturnMessageDummy, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);

            common.WaitForResponse ();         

            if (ParseResponse (common.Response)) {
                Assert.Pass ("Connected and status code received");
            } else {
                Assert.Fail ("Test failed");
            }
            pubnub.EndPendingRequests ();
        }
Exemplo n.º 51
0
        void SubscribePublishAndParseComplexObject (Pubnub pubnub, Common common, string channel)
        {
            CustomClass message = new CustomClass ();

            Random r = new Random ();
            channel = "hello_world_sub" + r.Next (1000);

            pubnub.Subscribe<object> (channel, common.DisplayReturnMessage, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy); 
            Thread.Sleep (5000);

            pubnub.Publish (channel, (object)message, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy);

            common.WaitForResponse ();

            if (common.Response != null) {
                List<object> lst = common.Response as List<object>;
                Console.WriteLine (lst [0].ToString ());
                Console.WriteLine (lst [1].ToString ());
                if (lst.Count == 3)
                    Console.WriteLine (lst [2].ToString ());
                if (lst.Count == 4)
                    Console.WriteLine (lst [3].ToString ());
                Console.WriteLine ();

                if (lst [0] != null) {
                    CustomClass cc = new CustomClass ();

                    var dict = lst [0] as IDictionary;

                    if ((dict != null) && (dict.Count > 1)) {
                        cc.foo = (string)dict ["foo"];
                        cc.bar = (int[])dict ["bar"];
                    } else {
                        cc = lst[0] as CustomClass;
                    }
                    if (cc.bar.SequenceEqual (message.bar) && cc.foo.Equals (message.foo)) {
                        Assert.Pass ("Complex message test successful");
                    } else {
                        Assert.Fail ("Complex message test not successful");
                    }
                } else {
                    Assert.Fail ("No response1");
                }
            } else {
                Assert.Fail ("No response");
            }
            common.DeliveryStatus = false;
            common.Response = null;

            pubnub.Unsubscribe<string> (channel, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);

            common.WaitForResponse (20);

            pubnub.EndPendingRequests ();
        }
Exemplo n.º 52
0
        void SubscribePublishAndParseComplex (Pubnub pubnub, Common common, string channel)
        {
            Random r = new Random ();
            channel = "hello_world_sub" + r.Next (1000);

            CustomClass message = new CustomClass ();

            pubnub.Subscribe<string> (channel, common.DisplayReturnMessage, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy); 
            Thread.Sleep (5000);
            pubnub.NonSubscribeTimeout = 30;
            pubnub.Publish (channel, (object)message, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy);
            pubnub.NonSubscribeTimeout = 15;
            common.WaitForResponse ();

            if (common.Response != null) {
                object[] fields = Common.Deserialize<object[]> (common.Response.ToString ());

                if (fields [0] != null) {
                    var myObjectArray = (from item in fields
                                                        select item as object).ToArray ();

                    CustomClass cc = new CustomClass ();

                    //If the custom class is serialized with jsonfx the response is received as a dictionary and
                    //on deserialization with Newtonsoft.Json we get an error.
                    //As a work around we parse the dictionary object.   
                    var dict = myObjectArray [0] as IDictionary;

                    if ((dict != null) && (dict.Count > 1)) {
                        cc.foo = (string)dict ["foo"];
                        cc.bar = (int[])dict ["bar"];
                    } else {
                        cc = Common.Deserialize<CustomClass> (myObjectArray [0].ToString ());
                        /*                                                            #if (USE_JSONFX)
                        var reader = new JsonFx.Json.JsonReader();
                        cc = reader.Read<CustomClass>(myObjectArray[0].ToString());
            #else
                        cc = JsonConvert.DeserializeObject<CustomClass>(myObjectArray[0].ToString());
            #endif*/
                    }  
                    if (cc.bar.SequenceEqual (message.bar) && cc.foo.Equals (message.foo)) {
                        Assert.Pass ("Complex message test successful");
                    } else {
                        Assert.Fail ("Complex message test not successful");
                    }
                } else {
                    Assert.Fail ("No response");
                }
            } else {
                Assert.Fail ("No response");
            }
            common.DeliveryStatus = false;
            common.Response = null;

            pubnub.Unsubscribe<string> (channel, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);

            common.WaitForResponse (20);

            pubnub.EndPendingRequests ();
        }
    public void DetailedHistoryExample()
    {
      Pubnub pubnub = new Pubnub(
        "demo",
        "demo",
        "",
        "",
        false);
      string channel = "hello_world";

      string message = "Test Message";

      Common common = new Common();
      common.DeliveryStatus = false;
      common.Response = null;
      
      pubnub.Publish(channel, message, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);
      common.WaitForResponse();
      
      pubnub.PubnubUnitTest = common.CreateUnitTestInstance("WhenDetailedHistoryIsRequested", "DetailHistoryCount10ReturnsRecords");
      
      common.DeliveryStatus = false;
      common.Response = null;
      
      pubnub.DetailedHistory(channel, 10, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);

      common.WaitForResponse();
      Console.WriteLine("\n*********** DetailedHistory Messages Received*********** ");

      ParseResponse(common.Response, 0,  0, "");
    }
Exemplo n.º 54
0
        public void ThenPresenceShouldReturnCustomUUID()
        {
          Pubnub pubnub = new Pubnub("demo", "demo", "", "", false);
          
          Common commonHereNow = new Common();
          commonHereNow.DeliveryStatus = false;
          commonHereNow.Response = null;

          Common commonSubscribe = new Common();
          commonSubscribe.DeliveryStatus = false;
          commonSubscribe.Response = null;

          pubnub.PubnubUnitTest = commonHereNow.CreateUnitTestInstance("WhenAClientIsPresented", "ThenPresenceShouldReturnCustomUUID");;
          pubnub.SessionUUID = "CustomSessionUUIDTest";
          
          string channel = "hello_world";

          pubnub.Subscribe(channel, commonSubscribe.DisplayReturnMessageDummy, commonSubscribe.DisplayReturnMessage, commonSubscribe.DisplayReturnMessage);
            
          //while (!commonSubscribe.DeliveryStatus);
          commonSubscribe.WaitForResponse();

          pubnub.HereNow<string>(channel, commonHereNow.DisplayReturnMessage, commonHereNow.DisplayReturnMessage);

          //while (!commonHereNow.DeliveryStatus);
          commonHereNow.WaitForResponse();
          if (commonHereNow.Response!= null)
          {
#if (USE_JSONFX)
              IList<object> fields = new JsonFXDotNet ().DeserializeToObject (commonHereNow.Response.ToString ()) as IList<object>;
              if (fields [0] != null)
              {
                  bool result = false;
                  Dictionary<string, object> message = (Dictionary<string, object>)fields [0];
                  foreach (KeyValuePair<String, object> entry in message)
                  {
                      Console.WriteLine("value:" + entry.Value + "  " + "key:" + entry.Key);
                      Type valueType = entry.Value.GetType();
                      var expectedType = typeof(string[]);
                      if (valueType.IsArray && expectedType.IsAssignableFrom(valueType))
                      {
                        List<string> uuids = new List<string>(entry.Value as string[]);
                        if(uuids.Contains(pubnub.SessionUUID )){
                            result= true;
                            break;
                        }
                      }
                  }
                  Assert.True(result);
              } 
              else
              {
                Assert.Fail("Null response");
              }
#else
              object[] serializedMessage = JsonConvert.DeserializeObject<object[]>(commonHereNow.Response.ToString());
              JContainer dictionary = serializedMessage[0] as JContainer;
              var uuid = dictionary["uuids"].ToString();
              if (uuid != null)
              {
                  Assert.True(uuid.Contains(pubnub.SessionUUID));
              } else {
                  Assert.Fail("Custom uuid not found.");
              }
#endif
          } else {
              Assert.Fail("Null response");
          }

        }
Exemplo n.º 55
0
        public void ThenDuplicateChannelShouldReturnAlreadySubscribed ()
        {
            Pubnub pubnub = new Pubnub (Common.PublishKey,
                                Common.SubscribeKey,
                                "", "", false);

            Common common = new Common ();
            common.DeliveryStatus = false;
            common.Response = null;

            pubnub.PubnubUnitTest = common.CreateUnitTestInstance ("WhenSubscribedToAChannel", "ThenDuplicateChannelShouldReturnAlreadySubscribed");

            string channel = "testChannel";

            pubnub.Subscribe<string> (channel, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy);
            Thread.Sleep (100);

            pubnub.Subscribe<string> (channel, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy, common.DisplayReturnMessage);
            common.WaitForResponse ();  

            Console.WriteLine ("Response:" + common.Response);
            if (common.Response.ToString ().ToLower ().Contains ("already subscribed")) {
                Assert.Pass ("Test passed");
            } else {
                Assert.Fail ("Test failed");
            }
            pubnub.EndPendingRequests ();
        }
Exemplo n.º 56
0
        //[Test]
        public void ThenSubscriberShouldBeAbleToReceiveManyMessages ()
        {
            Pubnub pubnub = new Pubnub (Common.PublishKey,
                                Common.SubscribeKey,
                                "", "", false);

            Common common = new Common ();
            common.DeliveryStatus = false;
            common.Response = null;

            //pubnub.PubnubUnitTest = common.CreateUnitTestInstance("WhenSubscribedToAChannel", "ThenSubscriberShouldBeAbleToReceiveManyMessages");

            string channel = "testChannel";

            pubnub.Subscribe<string> (channel, common.DisplayReturnMessage, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy);
            Thread.Sleep (1000);

            int iPassCount = 0;
            for (int i = 0; i < 10; i++) {
                /*                if(pubnub.PubnubUnitTest.EnableStubTest)
            {
              if(common.Response!=null)
              {
                iPassCount++;
              }
            }
            else
            {*/
                string message = "Test Message " + i;
                pubnub.Publish (channel, message, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy);
                Console.WriteLine (string.Format ("Sent {0}", message)); 

                common.WaitForResponse ();

                if (common.Response.ToString ().Contains (message)) {
                    iPassCount++;
                    Console.WriteLine (string.Format ("Received {0}", message)); 
                }
                //}
                common.DeliveryStatus = false;
                common.Response = null;            
            }
            Console.WriteLine (string.Format ("passcount {0}", iPassCount)); 
            if (iPassCount >= 10) {
                Assert.Pass ("Test passed");
            } else {
                Assert.Fail ("Test failed");
            }
        }
                private void Unsub(Common common, Pubnub pubnub, string channel)
                {
                    Common commonUnsubscribe = new Common();

                    common.DeliveryStatus = false;
                    common.Response = null;
                    pubnub.Unsubscribe<string>(channel, commonUnsubscribe.DisplayReturnMessageDummy, commonUnsubscribe.DisplayReturnMessageDummy, commonUnsubscribe.DisplayReturnMessage, common.DisplayReturnMessageDummy);

                    common.WaitForResponse();
                    string response = "";
                    if (common.Response == null)
                    {
                        Assert.Fail("Null response");
                    } else
                    {
                        object[] responseFields2 = Common.Deserialize<object[]>(common.Response.ToString());
                        int count = 0;
                        foreach (object item in responseFields2)
                        {
                            count++;
                            response = item.ToString();
                            UnityEngine.Debug.Log("Response:" + response);
                            if (count == 0){
                                Assert.True(item.ToString().Contains("leave"));
                            }
                        }
                                //Assert.True(responseFields2 [0].ToString().Contains("leave"));
                    }
                }
 public void ThenLargeMessageShoudFailWithMessageTooLargeInfo()
 {
     Pubnub pubnub = new Pubnub(
         Common.PublishKey,
         Common.SubscribeKey,
                         "",
                         "",
                         false
                     );
     string channel = "hello_world";
     string messageLarge2K = "This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. This is a large message test which will return an error message. ";
     
     Common common = new Common();
     
     pubnub.PubnubUnitTest = common.CreateUnitTestInstance("WhenAMessageIsPublished", "ThenLargeMessageShoudFailWithMessageTooLargeInfo");
     
     common.DeliveryStatus = false;
     common.Response = null;
     
     pubnub.Publish(channel, messageLarge2K, common.DisplayReturnMessage, common.DisplayReturnMessage);
     //wait till the response is received from the server
     common.WaitForResponse();
     if (common.Response != null)
         {
             IList<object> fields = common.Response as IList<object>;
             string sent = fields [1].ToString();
             Assert.AreEqual("Message Too Large", sent);
         } else
         {
             Assert.Fail("Null response");
         }
 }
Exemplo n.º 59
0
        public void TestUnsubscribePresence ()
        {
            Pubnub pubnub = new Pubnub (
                                Common.PublishKey,
                                Common.SubscribeKey,
                                "",
                                "",
                                false
                            );
            string channel = "hello_world_unsub2";
            Common common = new Common ();
            common.DeliveryStatus = false;
            common.Response = null;

            pubnub.PubnubUnitTest = common.CreateUnitTestInstance ("WhenAClientIsPresented", "ThenPresenceShouldReturnReceivedMessage");

            pubnub.Presence<string> (channel, common.DisplayReturnMessage, common.DisplayReturnMessage, common.DisplayErrorMessage);
            Thread.Sleep (3000);
            Common commonSubscribe = new Common ();
            common.DeliveryStatus = false;
            common.Response = null;

            pubnub.Subscribe<string> (channel, commonSubscribe.DisplayReturnMessage, commonSubscribe.DisplayReturnMessage, commonSubscribe.DisplayErrorMessage);

            commonSubscribe.DeliveryStatus = false;
            commonSubscribe.Response = null;

            common.WaitForResponse (30);
            string response = "";
            if (common.Response == null) {
                Assert.Fail ("Null response");
            } else {
                //IList<object> responseFields = common.Response as IList<object>;

                object[] responseFields = Common.Deserialize<object[]> (common.Response.ToString ());
                Type valueType = responseFields [0].GetType ();
                var expectedType = typeof(System.Dynamic.ExpandoObject);
                if (expectedType.IsAssignableFrom (valueType)) {
                    dynamic x = responseFields [0];
                    Console.WriteLine (x.action);
                } else {
                    foreach (object item in responseFields) {
                        response = item.ToString ();
                        Console.WriteLine ("Response:" + response);
                    }
                }
                if (channel.Equals (responseFields [2])) {
                    Unsub (common, pubnub, channel);
                }
            }
        }
Exemplo n.º 60
0
        private void Unsub (Common common, Pubnub pubnub, string channel)
        {
            Common commonUnsubscribe = new Common ();

            common.DeliveryStatus = false;
            common.Response = null;
            pubnub.Unsubscribe<string> (channel, commonUnsubscribe.DisplayReturnMessageDummy, commonUnsubscribe.DisplayReturnMessageDummy, commonUnsubscribe.DisplayReturnMessage, common.DisplayReturnMessageDummy);

            common.WaitForResponse (20);
            string response = "";
            if (common.Response == null) {
                Assert.Fail ("Null response");
            } else {
                object[] responseFields2 = Common.Deserialize<object[]> (common.Response.ToString ());
                Type valueType = responseFields2 [0].GetType ();
                var expectedType = typeof(System.Dynamic.ExpandoObject);
                if (expectedType.IsAssignableFrom (valueType)) {
                    dynamic x = responseFields2 [0];
                    Console.WriteLine (x.action);
                    Assert.True (channel.Equals (responseFields2 [2]) && x.action.Contains ("leave"));
                } else {
                    foreach (object item in responseFields2) {
                        response = item.ToString ();
                        Console.WriteLine ("Response:" + response);
                    }
                    Assert.True (channel.Equals (responseFields2 [2]) && responseFields2 [0].ToString ().Contains ("leave"));
                }
            }
            pubnub.EndPendingRequests ();
        }