public void ThenItShouldReturnTimeStamp() { Pubnub pubnub = new Pubnub( "demo", "demo", "", "", false ); PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenGetRequestServerTime"; unitTest.TestCaseName = "ThenItShouldReturnTimeStamp"; pubnub.PubnubUnitTest = unitTest; string strResponse = ""; Common cm = new Common(); cm.deliveryStatus = false; cm.objResponse = null; pubnub.time(cm.DisplayReturnMessage); //cm.objResponse = null; while (!cm.deliveryStatus) ; IList<object> fields = cm.objResponse as IList<object>; strResponse = fields[0].ToString(); Console.WriteLine("Resp:" + strResponse); Assert.AreNotEqual("0",strResponse); }
public void NullMessage() { Pubnub pubnub = new Pubnub( "demo", "demo", "", "", false ); string channel = "hello_world"; string message = null; Common cm = new Common(); cm.deliveryStatus = false; cm.objResponse = null; pubnub.publish(channel, message, cm.DisplayReturnMessage); //wait till the response is received from the server while (!cm.deliveryStatus) ; IList<object> fields = cm.objResponse as IList<object>; string strSent = fields[1].ToString(); string strOne = fields[0].ToString(); Assert.True(("Sent").Equals(strSent)); Assert.True(("1").Equals(strOne)); }
public void ThenItShouldReturnSuccessCodeAndInfo() { Pubnub pubnub = new Pubnub( "demo", "demo", "", "", false ); string channel = "hello_world"; string message = "Pubnub API Usage Example"; Common cm = new Common(); PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenAMessageIsPublished"; unitTest.TestCaseName = "ThenItShouldReturnSuccessCodeAndInfo"; pubnub.PubnubUnitTest = unitTest; cm.deliveryStatus = false; cm.objResponse = null; pubnub.publish(channel, message, cm.DisplayReturnMessage); //wait till the response is received from the server while (!cm.deliveryStatus) ; IList<object> fields = cm.objResponse as IList<object>; string strSent = fields[1].ToString(); string strOne = fields[0].ToString(); Assert.True(("Sent").Equals(strSent)); Assert.True(("1").Equals(strOne)); }
public void ItShouldReturnDetailedHistory() { Pubnub pubnub = new Pubnub( "demo", "demo", "", "", false ); string channel = "hello_world"; Common cm = new Common(); cm.deliveryStatus = false; cm.objResponse = null; //publish a test message. pubnub.publish(channel, "Test message", cm.DisplayReturnMessage); while (!cm.deliveryStatus) ; cm.deliveryStatus = false; cm.objResponse = null; pubnub.detailedHistory(channel, 1, cm.DisplayReturnMessage); while (!cm.deliveryStatus) ; string strResponse = ""; if (cm.objResponse.Equals(null)) { Assert.Fail("Null response"); } else { IList<object> fields = cm.objResponse as IList<object>; foreach (object item in fields) { strResponse = item.ToString(); Console.WriteLine(strResponse); Assert.IsNotNull(strResponse); } if (fields [0] != null) { var myObjectArray = (from item in fields select item as object).ToArray(); IList<object> enumerable = myObjectArray [0] as IList<object>; if ((enumerable != null) && (enumerable.Count > 0)) { foreach (object element in enumerable) { Console.WriteLine("Resp:" + element.ToString()); } } else { Assert.Fail("No response"); } } } }
public void IfSSLNotProvidedThenDefaultShouldBeFalse() { Pubnub pubnub = new Pubnub( "demo", "demo", "" ); string channel = "hello_world"; string message = "Pubnub API Usage Example"; Common cm = new Common(); Assert.AreEqual(true, pubnub.publish(channel, message, cm.DisplayReturnMessage)); }
public void NullShouldBeTreatedAsEmpty() { Pubnub pubnub = new Pubnub( null, "demo", null, null, false ); string channel = "mychannel"; string message = "Pubnub API Usage Example"; Common cm = new Common(); Assert.AreEqual(false, pubnub.publish(channel, message, cm.DisplayReturnMessage)); }
public void IfHereNowIsCalledThenItShouldReturnInfo() { Pubnub pubnub = new Pubnub( "demo", "demo", "", "", false ); string channel = "hello_world"; PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenAClientIsPresented"; unitTest.TestCaseName = "IfHereNowIsCalledThenItShouldReturnInfo"; pubnub.PubnubUnitTest = unitTest; Common cm = new Common(); cm.deliveryStatus = false; cm.objResponse = null; pubnub.here_now(channel, cm.DisplayReturnMessage); while (!cm.deliveryStatus) ; string strResponse = ""; if (cm.objResponse.Equals (null)) { Assert.Fail("Null response"); } else { IList<object> fields = cm.objResponse as IList<object>; foreach(object lst in fields) { strResponse = lst.ToString(); Console.WriteLine("Resp:" + strResponse); Assert.IsNotEmpty(strResponse); } Dictionary<string, object> message = (Dictionary<string, object>)fields[0]; foreach(KeyValuePair<String, object> entry in message) { Console.WriteLine("value:" + entry.Value + " " + "key:" + entry.Key); } /*object[] objUuid = (object[])message["uuids"]; foreach (object obj in objUuid) { Console.WriteLine(obj.ToString()); }*/ //Assert.AreNotEqual(0, message["occupancy"]); } }
public void ThenItShouldReturnReceivedMessage () { Pubnub pubnub = new Pubnub ( "demo", "demo", "", "", false); string channel = "hello_world"; Common cm = new Common(); cm.deliveryStatus = false; cm.objResponse = null; PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenSubscribedToAChannel"; unitTest.TestCaseName = "ThenSubscribeShouldReturnReceivedMessage"; pubnub.PubnubUnitTest = unitTest; pubnub.subscribe (channel, cm.DisplayReturnMessage); Thread.Sleep(3000); string msg = "Test Message"; pubnub.publish (channel, msg, cm.DisplayReturnMessageDummy); //cm.deliveryStatus = false; while (!cm.deliveryStatus); if (cm.objResponse != null) { IList<object> fields = cm.objResponse as IList<object>; if (fields [0] != null) { var myObjectArray = (from item in fields select item as object).ToArray (); Console.WriteLine ("Resp:" + myObjectArray[0].ToString ()); Assert.AreEqual(msg, myObjectArray[0].ToString()); } else { Assert.Fail("No response"); } } else { Assert.Fail("No response"); } }
public void ThenItShouldReturnHistoryMessages () { Pubnub pubnub = new Pubnub ( "demo", "demo", "", "", false ); string channel = "hello_world"; bool responseStatus = false; //publish a test message. Common cm = new Common(); cm.deliveryStatus = false; cm.objResponse = null; pubnub.publish (channel, "Test message", cm.DisplayReturnMessage); List<object> lstHistory = null; pubnub.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "History") { lstHistory = ((Pubnub)sender).History; responseStatus = true; } }; pubnub.history(channel, 1); /*while (!responseStatus) ; string strResponse = ""; if (lstHistory.Equals (null)) { Assert.Fail("Null response"); } else { foreach(object lst in lstHistory) { strResponse = lst.ToString(); Console.WriteLine("resp:" + strResponse); Assert.IsNotEmpty(strResponse); } }*/ }
public void ThenItShouldReturnReceivedMessage() { Pubnub pubnub = new Pubnub( "demo", "demo", "", "", false ); string channel = "hello_world"; Common cm = new Common(); cm.deliveryStatus = false; cm.objResponse = null; PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenAClientIsPresented"; unitTest.TestCaseName = "ThenPresenceShouldReturnReceivedMessage"; pubnub.PubnubUnitTest = unitTest; pubnub.presence(channel, cm.DisplayReturnMessage); //while (!cm.deliveryStatus) ; //cm.objResponse = null; pubnub.subscribe(channel, cm.DisplayReturnMessageDummy); while (!cm.deliveryStatus) ; string strResponse = ""; if (cm.objResponse.Equals (null)) { Assert.Fail("Null response"); } else { IList<object> fields = cm.objResponse as IList<object>; foreach (object item in fields) { strResponse = item.ToString(); Console.WriteLine("Resp:" + strResponse); //Assert.IsNotEmpty(strResponse); } Assert.AreEqual("hello_world", fields[2]); } }
public static void TestUnencryptedHistory() { Pubnub pubnub = new Pubnub( "demo", "demo", "", "", false); string channel = "my_channel"; Common cm = new Common(); cm.deliveryStatus = false; cm.objResponse = null; string message = "Pubnub API Usage Example - Publish"; //pubnub.CIPHER_KEY = "enigma"; pubnub.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "History") { Console.WriteLine("\n*********** History Messages *********** "); cm.deliveryStatus = true; } }; cm.deliveryStatus = false; pubnub.publish(channel, message, cm.DisplayReturnMessage); while (!cm.deliveryStatus) ; cm.deliveryStatus = false; pubnub.history(channel, 1); while (!cm.deliveryStatus) ; if (pubnub.History[0].Equals (null)) { Assert.Fail("Null response"); } else { Assert.True(message.Equals(pubnub.History[0].ToString())); } }
public void ThenItShouldReturnTimeStamp() { Pubnub pubnub = new Pubnub( "demo", "demo", "", "", false ); string strResponse = ""; Common cm = new Common(); cm.deliveryStatus = false; cm.objResponse = null; pubnub.time(cm.DisplayReturnMessage); cm.objResponse = null; while (!cm.deliveryStatus) ; IList<object> fields = cm.objResponse as IList<object>; strResponse = fields[0].ToString(); Console.WriteLine(strResponse); Assert.AreNotEqual("0",strResponse); }
public void ThenPublishKeyShouldBeOverriden() { Pubnub pubnub = new Pubnub( "", "demo", "", "", false ); string channel = "mychannel"; string message = "Pubnub API Usage Example"; pubnub = new Pubnub( "demo", "demo", "", "", false ); Common cm = new Common(); Assert.True((true).Equals(pubnub.publish(channel, message, cm.DisplayReturnMessage))); }
public void ThenItShouldReturnSuccessCodeAndInfo() { Pubnub pubnub = new Pubnub( "demo", "demo", "", "", false ); string channel = "hello_world"; string message = "Pubnub API Usage Example"; Common cm = new Common(); cm.deliveryStatus = false; cm.objResponse = null; pubnub.publish(channel, message, cm.DisplayReturnMessage); //wait till the response is received from the server while (!cm.deliveryStatus) ; IList<object> fields = cm.objResponse as IList<object>; string strSent = fields[1].ToString(); string strOne = fields[0].ToString(); Assert.AreEqual("Sent", strSent); Assert.AreEqual("1", strOne); }
public void ThenSecretKeyShouldBeProvidedOptionally() { Pubnub pubnub = new Pubnub( "demo", "demo" ); string channel = "mychannel"; string message = "Pubnub API Usage Example"; Common cm = new Common(); Assert.True((true).Equals(pubnub.publish(channel, message, cm.DisplayReturnMessage))); pubnub = new Pubnub( "demo", "demo", "key" ); Assert.True((true).Equals(pubnub.publish(channel, message, cm.DisplayReturnMessage))); }
public static void TestEncryptedDetailedHistory() { Pubnub pubnub = new Pubnub( "demo", "demo", "", "enigma", false); string channel = "testchannel"; //pubnub.CIPHER_KEY = "enigma"; int total_msg = 10; Common cm = new Common(); long starttime = cm.Timestamp(pubnub); cm.deliveryStatus = false; cm.objResponse = null; Dictionary<long, string> inputs = new Dictionary<long, string>(); for (int i = 0; i < total_msg / 2; i++) { string msg = i.ToString(); pubnub.publish(channel, msg, cm.DisplayReturnMessage); while (!cm.deliveryStatus) ; //long t = Timestamp(); //inputs.Add(t, msg); Console.WriteLine("Message # " + i.ToString() + " published"); } long midtime = cm.Timestamp(pubnub); for (int i = total_msg / 2; i < total_msg; i++) { string msg = i.ToString(); pubnub.publish(channel, msg, cm.DisplayReturnMessage); while (!cm.deliveryStatus) ; //long t = Timestamp(); //inputs.Add(t, msg); Console.WriteLine("Message # " + i.ToString() + " published"); } long endtime = cm.Timestamp(pubnub); while (!cm.deliveryStatus) ; cm.objResponse = null; pubnub.detailedHistory(channel, total_msg, cm.DisplayReturnMessage); cm.deliveryStatus = false; while (!cm.deliveryStatus) ; Console.WriteLine("\n*********** DetailedHistory Messages Received*********** "); string strResponse = ""; if (cm.objResponse.Equals(null)) { Assert.Fail("Null response"); } else { IList<object> fields = cm.objResponse as IList<object>; int j = 0; if (fields [0] != null) { var myObjectArray = (from item in fields select item as object).ToArray(); IList<object> enumerable = myObjectArray [0] as IList<object>; if ((enumerable != null) && (enumerable.Count > 0)) { foreach (object element in enumerable) { strResponse = element.ToString(); Console.WriteLine(String.Format("resp:{0} :: j: {1}", strResponse, j)); if(j<total_msg) Assert.AreEqual(j.ToString(), strResponse); j++; } } else { Assert.Fail("No response"); } } } }
public static void TestUnencryptedSecretDetailedHistoryParams() { Pubnub pubnub = new Pubnub( "demo", "demo", "secretkey", "", false); string channel = "hello_world"; //pubnub.CIPHER_KEY = "enigma"; int total_msg = 10; Common cm = new Common(); long starttime = cm.Timestamp(pubnub); cm.deliveryStatus = false; cm.objResponse = null; for (int i = 0; i < total_msg / 2; i++) { cm.deliveryStatus = false; string msg = i.ToString(); pubnub.publish(channel, msg, cm.DisplayReturnMessage); while (!cm.deliveryStatus) ; //long t = Timestamp(); //inputs.Add(t, msg); Console.WriteLine("Message # " + i.ToString() + " published"); } long midtime = cm.Timestamp(pubnub); for (int i = total_msg / 2; i < total_msg; i++) { cm.deliveryStatus = false; string msg = i.ToString(); pubnub.publish(channel, msg, cm.DisplayReturnMessage); while (!cm.deliveryStatus) ; //long t = Timestamp(); //inputs.Add(t, msg); Console.WriteLine("Message # " + i.ToString() + " published"); } long endtime = cm.Timestamp(pubnub); PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenDetailedHistoryIsRequested"; unitTest.TestCaseName = "TestUnencryptedSecretDetailedHistoryParams1"; pubnub.PubnubUnitTest = unitTest; cm.deliveryStatus = false; cm.objResponse = null; Console.WriteLine("DetailedHistory with start & end"); pubnub.detailedHistory(channel, starttime, midtime, total_msg / 2, true, cm.DisplayReturnMessage); while (!cm.deliveryStatus) ; Console.WriteLine("DetailedHistory with start & reverse = true"); string strResponse = ""; if (cm.objResponse.Equals(null)) { Assert.Fail("Null response"); } else { IList<object> fields = cm.objResponse as IList<object>; int j = 0; if (fields [0] != null) { var myObjectArray = (from item in fields select item as object).ToArray(); IList<object> enumerable = myObjectArray [0] as IList<object>; if ((enumerable != null) && (enumerable.Count > 0)) { foreach (object element in enumerable) { strResponse = element.ToString(); Console.WriteLine(String.Format("resp:{0} :: j: {1}", strResponse, j)); if(j<total_msg/2) Assert.True(j.ToString().Equals(strResponse)); j++; } } else { Assert.Fail("No response"); } } } PubnubUnitTest unitTest2 = new PubnubUnitTest(); unitTest2.TestClassName = "WhenDetailedHistoryIsRequested"; unitTest2.TestCaseName = "TestUnencryptedSecretDetailedHistoryParams2"; pubnub.PubnubUnitTest = unitTest2; cm.deliveryStatus = false; cm.objResponse = null; pubnub.detailedHistory(channel, midtime, -1, total_msg / 2, true, cm.DisplayReturnMessage); while (!cm.deliveryStatus) ; Console.WriteLine("DetailedHistory with start & reverse = false"); strResponse = ""; if (cm.objResponse.Equals(null)) { Assert.Fail("Null response"); } else { IList<object> fields = cm.objResponse as IList<object>; int j = total_msg / 2; if (fields [0] != null) { var myObjectArray = (from item in fields select item as object).ToArray(); IList<object> enumerable = myObjectArray [0] as IList<object>; if ((enumerable != null) && (enumerable.Count > 0)) { foreach (object element in enumerable) { strResponse = element.ToString(); Console.WriteLine(String.Format("resp:{0} :: j: {1}", strResponse, j)); if(j<total_msg) Assert.True(j.ToString().Equals(strResponse)); j++; } } else { Assert.Fail("No response"); } } } PubnubUnitTest unitTest3 = new PubnubUnitTest(); unitTest3.TestClassName = "WhenDetailedHistoryIsRequested"; unitTest3.TestCaseName = "TestUnencryptedSecretDetailedHistoryParams3"; pubnub.PubnubUnitTest = unitTest3; cm.deliveryStatus = false; cm.objResponse = null; pubnub.detailedHistory(channel, midtime, -1, total_msg / 2, false, cm.DisplayReturnMessage); while (!cm.deliveryStatus) ; Console.WriteLine("\n******* DetailedHistory Messages Received ******* "); strResponse = ""; if (cm.objResponse.Equals(null)) { Assert.Fail("Null response"); } else { IList<object> fields = cm.objResponse as IList<object>; int j = 0; if (fields [0] != null) { var myObjectArray = (from item in fields select item as object).ToArray(); IList<object> enumerable = myObjectArray [0] as IList<object>; if ((enumerable != null) && (enumerable.Count > 0)) { foreach (object element in enumerable) { strResponse = element.ToString(); Console.WriteLine(String.Format("resp:{0} :: j: {1}", strResponse, j)); if(j<total_msg/2) Assert.True(j.ToString().Equals(strResponse)); j++; } } else { Assert.Fail("No response"); } } } }
public static void DetailedHistory_Decrypted_Example() { Pubnub pubnub = new Pubnub( "demo", "demo", "", "enigma", false); string channel = "hello_world"; //pubnub.CIPHER_KEY = "enigma"; string msg = "Test Message"; Common cm = new Common(); cm.deliveryStatus = false; cm.objResponse = null; pubnub.publish(channel, msg, cm.DisplayReturnMessage); while (!cm.deliveryStatus) ; PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenDetailedHistoryIsRequested"; unitTest.TestCaseName = "DetailedHistory_Decrypted_Example"; pubnub.PubnubUnitTest = unitTest; cm.deliveryStatus = false; cm.objResponse = null; pubnub.detailedHistory(channel, 1, cm.DisplayReturnMessage); while (!cm.deliveryStatus) ; Console.WriteLine("\n*********** DetailedHistory Messages Received*********** "); if (cm.objResponse.Equals(null)) { Assert.Fail("Null response"); } else { IList<object> fields = cm.objResponse as IList<object>; if (fields [0] != null) { var myObjectArray = (from item in fields select item as object).ToArray(); IList<object> myObjectList = myObjectArray[0] as IList<object>; if (fields [0] != null) { Console.WriteLine("myObjectList[0]: " + myObjectList[0]); Assert.True(msg.Equals(myObjectList[0])); } else { Assert.Fail("NULL response"); } } } }
public static void DetailedHistory_Example() { Pubnub pubnub = new Pubnub( "demo", "demo", "", "", false); string channel = "hello_world"; //pubnub.CIPHER_KEY = ""; string msg = "Test Message"; Common cm = new Common(); cm.deliveryStatus = false; cm.objResponse = null; pubnub.publish(channel, msg, cm.DisplayReturnMessage); while (!cm.deliveryStatus) ; PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenDetailedHistoryIsRequested"; unitTest.TestCaseName = "DetailHistoryCount10ReturnsRecords"; pubnub.PubnubUnitTest = unitTest; cm.deliveryStatus = false; cm.objResponse = null; pubnub.detailedHistory(channel, 10, cm.DisplayReturnMessage); while (!cm.deliveryStatus) ; Console.WriteLine("\n*********** DetailedHistory Messages Received*********** "); if (cm.objResponse.Equals(null)) { Assert.Fail("Null response"); } else { IList<object> fields = cm.objResponse as IList<object>; if (fields [0] != null) { var myObjectArray = (from item in fields select item as object).ToArray(); IList<object> enumerable = myObjectArray [0] as IList<object>; if ((enumerable != null) && (enumerable.Count > 0)) { foreach (object element in enumerable) { string strResponse = element.ToString(); Console.WriteLine(String.Format("resp:{0}", strResponse)); Assert.NotNull(strResponse); } } else { Assert.Fail("No response"); } } } }
public void ThenPublishKeyShouldNotBeEmptyAfterOverriden() { Pubnub pubnub = new Pubnub( "", "demo", "", "", false ); string channel = "mychannel"; string message = "Pubnub API Usage Example"; Common cm = new Common(); Assert.AreEqual(false, pubnub.publish(channel, message, cm.DisplayReturnMessage)); }