Beispiel #1
0
        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");
            }
        }
Beispiel #2
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();
            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();
                    if (count == 0)
                    {
                        Assert.True(item.ToString().Contains("leave"));
                    }
                }
                //Assert.True(responseFields2 [0].ToString().Contains("leave"));
            }
            pubnub.EndPendingRequests();
        }
Beispiel #3
0
        bool ParseDict(Pubnub pubnub, object uuids)
        {
            object[] objUuid = null;
            UnityEngine.Debug.Log("uuids:" + uuids);
            Type valueType     = uuids.GetType();
            var  expectedType  = typeof(string[]);
            var  expectedType2 = typeof(object[]);

            if (expectedType.IsAssignableFrom(valueType))
            {
                objUuid = uuids as string[];
            }
            else if (expectedType2.IsAssignableFrom(valueType))
            {
                objUuid = uuids as object[];
            }
            else if (uuids is IList && uuids.GetType().IsGenericType)
            {
                objUuid = ((IEnumerable)uuids).Cast <object> ().ToArray();
            }
            else
            {
                objUuid = Common.Deserialize <object[]> (uuids.ToString());
            }
            foreach (object obj in objUuid)
            {
                UnityEngine.Debug.Log("session:" + obj.ToString());
                if (obj.Equals(pubnub.SessionUUID))
                {
                    return(true);
                }
            }
            return(false);
        }
        bool ParseResponse(object response)
        {
            bool retVal = false;

            if (response != null)
            {
                object[] deserializedMessage = Common.Deserialize <object[]> (response.ToString());

                /*                        #if (USE_JSONFX)
                 * var reader = new JsonFx.Json.JsonReader();
                 * deserializedMessage = reader.Read<object[]>(response.ToString());
                 #else
                 * deserializedMessage = JsonConvert.DeserializeObject<object[]>(response.ToString());
                 #endif*/
                if (deserializedMessage is object[])
                {
                    long   statusCode    = Int64.Parse(deserializedMessage [0].ToString());
                    string statusMessage = (string)deserializedMessage [1];
                    if (statusCode == 1 && statusMessage.ToLower() == "connected")
                    {
                        retVal = true;
                    }
                }
            }
            return(retVal);
        }
Beispiel #5
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)
            {
                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 (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");
            }
        }
Beispiel #6
0
        public void TestUnsubscribePresence()
        {
            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                "",
                "",
                false
                );
            string channel = "hello_world_unsub12";
            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.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());
                foreach (object item in responseFields)
                {
                    response = item.ToString();
                    Console.WriteLine("Response:" + response);
                }
                if (channel.Equals(responseFields [2]))
                {
                    Unsub(common, pubnub, channel);
                }
            }
        }
        public void TestPubNubDecryption2()
        {
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma");
            //Deserialized string
            string message = "f42pIQcWZ9zbTbH8cyLwB/tdvRxjFLOYcBNMVKeHS54=";
            //Decrypt
            string decrypted = pubnubCrypto.Decrypt(message);

            //Deserialize
            message = Common.Deserialize <string> (decrypted);
            Assert.True(("Pubnub Messaging API 2").Equals(message));
        }
        public void TestPubNubDecryption1()
        {
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma");
            //deserialized string
            string message = "f42pIQcWZ9zbTbH8cyLwByD/GsviOE0vcREIEVPARR0=";
            //decrypt
            string decrypted = pubnubCrypto.Decrypt(message);

            //deserialize
            message = Common.Deserialize <string> (decrypted);
            Assert.True(("Pubnub Messaging API 1").Equals(message));
        }
        public void TestUnicodeCharsDecryption()
        {
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma");
            string       message      = "+BY5/miAA8aeuhVl4d13Kg==";
            //decrypt
            string decrypted = pubnubCrypto.Decrypt(message);

            //deserialize
            message = Common.Deserialize <string> (decrypted);

            Assert.True(("漢語").Equals(message));
        }
Beispiel #10
0
        public void TestGermanCharsDecryption()
        {
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma");
            string       message      = "stpgsG1DZZxb44J7mFNSzg==";
            //decrypt
            string decrypted = pubnubCrypto.Decrypt(message);

            //deserialize
            message = Common.Deserialize <string> (decrypted);

            Assert.True(("ÜÖ").Equals(message));
        }
Beispiel #11
0
        public long Timestamp(Pubnub pubnub)
        {
            DeliveryStatus = false;

            pubnub.Time <string> (DisplayReturnMessage, DisplayReturnMessage);
            while (!DeliveryStatus)
            {
                ;
            }

            object[] fields = Common.Deserialize <object[]> (Response.ToString());

            //IList<object> fields = Response as IList<object>;
            return(Convert.ToInt64(fields [0].ToString()));
        }
Beispiel #12
0
        public void TestYayDecryption()
        {
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma");
            //Non deserialized string
            string message = "\"Wi24KS4pcTzvyuGOHubiXg==\"";

            //Deserialize
            message = Common.Deserialize <string> (message);

            //decrypt
            string decrypted = pubnubCrypto.Decrypt(message);

            //deserialize again
            message = Common.Deserialize <string> (decrypted);
            Assert.True(("yay!").Equals(message));
        }
        bool ParseResponse(object response)
        {
            bool retVal = false;
            if (response != null) {
                object[] deserializedMessage = Common.Deserialize<object[]> (response.ToString ());

                if (deserializedMessage is object[]) {
                    long statusCode = Int64.Parse (deserializedMessage [0].ToString ());
                    string statusMessage = (string)deserializedMessage [1];
                    if (statusCode == 1 && statusMessage.ToLower () == "connected") {
                        retVal = true;
                    }
                }
            }
            return retVal;
        }
Beispiel #14
0
        void SubscribePublishAndParse(string message, Pubnub pubnub, Common common, string channel)
        {
            Random r = new Random();

            channel = "hello_world_sub" + r.Next(1000);
            Thread.Sleep(1000);
            pubnub.Subscribe <string> (channel, common.DisplayReturnMessage, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy);
            Thread.Sleep(2500);
            pubnub.NonSubscribeTimeout = 30;

            pubnub.Publish(channel, message, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy);
            pubnub.NonSubscribeTimeout = 15;

            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(string.Format("Test not successful {0}, {1}", message, common.Response.ToString()));
                }
            }
            else
            {
                Assert.Fail("No response: " + common.ErrorResponse);
            }
            common.DeliveryStatus = false;
            common.Response       = null;

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

            common.WaitForResponse(20);

            pubnub.EndPendingRequests();
        }
Beispiel #15
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();
        }
        public void ThenItShouldReturnReceivedMessageCipherForComplexMessage()
        {
            Pubnub pubnub = new Pubnub(
                "demo",
                "demo",
                "",
                "enigma",
                false);
            string channel = "hello_world";

            Common common = new Common();

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

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

            CustomClass message = new CustomClass();

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

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

            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();

                    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.True(true, "Complex message test successful");
                    }
                    else
                    {
                        Assert.Fail("Complex message test not successful");
                    }
                }
                else
                {
                    Assert.Fail("No response");
                }
            }
            else
            {
                Assert.Fail("No response");
            }
        }
        public void ThenPresenceShouldReturnCustomUUID()
        {
            Pubnub pubnub = new Pubnub(Common.PublishKey,
                                       Common.SubscribeKey,
                                       "", "", 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_world3";

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

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

            //while (!commonSubscribe.DeliveryStatus);
            commonSubscribe.WaitForResponse(30);
            Thread.Sleep(10000);

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

            //while (!commonHereNow.DeliveryStatus);
            commonHereNow.WaitForResponse(30);
            pubnub.Unsubscribe <string>(channel, commonSubscribe.DisplayReturnMessageDummy, commonSubscribe.DisplayReturnMessageDummy, commonSubscribe.DisplayReturnMessageDummy, commonSubscribe.DisplayReturnMessage);
            if (commonHereNow.Response != null)
            {
                Console.WriteLine(commonHereNow.Response.ToString());
                object[] fields = Common.Deserialize <object[]>(commonHereNow.Response.ToString());
#if (USE_JSONFX)
                if (fields [0] != null)
                {
                    dynamic  x      = fields [0];
                    string[] strarr = x.uuids;
                    bool     found  = false;
                    foreach (string s in strarr)
                    {
                        if (s.Contains(pubnub.SessionUUID))
                        {
                            found = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        Assert.True(found, "Customuuid pass");
                    }
                    else
                    {
                        Assert.Fail("Customuuid fail");
                    }
                }
                else
                {
                    Assert.Fail("Null response");
                }
#else
                JContainer dictionary = fields [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");
            }
        }
        public void TestUnsubscribePresence()
        {
            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(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);
                }
            }
        }
        public void ParseResponse(object commonResponse, Pubnub pubnub)
        {
            if (commonResponse.Equals(null))
            {
                Assert.Fail("Null response");
            }
            else
            {
                bool           found          = false;
                IList <object> responseFields = commonResponse as IList <object>;
                foreach (object item in responseFields)
                {
                    if (item is Dictionary <string, object> )
                    {
                        Dictionary <string, object> message = (Dictionary <string, object>)item;
                        if (message.ContainsKey("uuids"))
                        {
                            object[] objUuid = null;
                            Console.WriteLine("uuids:" + message ["uuids"]);
                            Type valueType     = message ["uuids"].GetType();
                            var  expectedType  = typeof(string[]);
                            var  expectedType2 = typeof(object[]);

                            if (expectedType.IsAssignableFrom(valueType))
                            {
                                objUuid = message ["uuids"] as string[];
                            }
                            else if (expectedType2.IsAssignableFrom(valueType))
                            {
                                objUuid = message ["uuids"] as object[];
                            }
                            else
                            {
                                objUuid = Common.Deserialize <object[]> (message ["uuids"].ToString());
                            }
                            foreach (object obj in objUuid)
                            {
                                Console.WriteLine(obj.ToString());
                                if (obj.Equals(pubnub.SessionUUID))
                                {
                                    found = true;
                                }
                            }
                        }
                    }
                }
                if (found)
                {
                    Assert.True(found, "Test passed");
                }
                else
                {
                    Console.WriteLine("response:" + commonResponse.ToString());
                    Assert.Fail("Test failed");
                }

                /*foreach (object item in responseFields) {
                 *  response = item.ToString ();
                 *  Console.WriteLine ("Response:" + response);
                 *  Assert.NotNull (response);
                 * }
                 * Dictionary<string, object> message = (Dictionary<string, object>)responseFields [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"]);
            }
        }
Beispiel #20
0
        void SubscribePublishAndParseComplexObject(Pubnub pubnub, Common common, string channel)
        {
            Random r = new Random();

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

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

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

            common.WaitForResponse();

            if (common.Response != null)
            {
                Console.WriteLine("response:" + common.Response.ToString());
                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)
                {
                    //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;
                    var dict = lst [0] as IDictionary;

                    if ((dict != null) && (dict.Count > 1))
                    {
                        cc.foo = (string)dict ["foo"];
                        cc.bar = (int[])dict ["bar"];
                    }
                    else
                    {
                        Type valueType    = lst [0].GetType();
                        var  expectedType = typeof(System.Dynamic.ExpandoObject);
                        if (expectedType.IsAssignableFrom(valueType))
                        {
                            dynamic x = lst [0];
                            cc.foo = x.foo;
                            cc.bar = x.bar;
                        }
                        else
                        {
                            cc = Common.Deserialize <CustomClass> (lst [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");
            }
            common.DeliveryStatus = false;
            common.Response       = null;

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

            common.WaitForResponse(20);

            pubnub.EndPendingRequests();
        }
        void SubscribePublishAndParseComplex(Pubnub pubnub, Common common, string channel)
        {
            Random r = new Random();

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

            CustomClass message = new CustomClass();

            Thread.Sleep(1000);
            pubnub.Subscribe <string> (channel, common.DisplayReturnMessage, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy);
            Thread.Sleep(3000);
            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: " + common.ErrorResponse);
                }
            }
            else
            {
                Assert.Fail("No response: " + common.ErrorResponse);
            }
            common.DeliveryStatus = false;
            common.Response       = null;

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

            common.WaitForResponse(20);

            pubnub.EndPendingRequests();
        }