private void DetailedHistoryStartWithReverseTrueCallback(string result) { int actualCountAtStartTimeWithReverseFalse = 0; if (!string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(result.Trim())) { object[] deserializedMessage = new JsonFXDotNet().DeserializeToListOfObject(result).ToArray(); if (deserializedMessage is object[]) { object[] messages = deserializedMessage[0] as object[]; if (messages != null && messages.Length >= expectedCountAtStartTimeWithReverseTrue) { foreach (object item in messages) { if (item.ToString().Contains("DetailedHistoryStartTimeWithReverseTrue")) { actualCountAtStartTimeWithReverseFalse++; } } if (actualCountAtStartTimeWithReverseFalse == expectedCountAtStartTimeWithReverseTrue) { messageStartReverseTrue = true; } } } } mreMessageStartReverseTrue.Set(); }
void DummyMethodForSubscribeUUID(string receivedMessage) { try { if (!string.IsNullOrEmpty(receivedMessage) && !string.IsNullOrEmpty(receivedMessage.Trim())) { object[] serializedMessage = new JsonFXDotNet().DeserializeToListOfObject(receivedMessage).ToArray(); Dictionary <string, object> dictionary = serializedMessage[0] as Dictionary <string, object>; if (dictionary != null) { var uuid = dictionary["uuid"].ToString(); if (uuid != null) { receivedCustomUUID = true; } } } } catch (Exception ex) { Debug.Log("DummyMethodForSubscribeUUID exception = " + ex.ToString()); } finally { presenceUUIDManualEvent.Set(); } //Dummary callback method for subscribe and unsubscribe to test presence }
public void TestUnicodeCharsEncryption() { Debug.Log("Running TestUnicodeCharsEncryption()"); PubnubCrypto pc = new PubnubCrypto("enigma"); string message = "漢語"; message = new JsonFXDotNet().SerializeToJsonString(message); //JsonConvert.SerializeObject(message); string encryptedMessage = pc.Encrypt(message); UUnitAssert.Equals("+BY5/miAA8aeuhVl4d13Kg==", encryptedMessage); }
public void TestPubNubDecryption2() { Debug.Log("Running TestPubNubDecryption2()"); PubnubCrypto pc = new PubnubCrypto("enigma"); //Deserialized string string message = "f42pIQcWZ9zbTbH8cyLwB/tdvRxjFLOYcBNMVKeHS54="; //Decrypt string decryptedMessage = pc.Decrypt(message); //Deserialize message = new JsonFXDotNet().DeserializeToObject(decryptedMessage) as string; //JsonConvert.DeserializeObject<string>(decryptedMessage); UUnitAssert.Equals("Pubnub Messaging API 2", message); }
public void TestMyObjectEncryption() { Debug.Log("Running TestMyObjectEncryption()"); PubnubCrypto pc = new PubnubCrypto("enigma"); //create an object of the custom class CustomClass cc = new CustomClass(); //serialize it string result = new JsonFXDotNet().SerializeToJsonString(cc); //JsonConvert.SerializeObject(cc); //encrypt it string encryptedMessage = pc.Encrypt(result); UUnitAssert.Equals("Zbr7pEF/GFGKj1rOstp0tWzA4nwJXEfj+ezLtAr8qqE=", encryptedMessage); }
public void TestPubNubEncryption1() { Debug.Log("Running TestPubNubEncryption1()"); PubnubCrypto pc = new PubnubCrypto("enigma"); //non serialized string string message = "Pubnub Messaging API 1"; //serialize message = new JsonFXDotNet().SerializeToJsonString(message); //JsonConvert.SerializeObject(message); //encrypt string encryptedMessage = pc.Encrypt(message); UUnitAssert.Equals("f42pIQcWZ9zbTbH8cyLwByD/GsviOE0vcREIEVPARR0=", encryptedMessage); }
public void TestPubNubEncryption2() { Debug.Log("Running TestPubNubEncryption2()"); PubnubCrypto pc = new PubnubCrypto("enigma"); //Deserialized string message = "Pubnub Messaging API 2"; //serialize the message message = new JsonFXDotNet().SerializeToJsonString(message); //JsonConvert.SerializeObject(message); //encrypt string encryptedMessage = pc.Encrypt(message); UUnitAssert.Equals("f42pIQcWZ9zbTbH8cyLwB/tdvRxjFLOYcBNMVKeHS54=", encryptedMessage); }
public void TestObjectEncryption() { Debug.Log("Running TestObjectEncryption()"); PubnubCrypto pc = new PubnubCrypto("enigma"); //create an object System.Object obj = new System.Object(); //serialize string serializedObject = new JsonFXDotNet().SerializeToJsonString(obj);//JsonConvert.SerializeObject(obj); //encrypt string encryptedMessage = pc.Encrypt(serializedObject); UUnitAssert.Equals("IDjZE9BHSjcX67RddfCYYg==", encryptedMessage); }
public void TestArrayEncryption() { Debug.Log("Running TestArrayEncryption()"); PubnubCrypto pc = new PubnubCrypto("enigma"); //create an empty array object object[] emptyArray = { }; //serialize string serializedArray = new JsonFXDotNet().SerializeToJsonString(emptyArray); //JsonConvert.SerializeObject(emptyArray); //Encrypt string encryptedMessage = pc.Encrypt(serializedArray); UUnitAssert.Equals("Ns4TB41JjT2NCXaGLWSPAQ==", encryptedMessage); }
public void TestYayEncryption() { Debug.Log("Running TestYayEncryption()"); PubnubCrypto pc = new PubnubCrypto("enigma"); //deserialized string string message = "yay!"; //serialize the string message = new JsonFXDotNet().SerializeToJsonString(message); //JsonConvert.SerializeObject(message); Console.WriteLine(message); //Encrypt string enc = pc.Encrypt(message); UUnitAssert.Equals("Wi24KS4pcTzvyuGOHubiXg==", enc); }
public void TestObjectDecryption() { Debug.Log("Running TestObjectDecryption()"); PubnubCrypto pc = new PubnubCrypto("enigma"); //Deserialized string message = "IDjZE9BHSjcX67RddfCYYg=="; //Decrypt string decryptedMessage = pc.Decrypt(message); //create an object System.Object obj = new System.Object(); //Serialize the object string result = new JsonFXDotNet().SerializeToJsonString(obj); //JsonConvert.SerializeObject(obj); UUnitAssert.Equals(result, decryptedMessage); }
public void TestArrayDecryption() { Debug.Log("Running TestArrayDecryption()"); PubnubCrypto pc = new PubnubCrypto("enigma"); //Input the deserialized string string message = "Ns4TB41JjT2NCXaGLWSPAQ=="; //decrypt string decryptedMessage = pc.Decrypt(message); //create a serialized object object[] emptyArrayObject = { }; string result = new JsonFXDotNet().SerializeToJsonString(emptyArrayObject); //JsonConvert.SerializeObject(emptyArrayObject); //compare the serialized object and the return of the Decrypt method UUnitAssert.Equals(result, decryptedMessage); }
private void ReceivedMessageCallbackWhenSubscribed(string result) { if (!string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(result.Trim())) { object[] deserializedMessage = new JsonFXDotNet().DeserializeToListOfObject(result).ToArray(); if (deserializedMessage is object[]) { object subscribedObject = (object)deserializedMessage[0]; if (subscribedObject != null) { receivedMessage = true; } } } meSubscribeNoConnect.Set(); }
void DetailedHistoryCount10Callback(string result) { if (!string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(result.Trim())) { object[] deserializedMessage = new JsonFXDotNet().DeserializeToListOfObject(result).ToArray(); if (deserializedMessage is object[]) { object[] messages = deserializedMessage[0] as object[]; if (messages != null && messages.Length >= 0) { message10Received = true; } } } mreMessageCount10.Set(); }
private void DetailedHistorySamplePublishCallback(string result) { if (!string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(result.Trim())) { object[] deserializedMessage = new JsonFXDotNet().DeserializeToListOfObject(result).ToArray(); if (deserializedMessage is object[]) { int statusCode = Int32.Parse(deserializedMessage[0].ToString()); string statusMessage = (string)deserializedMessage[1]; if (statusCode == 1 && statusMessage.ToLower() == "sent") { expectedCountAtStartTimeWithReverseTrue++; } } } mrePublishStartReverseTrue.Set(); }
public void TestYayDecryption() { Debug.Log("Running TestYayDecryption()"); PubnubCrypto pc = new PubnubCrypto("enigma"); //string strMessage= "\"q/xJqqN6qbiZMXYmiQC1Fw==\""; //Non deserialized string string message = "\"Wi24KS4pcTzvyuGOHubiXg==\""; //Deserialize message = new JsonFXDotNet().DeserializeToObject(message) as string; //JsonConvert.DeserializeObject<string>(message); //decrypt string decryptedMessage = pc.Decrypt(message); //deserialize again message = new JsonFXDotNet().DeserializeToObject(decryptedMessage) as string; //JsonConvert.DeserializeObject<string>(decryptedMessage); UUnitAssert.Equals("yay!", message); }
private void ReturnTimeStampCallback(string result) { if (!string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(result.Trim())) { object[] deserializedMessage = new JsonFXDotNet().DeserializeToListOfObject(result).ToArray(); if (deserializedMessage is object[]) { string time = deserializedMessage[0].ToString(); Int64 nanoTime; if (time.Length > 2 && Int64.TryParse(time, out nanoTime)) { timeReceived = true; } } } mreTime.Set(); }
private void ConnectStatusCallback(string result) { if (!string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(result.Trim())) { object[] deserializedMessage = new JsonFXDotNet().DeserializeToListOfObject(result).ToArray(); if (deserializedMessage is object[]) { long statusCode = Int64.Parse(deserializedMessage[0].ToString()); string statusMessage = (string)deserializedMessage[1]; if (statusCode == 1 && statusMessage.ToLower() == "connected") { receivedConnectMessage = true; } } } meSubscribeYesConnect.Set(); }
private void ReturnNoSSLDefaultFalseCallback(string result) { if (!string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(result.Trim())) { object[] deserializedResult = new JsonFXDotNet().DeserializeToListOfObject(result).ToArray(); if (deserializedResult is object[]) { long statusCode = Int64.Parse(deserializedResult[0].ToString()); string statusMessage = (string)deserializedResult[1]; if (statusCode == 1 && statusMessage.ToLower() == "sent") { isPublished3 = true; } } } mreNoSslPublish.Set(); }
private void CaptureSecretEncryptDetailedHistoryCallback(string result) { if (!string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(result.Trim())) { object[] deserializedResult = new JsonFXDotNet().DeserializeToListOfObject(result).ToArray(); if (deserializedResult is object[] && deserializedResult.Length > 0) { object[] message = deserializedResult[0] as object[]; if (message != null && message.Length > 0 && message[0].ToString() == messageForSecretEncryptPublish) { isSecretEncryptDetailedHistory = true; } } } mreSecretEncryptDetailedHistory.Set(); }
private void ReturnPublishMessageTooLargeInfoCallback(string result) { if (!string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(result.Trim())) { object[] deserializedMessage = new JsonFXDotNet().DeserializeToListOfObject(result).ToArray(); if (deserializedMessage is object[]) { long statusCode = Int64.Parse(deserializedMessage[0].ToString()); string statusMessage = (string)deserializedMessage[1]; if (statusCode == 0 && statusMessage.ToLower() == "message too large") { isLargeMessagePublished = true; } } } mreLaregMessagePublish.Set(); }
private void ReturnSuccessSerializedObjectMessageForPublishCallback(string result) { if (!string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(result.Trim())) { object[] deserializedResult = new JsonFXDotNet().DeserializeToListOfObject(result).ToArray(); if (deserializedResult is object[]) { long statusCode = Int64.Parse(deserializedResult[0].ToString()); string statusMessage = (string)deserializedResult[1]; if (statusCode == 1 && statusMessage.ToLower() == "sent") { isSerializedObjectMessagePublished = true; serializedMessagePublishTimetoken = Convert.ToInt64(deserializedResult[2].ToString()); } } } mreSerializedObjectMessageForPublish.Set(); }
void ThenHereNowShouldReturnMessage(string receivedMessage) { try { if (!string.IsNullOrEmpty(receivedMessage) && !string.IsNullOrEmpty(receivedMessage.Trim())) { object[] serializedMessage = new JsonFXDotNet().DeserializeToListOfObject(receivedMessage).ToArray(); Dictionary <string, object> dictionary = serializedMessage[0] as Dictionary <string, object>; if (dictionary != null) { receivedHereNowMessage = true; } } } catch { } finally { hereNowManualEvent.Set(); } }
private void CaptureSerializedMessagePublishDetailedHistoryCallback(string result) { if (!string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(result.Trim())) { object[] deserializedMessage = new JsonFXDotNet().DeserializeToListOfObject(result).ToArray(); if (deserializedMessage is object[]) { object[] message = deserializedMessage[0] as object[]; if (message != null && message.Length > 0) { string receivedObjectString = new JsonFXDotNet().SerializeToJsonString(message[0]); if (receivedObjectString != null && receivedObjectString == serializedObjectMessageForPublish) { isSerializedObjectMessageDetailedHistory = true; } } } } mreSerializedMessagePublishDetailedHistory.Set(); }
void ThenPresenceWithCustomUUIDShouldReturnMessage(string receivedMessage) { try { if (!string.IsNullOrEmpty(receivedMessage) && !string.IsNullOrEmpty(receivedMessage.Trim())) { object[] serializedMessage = new JsonFXDotNet().DeserializeToListOfObject(receivedMessage).ToArray(); Dictionary <string, object> dictionary = serializedMessage[0] as Dictionary <string, object>; var uuid = dictionary["uuid"].ToString(); if (uuid != null && uuid.Contains(customUUID)) { receivedCustomUUID = true; } } } catch { } finally { presenceUUIDManualEvent.Set(); } }
public void TestMyObjectDecryption() { Debug.Log("Running TestMyObjectDecryption()"); PubnubCrypto pc = new PubnubCrypto("enigma"); //Deserialized string message = "Zbr7pEF/GFGKj1rOstp0tWzA4nwJXEfj+ezLtAr8qqE="; //Decrypt string decryptedMessage = pc.Decrypt(message); //create an object of the custom class CustomClass cc = new CustomClass(); //Serialize it string result = new JsonFXDotNet().SerializeToJsonString(cc); //JsonConvert.SerializeObject(cc); UUnitAssert.Equals(result, decryptedMessage); }
void DummyMethodForSubscribeUUID(string receivedMessage) { try { if (!string.IsNullOrEmpty(receivedMessage) && !string.IsNullOrEmpty(receivedMessage.Trim())) { object[] serializedMessage = new JsonFXDotNet().DeserializeToListOfObject(receivedMessage).ToArray(); Dictionary<string,object> dictionary = serializedMessage[0] as Dictionary<string,object>; if (dictionary != null) { var uuid = dictionary["uuid"].ToString(); if (uuid != null) { receivedCustomUUID = true; } } } } catch(Exception ex) { Debug.Log("DummyMethodForSubscribeUUID exception = " + ex.ToString()); } finally { presenceUUIDManualEvent.Set(); } //Dummary callback method for subscribe and unsubscribe to test presence }
void RevokeToUserLevelCallback(string receivedMessage) { try { if (!string.IsNullOrEmpty(receivedMessage) && !string.IsNullOrEmpty(receivedMessage.Trim())) { //object[] serializedMessage = JsonConvert.DeserializeObject<object[]>(receivedMessage); object[] deserializedMessage = new JsonFXDotNet().DeserializeToListOfObject(receivedMessage).ToArray(); Dictionary<string,object> dictionary = null; string currentChannel = ""; if (deserializedMessage is object[]) { dictionary = deserializedMessage[0] as Dictionary<string, object>; currentChannel = deserializedMessage[1].ToString(); } //JContainer dictionary = serializedMessage[0] as JContainer; //string currentChannel = serializedMessage[1].ToString(); if (dictionary != null) { int statusCode = (int)dictionary["status"]; string statusMessage = dictionary["message"].ToString(); if (statusCode == 200 && statusMessage.ToLower() == "success") { Dictionary<string, object> payload = dictionary["payload"] as Dictionary<string, object>; if (payload != null) { string level = payload["level"].ToString(); string channel = payload["channel"].ToString(); Dictionary<string, object> auths = payload["auths"] as Dictionary<string, object>; if (auths != null && auths.Count > 0) { receivedRevokeMessage = true; foreach (string authKey in auths.Keys) { //if (auth is JProperty) //{ //var authProperty = auth as JProperty; //if (authProperty != null) //{ //string authKey = authProperty.Name; Dictionary<string, object> authKeyContainer = auths[authKey] as Dictionary<string, object>; if (authKeyContainer != null) { receivedRevokeMessage = false; break; } //} //} } } else { receivedRevokeMessage = true; } } } } } } catch { } finally { revokeManualEvent.Set(); } }
void RevokeToChannelLevelCallback(string receivedMessage) { try { if (!string.IsNullOrEmpty(receivedMessage) && !string.IsNullOrEmpty(receivedMessage.Trim())) { ///object[] serializedMessage = JsonConvert.DeserializeObject<object[]>(receivedMessage); object[] deserializedMessage = new JsonFXDotNet().DeserializeToListOfObject(receivedMessage).ToArray(); Dictionary<string,object> dictionary = null; string currentChannel = ""; if (deserializedMessage is object[]) { dictionary = deserializedMessage[0] as Dictionary<string, object>; currentChannel = deserializedMessage[1].ToString(); } //JContainer dictionary = serializedMessage[0] as JContainer; //string currentChannel = serializedMessage[1].ToString(); if (dictionary != null) { int statusCode = (int)dictionary["status"]; string statusMessage = dictionary["message"].ToString(); if (statusCode == 200 && statusMessage.ToLower() == "success") { Dictionary<string, object> payload = dictionary["payload"] as Dictionary<string, object>; if (payload != null) { string level = payload["level"].ToString(); Dictionary<string, object> channels = payload["channels"] as Dictionary<string, object>; if (channels != null) { var channelContainer = (channels.ContainsKey(currentChannel)) ? channels[currentChannel] : null; if (channelContainer == null) { receivedRevokeMessage = true; } } else { receivedRevokeMessage = true; } } } } } } catch {} finally { revokeManualEvent.Set(); } }
void RevokeToSubKeyLevelCallback(string receivedMessage) { try { if (!string.IsNullOrEmpty(receivedMessage) && !string.IsNullOrEmpty(receivedMessage.Trim())) { //object[] serializedMessage = JsonConvert.DeserializeObject<object[]>(receivedMessage); object[] deserializedMessage = new JsonFXDotNet().DeserializeToListOfObject(receivedMessage).ToArray(); Dictionary<string,object> dictionary = null; if (deserializedMessage is object[]) { dictionary = deserializedMessage[0] as Dictionary<string, object>; } //JContainer dictionary = serializedMessage[0] as JContainer; if (dictionary != null) { int statusCode = (int)dictionary["status"]; string statusMessage = dictionary["message"].ToString(); if (statusCode == 200 && statusMessage.ToLower() == "success") { Dictionary<string, object> payload = dictionary["payload"] as Dictionary<string, object>; if (payload != null) { bool read = (payload["r"].ToString() == "1") ? true : false; bool write = (payload["w"].ToString() == "1") ? true : false; string level = payload["level"].ToString(); if (level == "subkey") { switch (currentUnitTestCase) { case "ThenRevokeAtSubKeyLevelReturnSuccess": if (!read && !write) receivedRevokeMessage = true; break; case "ThenSubKeyLevelWithReadShouldReturnSuccess": //if (read && !write) receivedGrantMessage = true; break; case "ThenSubKeyLevelWithWriteShouldReturnSuccess": //if (!read && write) receivedGrantMessage = true; break; default: break; } } } } //if (dictionary. //if (status == "200") //{ // receivedGrantMessage = true; //} } //var level = dictionary["level"].ToString(); } } catch { } finally { revokeManualEvent.Set(); } }
void ThenPresenceWithCustomUUIDShouldReturnMessage(string receivedMessage) { try { if (!string.IsNullOrEmpty(receivedMessage) && !string.IsNullOrEmpty(receivedMessage.Trim())) { object[] serializedMessage = new JsonFXDotNet().DeserializeToListOfObject(receivedMessage).ToArray(); Dictionary<string,object> dictionary = serializedMessage[0] as Dictionary<string,object>; var uuid = dictionary["uuid"].ToString(); if (uuid != null && uuid.Contains(customUUID)) { receivedCustomUUID = true; } } } catch { } finally { presenceUUIDManualEvent.Set(); } }
void ThenHereNowShouldReturnMessage(string receivedMessage) { try { if (!string.IsNullOrEmpty(receivedMessage) && !string.IsNullOrEmpty(receivedMessage.Trim())) { object[] serializedMessage = new JsonFXDotNet().DeserializeToListOfObject(receivedMessage).ToArray(); Dictionary<string,object> dictionary = serializedMessage[0] as Dictionary<string,object>; if (dictionary != null) { receivedHereNowMessage = true; } } } catch { } finally { hereNowManualEvent.Set(); } }
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); commonSubscribe.WaitForResponse(30); Thread.Sleep(5000); //while (!commonSubscribe.DeliveryStatus); //commonSubscribe.WaitForResponse (30); 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) { #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"); } pubnub.EndPendingRequests(); }
void AccessToUserLevelCallback(string receivedMessage) { try { if (!string.IsNullOrEmpty(receivedMessage) && !string.IsNullOrEmpty(receivedMessage.Trim())) { //object[] serializedMessage = JsonConvert.DeserializeObject<object[]>(receivedMessage); object[] deserializedMessage = new JsonFXDotNet().DeserializeToListOfObject(receivedMessage).ToArray(); Dictionary<string,object> dictionary = null; string currentChannel = ""; if (deserializedMessage is object[]) { dictionary = deserializedMessage[0] as Dictionary<string, object>; currentChannel = deserializedMessage[1].ToString(); } //JContainer dictionary = serializedMessage[0] as JContainer; //string currentChannel = serializedMessage[1].ToString(); if (dictionary != null) { int statusCode = (int)dictionary["status"]; string statusMessage = dictionary["message"].ToString(); if (statusCode == 200 && statusMessage.ToLower() == "success") { Dictionary<string, object> payload = dictionary["payload"] as Dictionary<string, object>; if (payload != null) { string level = payload["level"].ToString(); string channel = payload["channel"].ToString(); Dictionary<string, object> auths = payload["auths"] as Dictionary<string, object>; if (auths != null && auths.Count > 0) { foreach(string authKey in auths.Keys) { //if (auth is JProperty) //{ //var authProperty = auth as JProperty; //if (authProperty != null) //{ //string authKey = authProperty.Name; Dictionary<string, object> authKeyContainer = auths[authKey] as Dictionary<string, object>; if (authKeyContainer != null && authKeyContainer.Count > 0) { bool read = (authKeyContainer["r"].ToString() == "1") ? true : false; bool write = (authKeyContainer["w"].ToString() == "1") ? true : false; if (level == "user") { switch (currentUnitTestCase) { case "ThenUserLevelWithReadWriteShouldReturnSuccess": case "ThenRevokeAtUserLevelReturnSuccess": if (read && write) receivedGrantMessage = true; break; case "ThenUserLevelWithReadShouldReturnSuccess": if (read && !write) receivedGrantMessage = true; break; case "ThenUserLevelWithWriteShouldReturnSuccess": if (!read && write) receivedGrantMessage = true; break; default: break; } } } //} //} } } } } } } } catch { } finally { grantManualEvent.Set(); } }
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"); } }
void AccessToMultiAuthGrantCallback(string receivedMessage) { try { if (!string.IsNullOrEmpty(receivedMessage) && !string.IsNullOrEmpty(receivedMessage.Trim())) { //object[] serializedMessage = JsonConvert.DeserializeObject<object[]>(receivedMessage); object[] deserializedMessage = new JsonFXDotNet().DeserializeToListOfObject(receivedMessage).ToArray(); Dictionary<string,object> dictionary = null; string currentChannel = ""; if (deserializedMessage is object[]) { dictionary = deserializedMessage[0] as Dictionary<string, object>; currentChannel = deserializedMessage[1].ToString(); } //JContainer dictionary = serializedMessage[0] as JContainer; //string currentChannel = serializedMessage[1].ToString(); if (dictionary != null) { int statusCode = (int)dictionary["status"]; string statusMessage = dictionary["message"].ToString(); if (statusCode == 200 && statusMessage.ToLower() == "success") { Dictionary<string, object> payload = dictionary["payload"] as Dictionary<string, object>; if (payload != null) { string level = payload["level"].ToString(); string channel = payload["channel"].ToString(); Dictionary<string, object> auths = payload["auths"] as Dictionary<string, object>; if (auths != null) { //Console.WriteLine("{0} - AccessToMultiAuthGrantCallback - Grant Auth Count (Received/Sent) = {1}/{2}", currentUnitTestCase, auths.Count, multipleAuthGrantCount); if (auths.Count == multipleAuthGrantCount) { receivedGrantMessage = true; } } } } } } } catch { } finally { grantManualEvent.Set(); } }