public void ThenSubscribeShouldReturnReceivedMessage() { receivedMessage = false; ThreadPool.QueueUserWorkItem((s) => { Pubnub pubnub = new Pubnub("demo", "demo", "", "", false); string channel = "my/channel"; PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenSubscribedToAChannel"; unitTest.TestCaseName = "ThenSubscribeShouldReturnReceivedMessage"; pubnub.PubnubUnitTest = unitTest; pubnub.Subscribe<string>(channel, ReceivedMessageCallbackWhenSubscribed, SubscribeDummyMethodForConnectCallback); //Thread.Sleep(500); pubnub.Publish<string>(channel, "Test for WhenSubscribedToAChannel ThenItShouldReturnReceivedMessage", dummyPublishCallback); mePublish.WaitOne(310 * 1000); //Thread.Sleep(500); meSubscribeNoConnect.WaitOne(310 * 1000); pubnub.Unsubscribe<string>(channel, dummyUnsubscribeCallback, SubscribeDummyMethodForConnectCallback, UnsubscribeDummyMethodForDisconnectCallback); Thread.Sleep(500); meUnsubscribe.WaitOne(310 * 1000); Thread.Sleep(1000); pubnub.EndPendingRequests(); Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(receivedMessage, "WhenSubscribedToAChannel --> ThenItShouldReturnReceivedMessage Failed"); TestComplete(); }); }); }
public void ThenChannelLevelShouldReturnSuccess() { currentUnitTestCase = "ThenChannelLevelShouldReturnSuccess"; receivedAuditMessage = false; ThreadPool.QueueUserWorkItem((s) => { Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, PubnubCommon.SecretKey, "", false); PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenAuditIsRequested"; unitTest.TestCaseName = "ThenChannelLevelShouldReturnSuccess"; pubnub.PubnubUnitTest = unitTest; string channel = "hello_my_channel"; if (PubnubCommon.PAMEnabled) { mreAudit = new ManualResetEvent(false); pubnub.AuditAccess<string>(channel, AccessToChannelLevelCallback, DummyErrorCallback); mreAudit.WaitOne(60 * 1000); Assert.IsTrue(receivedAuditMessage, "WhenAuditIsRequested -> ThenChannelLevelShouldReturnSuccess failed."); } else { Assert.Inconclusive("PAM Not Enabled for WhenAuditIsRequested -> ThenChannelLevelShouldReturnSuccess"); } Deployment.Current.Dispatcher.BeginInvoke(() => { TestComplete(); }); }); }
public void Init() { if (!PubnubCommon.PAMEnabled) return; receivedGrantMessage = false; ThreadPool.QueueUserWorkItem((s) => { Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, PubnubCommon.SecretKey, "", false); PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "GrantRequestUnitTest"; unitTest.TestCaseName = "Init3"; pubnub.PubnubUnitTest = unitTest; pubnub.ChannelGroupGrantAccess<string>(channelGroupName, true, true, 20, ThenChannelGroupInitializeShouldReturnGrantMessage, DummySubscribeErrorCallback); Thread.Sleep(1000); grantManualEvent.WaitOne(); Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(receivedGrantMessage, "WhenSubscribedToAChannelGroup Grant access failed."); pubnub.PubnubUnitTest = null; pubnub = null; TestComplete(); }); }); }
public void ThenChannelLevelShouldReturnSuccess() { currentUnitTestCase = "ThenChannelLevelShouldReturnSuccess"; receivedAuditMessage = false; Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, PubnubCommon.SecretKey, "", false); PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenAuditIsRequested"; unitTest.TestCaseName = "ThenChannelLevelShouldReturnSuccess"; pubnub.PubnubUnitTest = unitTest; string channel = "hello_my_channel"; if (PubnubCommon.PAMEnabled) { pubnub.AuditAccess<string>(channel, AccessToChannelLevelCallback, DummyErrorCallback); Thread.Sleep(1000); auditManualEvent.WaitOne(); Assert.IsTrue(receivedAuditMessage, "WhenAuditIsRequested -> ThenChannelLevelShouldReturnSuccess failed."); } else { Assert.Inconclusive("PAM Not Enabled for WhenAuditIsRequested -> ThenChannelLevelShouldReturnSuccess"); } }
public void Init() { if (!PubnubCommon.PAMEnabled) { Assert.Inconclusive("WhenAClientIsPresent Grant access failed."); return; } receivedGrantMessage = false; ThreadPool.QueueUserWorkItem((s) => { Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, PubnubCommon.SecretKey, "", false); PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "GrantRequestUnitTest"; unitTest.TestCaseName = "Init"; pubnub.PubnubUnitTest = unitTest; string channel = "hello_my_channel"; pubnub.GrantAccess<string>(channel, true, true, 20, ThenDetailedHistoryInitializeShouldReturnGrantMessage, DummyErrorCallback); //Thread.Sleep(1000); grantManualEvent.WaitOne(); Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(receivedGrantMessage, "WhenAClientIsPresent Grant access failed."); }); }); }
public void ThenPresenceShouldReturnReceivedMessage() { receivedPresenceMessage = false; ThreadPool.QueueUserWorkItem((s) => { Pubnub pubnub = new Pubnub("demo", "demo", "", "", false); string channel = "my/channel"; PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenAClientIsPresented"; unitTest.TestCaseName = "ThenPresenceShouldReturnReceivedMessage"; pubnub.PubnubUnitTest = unitTest; pubnub.Presence<string>(channel, ThenPresenceShouldReturnMessage); //since presence expects from stimulus from sub/unsub... pubnub.Subscribe<string>(channel, DummyMethodForSubscribe); subscribeManualEvent.WaitOne(2000); pubnub.Unsubscribe<string>(channel, DummyMethodForUnSubscribe); unsubscribeManualEvent.WaitOne(2000); pubnub.PresenceUnsubscribe<string>(channel, DummyMethodForPreUnSub); presenceUnsubscribeEvent.WaitOne(2000); presenceManualEvent.WaitOne(310 * 1000); Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(receivedPresenceMessage, "Presence message not received"); TestComplete(); }); }); }
public void ThenSubscribeShouldReturnConnectStatus() { receivedConnectMessage = false; ThreadPool.QueueUserWorkItem((s) => { Pubnub pubnub = new Pubnub("demo", "demo", "", "", false); PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenSubscribedToAChannel"; unitTest.TestCaseName = "ThenSubscribeShouldReturnConnectStatus"; pubnub.PubnubUnitTest = unitTest; string channel = "my/channel"; pubnub.Subscribe<string>(channel, ReceivedMessageCallbackYesConnect, ConnectStatusCallback); meSubscribeYesConnect.WaitOne(310 * 1000); Thread.Sleep(200); pubnub.Unsubscribe<string>(channel, dummyUnsubCallback); meUnsubscribe.WaitOne(310 * 1000); Thread.Sleep(200); Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(receivedConnectMessage, "WhenSubscribedToAChannel --> ThenSubscribeShouldReturnConnectStatus Failed"); TestComplete(); }); }); }
public void IfGlobalHereNowIsCalledThenItShouldReturnInfo() { ThreadPool.QueueUserWorkItem((s) => { receivedGlobalHereNowMessage = false; Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", false); PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenAClientIsPresented"; unitTest.TestCaseName = "IfGlobalHereNowIsCalledThenItShouldReturnInfo"; pubnub.PubnubUnitTest = unitTest; mreGlobalHereNow = new ManualResetEvent(false); pubnub.GlobalHereNow<string>(true, true, ThenGlobalHereNowShouldReturnMessage, DummyErrorCallback); mreGlobalHereNow.WaitOne(60 * 1000); Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(receivedGlobalHereNowMessage, "global_here_now message not received"); pubnub.PubnubUnitTest = null; pubnub = null; TestComplete(); }); }); }
public void ThenSubKeyLevelWithReadShouldReturnSuccess() { currentUnitTestCase = "ThenSubKeyLevelWithReadShouldReturnSuccess"; receivedGrantMessage = false; Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, PubnubCommon.SecretKey, "", false); PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenGrantIsRequested"; unitTest.TestCaseName = "ThenSubKeyLevelWithReadShouldReturnSuccess"; pubnub.PubnubUnitTest = unitTest; if (PubnubCommon.PAMEnabled) { pubnub.GrantAccess<string>("", true, false, 5, AccessToSubKeyLevelCallback, DummyErrorCallback); Thread.Sleep(1000); grantManualEvent.WaitOne(); Assert.IsTrue(receivedGrantMessage, "WhenGrantIsRequested -> ThenSubKeyLevelWithReadShouldReturnSuccess failed."); } else { Assert.Inconclusive("PAM Not Enabled for WhenGrantIsRequested -> ThenSubKeyLevelWithReadShouldReturnSuccess."); } }
public void ThenAddChannelShouldReturnSuccess() { currentUnitTestCase = "ThenAddChannelShouldReturnSuccess"; receivedChannelGroupMessage = false; ThreadPool.QueueUserWorkItem((s) => { Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, PubnubCommon.SecretKey, "", false); PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenChannelGroupIsRequested"; unitTest.TestCaseName = "ThenAddChannelShouldReturnSuccess"; pubnub.PubnubUnitTest = unitTest; channelGroupManualEvent = new ManualResetEvent(false); string channelName = "hello_my_channel"; pubnub.AddChannelsToChannelGroup<string>(new string[] { channelName }, channelGroupName, ChannelGroupCRUDCallback, DummyErrorCallback); channelGroupManualEvent.WaitOne(310 * 1000); Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(receivedChannelGroupMessage, "WhenChannelGroupIsRequested -> ThenAddChannelShouldReturnSuccess failed."); pubnub.PubnubUnitTest = null; pubnub = null; TestComplete(); }); }); }
public void Init() { if (!PubnubCommon.PAMEnabled) { TestComplete(); return; } receivedGrantMessage = false; ThreadPool.QueueUserWorkItem((s) => { Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, PubnubCommon.SecretKey, "", false); PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "GrantRequestUnitTest"; unitTest.TestCaseName = "Init"; pubnub.PubnubUnitTest = unitTest; string channel = "hello_my_channel,hello_my_channel1,hello_my_channel2"; mreGrant = new ManualResetEvent(false); pubnub.GrantAccess<string>(channel, true, true, 20, ThenSubscriberInitializeShouldReturnGrantMessage, DummyErrorCallback); mreGrant.WaitOne(60 * 1000); //1 minute Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(receivedGrantMessage, "WhenAClientIsPresent Grant access failed."); TestComplete(); }); }); }
public void Init() { if (!PubnubCommon.PAMEnabled) { Assert.Inconclusive("WhenAClientIsPresent Grant access failed."); return; } receivedGrantMessage = false; Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, PubnubCommon.SecretKey, "", false); PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "GrantRequestUnitTest"; unitTest.TestCaseName = "Init"; pubnub.PubnubUnitTest = unitTest; string channel = "hello_my_channel"; pubnub.GrantAccess<string>(channel, true, true, 20, ThenSubscriberInitializeShouldReturnGrantMessage, DummyErrorCallback); //Thread.Sleep(1000); grantManualEvent.WaitOne(); Assert.IsTrue(receivedGrantMessage, "WhenAClientIsPresent Grant access failed."); }
public void ThenShouldReturnUnsubscribedMessage() { currentUnitTestCase = "ThenShouldReturnUnsubscribedMessage"; receivedMessage = false; receivedChannelGroupMessage = false; receivedChannelGroupConnectedMessage = false; ThreadPool.QueueUserWorkItem((s) => { Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", false); pubnub.SessionUUID = "myuuid"; PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenUnsubscribedToAChannelGroup"; unitTest.TestCaseName = "ThenShouldReturnUnsubscribedMessage"; pubnub.PubnubUnitTest = unitTest; channelGroupName = "hello_my_group"; string channelName = "hello_my_channel"; unsubscribeManualEvent = new ManualResetEvent(false); pubnub.AddChannelsToChannelGroup<string>(new string[] { channelName }, channelGroupName, ChannelGroupAddCallback, DummySubscribeErrorCallback); unsubscribeManualEvent.WaitOne(manualResetEventsWaitTimeout); if (receivedChannelGroupMessage) { unsubscribeManualEvent = new ManualResetEvent(false); pubnub.Subscribe<string>("", channelGroupName, DummyMethodChannelSubscribeUserCallback, DummyMethodChannelSubscribeConnectCallback, DummyErrorCallback); Thread.Sleep(1000); unsubscribeManualEvent.WaitOne(manualResetEventsWaitTimeout); if (receivedChannelGroupConnectedMessage) { unsubscribeManualEvent = new ManualResetEvent(false); pubnub.Unsubscribe<string>("", channelGroupName, DummyMethodUnsubscribeChannelUserCallback, DummyMethodUnsubscribeChannelConnectCallback, DummyMethodUnsubscribeChannelDisconnectCallback, DummyErrorCallback); unsubscribeManualEvent.WaitOne(manualResetEventsWaitTimeout); } pubnub.EndPendingRequests(); Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(receivedMessage, "WhenUnsubscribedToAChannelGroup --> ThenShouldReturnUnsubscribedMessage Failed"); pubnub.PubnubUnitTest = null; pubnub = null; TestComplete(); }); } else { Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(receivedChannelGroupMessage, "WhenUnsubscribedToAChannelGroup --> ThenShouldReturnUnsubscribedMessage Failed"); pubnub.PubnubUnitTest = null; pubnub = null; TestComplete(); }); } }); }
public void ThenPresenceShouldReturnReceivedMessage() { receivedPresenceMessage = false; Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", false); string channel = "hello_my_channel"; PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenAClientIsPresented"; unitTest.TestCaseName = "ThenPresenceShouldReturnReceivedMessage"; pubnub.PubnubUnitTest = unitTest; pubnub.Presence<string>(channel, ThenPresenceShouldReturnMessage, PresenceDummyMethodForConnectCallback, DummyErrorCallback); Thread.Sleep(1000); //since presence expects from stimulus from sub/unsub... pubnub.Subscribe<string>(channel, DummyMethodForSubscribe, SubscribeDummyMethodForConnectCallback, DummyErrorCallback); Thread.Sleep(1000); subscribeManualEvent.WaitOne(2000); //pubnub.Unsubscribe<string>(channel, DummyMethodForUnSubscribe, UnsubscribeDummyMethodForConnectCallback, UnsubscribeDummyMethodForDisconnectCallback, DummyErrorCallback); //Thread.Sleep(1000); //unsubscribeManualEvent.WaitOne(2000); presenceManualEvent.WaitOne(310 * 1000); pubnub.EndPendingRequests(); Assert.IsTrue(receivedPresenceMessage, "Presence message not received"); }
public void ThenItShouldReturnTimeStamp() { Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", false); PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenGetRequestServerTime"; unitTest.TestCaseName = "ThenItShouldReturnTimeStamp"; pubnub.PubnubUnitTest = unitTest; pubnub.Time<string>(ReturnTimeStampCallback, DummyErrorCallback); mreTime.WaitOne(310 * 1000); Assert.IsTrue(timeReceived, "time() Failed"); }
public void ThenGetAllChannelsForDeviceShouldReturnSuccess() { string channel = "hello_my_channel"; string pushToken = "http://sn1.notify.live.net/throttledthirdparty/01.00/AQG2MdvoLlZFT7-VJ2TJ5LnbAgAAAAADAQAAAAQUZm52OkRFNzg2NTMxMzlFMEZFNkMFBlVTU0MwMQ"; receivedSuccessMessage = false; currentUnitTestCase = "ThenGetAllChannelsForDeviceShouldReturnSuccess"; ThreadPool.QueueUserWorkItem((s) => { Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, PubnubCommon.SecretKey, "", false); PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenPushIsRequested"; unitTest.TestCaseName = "ThenGetAllChannelsForDeviceShouldReturnSuccess"; pubnub.PubnubUnitTest = unitTest; if (!PubnubCommon.EnableStubTest) { mrePush = new ManualResetEvent(false); pubnub.RegisterDeviceForPush<string>(channel, PushTypeService.MPNS, pushToken, DeviceRegisterCallback, DummyErrorCallback); mrePush.WaitOne(60 * 1000); } else { receivedSuccessMessage = true; } if (receivedSuccessMessage) { mrePush = new ManualResetEvent(false); pubnub.GetChannelsForDevicePush<string>(PushTypeService.MPNS, pushToken, GetChannelsFromDeviceCallback, DummyErrorCallback); mrePush.WaitOne(60 * 1000); Assert.IsTrue(receivedSuccessMessage, "WhenPushIsRequested -> ThenGetAllChannelsForDeviceShouldReturnSuccess failed."); } else { Assert.IsTrue(receivedSuccessMessage, "WhenPushIsRequested -> RegisterDeviceForPush failed in ThenGetAllChannelsForDeviceShouldReturnSuccess."); } Deployment.Current.Dispatcher.BeginInvoke(() => { pubnub.PubnubUnitTest = null; pubnub = null; TestComplete(); }); }); }
public void ThenChannelGroupLevelWithReadManageShouldReturnSuccess() { currentUnitTestCase = "ThenChannelGroupLevelWithReadManageShouldReturnSuccess"; receivedGrantMessage = false; ThreadPool.QueueUserWorkItem((s) => { Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, PubnubCommon.SecretKey, "", false); PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenGrantIsRequested"; unitTest.TestCaseName = "ThenChannelGroupLevelWithReadManageShouldReturnSuccess"; pubnub.PubnubUnitTest = unitTest; string channelgroup = "hello_my_group"; if (PubnubCommon.PAMEnabled) { mreGrant = new ManualResetEvent(false); pubnub.ChannelGroupGrantAccess<string>(channelgroup, true, true, 5, AccessToChannelLevelCallback, DummyErrorCallback); Thread.Sleep(1000); mreGrant.WaitOne(); Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(receivedGrantMessage, "WhenGrantIsRequested -> ThenChannelGroupLevelWithReadManageShouldReturnSuccess failed."); pubnub.PubnubUnitTest = null; pubnub = null; TestComplete(); }); } else { Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.Inconclusive("PAM Not Enabled for WhenGrantIsRequested -> ThenChannelGroupLevelWithReadManageShouldReturnSuccess."); pubnub.PubnubUnitTest = null; pubnub = null; TestComplete(); }); } }); }
public void DetailedHistoryStartWithReverseTrue() { expectedCountAtStartTimeWithReverseTrue = 0; messageStartReverseTrue = false; ThreadPool.QueueUserWorkItem((s) => { Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", false); PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenDetailedHistoryIsRequested"; unitTest.TestCaseName = "DetailedHistoryStartWithReverseTrue"; pubnub.PubnubUnitTest = unitTest; string channel = "hello_my_channel"; if (PubnubCommon.EnableStubTest) { startTimeWithReverseTrue = Pubnub.TranslateDateTimeToPubnubUnixNanoSeconds(new DateTime(2012, 12, 1)); } else { startTimeWithReverseTrue = Pubnub.TranslateDateTimeToPubnubUnixNanoSeconds(DateTime.UtcNow); } for (int index = 0; index < 10; index++) { mrePublish = new ManualResetEvent(false); pubnub.Publish<string>(channel, string.Format("DetailedHistoryStartTimeWithReverseTrue {0}", index), DetailedHistorySamplePublishCallback, DummyErrorCallback); mrePublish.WaitOne(60 * 1000); } mreDetailedHistory = new ManualResetEvent(false); pubnub.DetailedHistory<string>(channel, startTimeWithReverseTrue, DetailedHistoryStartWithReverseTrueCallback, DummyErrorCallback, true); mreDetailedHistory.WaitOne(60 * 1000); Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(messageStartReverseTrue, "Detailed History with Start and Reverse True Failed"); pubnub.PubnubUnitTest = null; pubnub = null; TestComplete(); }); }); }
public void ThenItShouldReturnTimeStamp() { ThreadPool.QueueUserWorkItem((s) => { Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", false); PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenGetRequestServerTime"; unitTest.TestCaseName = "ThenItShouldReturnTimeStamp"; pubnub.PubnubUnitTest = unitTest; pubnub.Time<string>(ReturnTimeStampCallback, DummyErrorCallback); mreTime.WaitOne(60 * 1000); Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(timeReceived, "time() Failed"); TestComplete(); }); }); }
public void DetailHistoryCount10ReturnsRecords() { message10Received = false; ThreadPool.QueueUserWorkItem((s) => { Pubnub pubnub = new Pubnub("demo", "demo", "", "", false); string channel = "hello_my_channel"; PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenDetailedHistoryIsRequested"; unitTest.TestCaseName = "DetailHistoryCount10ReturnsRecords"; pubnub.PubnubUnitTest = unitTest; pubnub.DetailedHistory<string>(channel, 10, DetailedHistoryCount10Callback, DummyErrorCallback); mreMessageCount10.WaitOne(310 * 1000); Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(message10Received, "Detailed History Failed"); TestComplete(); }); }); }
public void ThenMultiSubscribeShouldReturnConnectStatus() { receivedChannel1ConnectMessage = false; receivedChannel2ConnectMessage = false; mreConnect = new ManualResetEvent(false); ThreadPool.QueueUserWorkItem((s) => { Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", false); PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenSubscribedToAChannel"; unitTest.TestCaseName = "ThenMultiSubscribeShouldReturnConnectStatus"; pubnub.PubnubUnitTest = unitTest; string channel1 = "hello_my_channel1"; pubnub.Subscribe <string>(channel1, ReceivedChannelUserCallback, ReceivedChannel1ConnectCallback, DummyErrorCallback); mreConnect.WaitOne(310 * 1000); mreConnect = new ManualResetEvent(false); string channel2 = "hello_my_channel2"; pubnub.Subscribe <string>(channel2, ReceivedChannelUserCallback, ReceivedChannel2ConnectCallback, DummyErrorCallback); mreConnect.WaitOne(310 * 1000); pubnub.EndPendingRequests(); Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(receivedChannel1ConnectMessage && receivedChannel2ConnectMessage, "WhenSubscribedToAChannel --> ThenSubscribeShouldReturnConnectStatus Failed"); pubnub.PubnubUnitTest = null; pubnub = null; TestComplete(); }); }); }
public void ThenSubscribeShouldReturnReceivedMessage() { receivedMessage = false; mreConnect = new ManualResetEvent(false); mrePublish = new ManualResetEvent(false); mreSubscribe = new ManualResetEvent(false); ThreadPool.QueueUserWorkItem((s) => { Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", false); string channel = "hello_my_channel"; PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenSubscribedToAChannel"; unitTest.TestCaseName = "ThenSubscribeShouldReturnReceivedMessage"; pubnub.PubnubUnitTest = unitTest; pubnub.Subscribe <string>(channel, ReceivedMessageCallbackWhenSubscribed, SubscribeDummyMethodForConnectCallback, DummyErrorCallback); mreConnect.WaitOne(310 * 1000); pubnub.Publish <string>(channel, "Test for WhenSubscribedToAChannel ThenItShouldReturnReceivedMessage", dummyPublishCallback, DummyErrorCallback); mrePublish.WaitOne(310 * 1000); mreSubscribe.WaitOne(310 * 1000); //pubnub.Unsubscribe<string>(channel, dummyUnsubscribeCallback, SubscribeDummyMethodForConnectCallback, UnsubscribeDummyMethodForDisconnectCallback, DummyErrorCallback); //Thread.Sleep(500); //meUnsubscribe.WaitOne(60 * 1000); //Thread.Sleep(1000); pubnub.EndPendingRequests(); Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(receivedMessage, "WhenSubscribedToAChannel --> ThenItShouldReturnReceivedMessage Failed"); TestComplete(); }); }); }
public void ThenUnencryptObjectPublishShouldReturnSuccessCodeAndInfo() { ThreadPool.QueueUserWorkItem((s) => { isUnencryptObjectPublished = false; Pubnub pubnub = new Pubnub("demo", "demo", "", "", false); string channel = "hello_my_channel"; object message = new CustomClass(); messageObjectForUnencryptPublish = JsonConvert.SerializeObject(message); PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenAMessageIsPublished"; unitTest.TestCaseName = "ThenUnencryptObjectPublishShouldReturnSuccessCodeAndInfo"; pubnub.PubnubUnitTest = unitTest; pubnub.Publish <string>(channel, message, ReturnSuccessUnencryptObjectPublishCodeCallback, DummyErrorCallback); mreUnencryptObjectPublish.WaitOne(310 * 1000); Thread.Sleep(1000); if (!isUnencryptObjectPublished) { Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(isUnencryptObjectPublished, "Unencrypt Publish Failed"); TestComplete(); }); } else { pubnub.DetailedHistory <string>(channel, -1, unEncryptObjectPublishTimetoken, -1, false, CaptureUnencryptObjectDetailedHistoryCallback, DummyErrorCallback); mreUnencryptObjectDetailedHistory.WaitOne(310 * 1000); Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(isUnencryptObjectDetailedHistory, "Unable to match the successful unencrypt object Publish"); TestComplete(); }); } }); }
public void ThenPublishMpnsFlipTileShouldReturnSuccess() { ThreadPool.QueueUserWorkItem((s) => { receivedSuccessMessage = false; Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", false); string channel = "hello_my_channel"; PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenPushIsRequested"; unitTest.TestCaseName = "ThenPublishMpnsFlipTileShouldReturnSuccess"; pubnub.PubnubUnitTest = unitTest; mrePublish = new ManualResetEvent(false); MpnsFlipTileNotification tile = new MpnsFlipTileNotification(); tile.title = "front title"; tile.count = 6; tile.back_title = "back title"; tile.back_content = "back message"; tile.back_background_image = "Assets/Tiles/pubnub3.png"; tile.background_image = "http://cdn.flaticon.com/png/256/37985.png"; Dictionary <string, object> dicTile = new Dictionary <string, object>(); dicTile.Add("pn_mpns", tile); pubnub.EnableDebugForPushPublish = true; pubnub.Publish <string>(channel, dicTile, PublishCallbackResult, DummyErrorCallback); mrePublish.WaitOne(60 * 1000); Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(receivedSuccessMessage, "Flip Tile Publish Failed"); pubnub.PubnubUnitTest = null; pubnub = null; TestComplete(); }); }); }
public void ThenPresenceShouldReturnCustomUUID() { receivedCustomUUID = false; ThreadPool.QueueUserWorkItem((s) => { Pubnub pubnub = new Pubnub("demo", "demo", "", "", false); PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenAClientIsPresented"; unitTest.TestCaseName = "ThenPresenceShouldReturnCustomUUID"; pubnub.PubnubUnitTest = unitTest; string channel = "my/channel"; pubnub.Presence <string>(channel, ThenPresenceWithCustomUUIDShouldReturnMessage, PresenceUUIDDummyMethodForConnectCallback); Thread.Sleep(1000); //since presence expects from stimulus from sub/unsub... pubnub.SessionUUID = customUUID; pubnub.Subscribe <string>(channel, DummyMethodForSubscribeUUID, SubscribeUUIDDummyMethodForConnectCallback); subscribeUUIDManualEvent.WaitOne(); Thread.Sleep(1000); pubnub.Unsubscribe <string>(channel, DummyMethodForUnSubscribeUUID, UnsubscribeUUIDDummyMethodForConnectCallback, UnsubscribeUUIDDummyMethodForDisconnectCallback); Thread.Sleep(1000); unsubscribeUUIDManualEvent.WaitOne(2000); presenceUUIDManualEvent.WaitOne(); Thread.Sleep(1000); pubnub.EndPendingRequests(); Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(receivedCustomUUID, "Custom UUID not received"); TestComplete(); }); }); }
public void ThenOptionalSecretKeyShouldBeProvidedInConstructor() { ThreadPool.QueueUserWorkItem((s) => { isPublished2 = false; Pubnub pubnub = new Pubnub("demo", "demo", "key"); string channel = "my/channel"; string message = "Pubnub API Usage Example"; PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenAMessageIsPublished"; unitTest.TestCaseName = "ThenOptionalSecretKeyShouldBeProvidedInConstructor"; pubnub.PubnubUnitTest = unitTest; pubnub.Publish <string>(channel, message, ReturnSecretKeyPublishCallback); mreOptionalSecretKeyPublish.WaitOne(310 * 1000); Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(isPublished2, "Publish Failed with secret key"); TestComplete(); }); }); }
public void IfSSLNotProvidedThenDefaultShouldBeFalse() { ThreadPool.QueueUserWorkItem((s) => { isPublished3 = false; Pubnub pubnub = new Pubnub("demo", "demo", ""); string channel = "my/channel"; string message = "Pubnub API Usage Example"; PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenAMessageIsPublished"; unitTest.TestCaseName = "IfSSLNotProvidedThenDefaultShouldBeFalse"; pubnub.PubnubUnitTest = unitTest; pubnub.Publish <string>(channel, message, ReturnNoSSLDefaultFalseCallback); mreNoSslPublish.WaitOne(310 * 1000); Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(isPublished3, "Publish Failed with no SSL"); TestComplete(); }); }); }
public void IfGlobalHereNowIsCalledThenItShouldReturnInfo() { ThreadPool.QueueUserWorkItem((s) => { receivedGlobalHereNowMessage = false; Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", false); PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenAClientIsPresented"; unitTest.TestCaseName = "IfGlobalHereNowIsCalledThenItShouldReturnInfo"; pubnub.PubnubUnitTest = unitTest; mreGlobalHereNow = new ManualResetEvent(false); pubnub.GlobalHereNow <string>(true, true, ThenGlobalHereNowShouldReturnMessage, DummyErrorCallback); mreGlobalHereNow.WaitOne(60 * 1000); Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(receivedGlobalHereNowMessage, "global_here_now message not received"); TestComplete(); }); }); }
public void DetailHistoryCount10ReturnsRecords() { messageReceived = false; ThreadPool.QueueUserWorkItem((s) => { Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", false); string channel = "hello_my_channel"; PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenDetailedHistoryIsRequested"; unitTest.TestCaseName = "DetailHistoryCount10ReturnsRecords"; pubnub.PubnubUnitTest = unitTest; mreDetailedHistory = new ManualResetEvent(false); pubnub.DetailedHistory <string>(channel, 10, DetailedHistoryCount10Callback, DummyErrorCallback); mreDetailedHistory.WaitOne(60 * 1000); Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(messageReceived, "Detailed History Failed"); TestComplete(); }); }); }
public void ThenUnencryptPublishShouldReturnSuccessCodeAndInfo() { ThreadPool.QueueUserWorkItem((s) => { isUnencryptPublished = false; Pubnub pubnub = new Pubnub("demo", "demo", "", "", false); string channel = "my/channel"; string message = messageForUnencryptPublish; PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenAMessageIsPublished"; unitTest.TestCaseName = "ThenUnencryptPublishShouldReturnSuccessCodeAndInfo"; pubnub.PubnubUnitTest = unitTest; pubnub.Publish<string>(channel, message, ReturnSuccessUnencryptPublishCodeCallback); mreUnencryptedPublish.WaitOne(310 * 1000); if (!isUnencryptPublished) { Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(isUnencryptPublished, "Unencrypt Publish Failed"); TestComplete(); }); } else { pubnub.DetailedHistory<string>(channel, -1, unEncryptPublishTimetoken, -1, false, CaptureUnencryptDetailedHistoryCallback); mreUnencryptDetailedHistory.WaitOne(310 * 1000); Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(isUnencryptDetailedHistory, "Unable to match the successful unencrypt Publish"); TestComplete(); }); } }); }
public void ThenChannelLevelShouldReturnSuccess() { currentUnitTestCase = "ThenChannelLevelShouldReturnSuccess"; receivedAuditMessage = false; ThreadPool.QueueUserWorkItem((s) => { Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, PubnubCommon.SecretKey, "", false); PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenAuditIsRequested"; unitTest.TestCaseName = "ThenChannelLevelShouldReturnSuccess"; pubnub.PubnubUnitTest = unitTest; string channel = "hello_my_channel"; if (PubnubCommon.PAMEnabled) { mreAudit = new ManualResetEvent(false); pubnub.AuditAccess <string>(channel, AccessToChannelLevelCallback, DummyErrorCallback); mreAudit.WaitOne(60 * 1000); Assert.IsTrue(receivedAuditMessage, "WhenAuditIsRequested -> ThenChannelLevelShouldReturnSuccess failed."); } else { Assert.Inconclusive("PAM Not Enabled for WhenAuditIsRequested -> ThenChannelLevelShouldReturnSuccess"); } Deployment.Current.Dispatcher.BeginInvoke(() => { pubnub.PubnubUnitTest = null; pubnub = null; TestComplete(); }); }); }
public void ThenSecretKeyWithEncryptPublishShouldReturnSuccessCodeAndInfo() { ThreadPool.QueueUserWorkItem((s) => { isSecretEncryptPublished = false; Pubnub pubnub = new Pubnub("demo", "demo", "key", "enigma", false); string channel = "my/channel"; string message = messageForSecretEncryptPublish; PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenAMessageIsPublished"; unitTest.TestCaseName = "ThenSecretKeyWithEncryptPublishShouldReturnSuccessCodeAndInfo"; pubnub.PubnubUnitTest = unitTest; pubnub.Publish <string>(channel, message, ReturnSuccessSecretEncryptPublishCodeCallback); mreSecretEncryptPublish.WaitOne(310 * 1000); if (!isSecretEncryptPublished) { Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(isSecretEncryptPublished, "Secret Encrypt Publish Failed"); TestComplete(); }); } else { pubnub.DetailedHistory <string>(channel, -1, secretEncryptPublishTimetoken, -1, false, CaptureSecretEncryptDetailedHistoryCallback); mreSecretEncryptDetailedHistory.WaitOne(310 * 1000); Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(isSecretEncryptDetailedHistory, "Unable to decrypt the successful Secret key Publish"); TestComplete(); }); } }); }
public void ThenUserLevelWithReadWriteShouldReturnSuccess() { currentUnitTestCase = "ThenUserLevelWithReadWriteShouldReturnSuccess"; receivedGrantMessage = false; ThreadPool.QueueUserWorkItem((s) => { Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, PubnubCommon.SecretKey, "", false); PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenGrantIsRequested"; unitTest.TestCaseName = "ThenUserLevelWithReadWriteShouldReturnSuccess"; pubnub.PubnubUnitTest = unitTest; string channel = "hello_my_authchannel"; string authKey = "hello_my_authkey"; if (PubnubCommon.PAMEnabled) { mreGrant = new ManualResetEvent(false); pubnub.AuthenticationKey = authKey; pubnub.GrantAccess <string>(channel, true, true, 5, AccessToUserLevelCallback, DummyErrorCallback); mreGrant.WaitOne(60 * 1000); Assert.IsTrue(receivedGrantMessage, "WhenGrantIsRequested -> ThenUserLevelWithReadWriteShouldReturnSuccess failed."); } else { Assert.Inconclusive("PAM Not Enabled for WhenGrantIsRequested -> ThenUserLevelWithReadWriteShouldReturnSuccess."); } Deployment.Current.Dispatcher.BeginInvoke(() => { TestComplete(); }); }); }
public void ThenOptionalSecretKeyShouldBeProvidedInConstructor() { ThreadPool.QueueUserWorkItem((s) => { isPublished2 = false; Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, PubnubCommon.SecretKey); string channel = "hello_my_channel"; string message = "Pubnub API Usage Example"; PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenAMessageIsPublished"; unitTest.TestCaseName = "ThenOptionalSecretKeyShouldBeProvidedInConstructor"; pubnub.PubnubUnitTest = unitTest; mrePublish = new ManualResetEvent(false); pubnub.Publish <string>(channel, message, ReturnSecretKeyPublishCallback, DummyErrorCallback); mrePublish.WaitOne(60 * 1000); Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(isPublished2, "Publish Failed with secret key"); TestComplete(); }); }); }
public void ThenLargeMessageShoudFailWithMessageTooLargeInfo() { ThreadPool.QueueUserWorkItem((s) => { isLargeMessagePublished = false; Pubnub pubnub = new Pubnub("demo", "demo", "", "", false); PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenAMessageIsPublished"; unitTest.TestCaseName = "ThenLargeMessageShoudFailWithMessageTooLargeInfo"; pubnub.PubnubUnitTest = unitTest; string channel = "my/channel"; string message = messageLarge2K; pubnub.Publish <string>(channel, message, ReturnPublishMessageTooLargeInfoCallback); mreLaregMessagePublish.WaitOne(310 * 1000); Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(isLargeMessagePublished, "Message Too Large is not failing as expected."); TestComplete(); }); }); }
public void ThenPresenceShouldReturnReceivedMessage() { receivedPresenceMessage = false; ThreadPool.QueueUserWorkItem((s) => { Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", false); string channel = "hello_my_channel"; PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenAClientIsPresented"; unitTest.TestCaseName = "ThenPresenceShouldReturnReceivedMessage"; pubnub.PubnubUnitTest = unitTest; mreConnect = new ManualResetEvent(false); mrePresence = new ManualResetEvent(false); pubnub.Presence <string>(channel, ThenPresenceShouldReturnMessage, PresenceDummyMethodForConnectCallback, DummyErrorCallback); mreConnect.WaitOne(310 * 1000); //since presence expects from stimulus from sub/unsub... mreSubscribe = new ManualResetEvent(false); pubnub.Subscribe <string>(channel, DummyMethodForSubscribe, SubscribeDummyMethodForConnectCallback, DummyErrorCallback); mreSubscribe.WaitOne(310 * 1000); mrePresence.WaitOne(310 * 1000); pubnub.EndPendingRequests(); Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(receivedPresenceMessage, "Presence message not received"); pubnub.PubnubUnitTest = null; pubnub = null; TestComplete(); }); }); }
public void IfSSLNotProvidedThenDefaultShouldBeFalse() { ThreadPool.QueueUserWorkItem((s) => { isPublished3 = false; Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, ""); string channel = "hello_my_channel"; string message = "Pubnub API Usage Example"; PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenAMessageIsPublished"; unitTest.TestCaseName = "IfSSLNotProvidedThenDefaultShouldBeFalse"; pubnub.PubnubUnitTest = unitTest; mrePublish = new ManualResetEvent(false); pubnub.Publish <string>(channel, message, ReturnNoSSLDefaultFalseCallback, DummyErrorCallback); mrePublish.WaitOne(60 * 1000); Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(isPublished3, "Publish Failed with no SSL"); TestComplete(); }); }); }
public void ThenSubscriberShouldBeAbleToReceiveManyMessages() { receivedManyMessages = false; Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", false); PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenSubscribedToAChannel"; unitTest.TestCaseName = "ThenSubscriberShouldBeAbleToReceiveManyMessages"; pubnub.PubnubUnitTest = unitTest; string channel = "hello_my_channel"; pubnub.Subscribe<string>(channel, SubscriberDummyMethodForManyMessagesUserCallback, SubscribeDummyMethodForManyMessagesConnectCallback, DummyErrorCallback); subscribeEvent.WaitOne(310 * 1000); if (!unitTest.EnableStubTest) { for (int index = 0; index < 10; index++) { pubnub.Publish<string>(channel, index.ToString(), dummyPublishCallback, DummyErrorCallback); mePublish.WaitOne(10 * 1000); } } meSubscriberManyMessages.WaitOne(310 * 1000); pubnub.EndPendingRequests(); Assert.IsTrue(receivedManyMessages, "WhenSubscribedToAChannel --> ThenSubscriberShouldBeAbleToReceiveManyMessages Failed"); }
public void IfSSLNotProvidedThenDefaultShouldBeFalse() { ThreadPool.QueueUserWorkItem((s) => { isPublished3 = false; Pubnub pubnub = new Pubnub("demo", "demo", ""); string channel = "my/channel"; string message = "Pubnub API Usage Example"; PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenAMessageIsPublished"; unitTest.TestCaseName = "IfSSLNotProvidedThenDefaultShouldBeFalse"; pubnub.PubnubUnitTest = unitTest; pubnub.Publish<string>(channel, message, ReturnNoSSLDefaultFalseCallback); mreNoSslPublish.WaitOne(310 * 1000); Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(isPublished3, "Publish Failed with no SSL"); TestComplete(); }); }); }
public void ThenMultiSubscribeShouldReturnConnectStatus() { currentUnitTestCase = "ThenMultiSubscribeShouldReturnConnectStatus"; receivedMessage = false; receivedChannelGroupMessage1 = false; receivedChannelGroupMessage2 = false; expectedCallbackResponses = 2; currentCallbackResponses = 0; ThreadPool.QueueUserWorkItem((s) => { Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", false); pubnub.SessionUUID = "myuuid"; PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenSubscribedToAChannelGroup"; unitTest.TestCaseName = "ThenMultiSubscribeShouldReturnConnectStatus"; pubnub.PubnubUnitTest = unitTest; manualResetEventsWaitTimeout = (unitTest.EnableStubTest) ? 6000 : 310 * 1000; channelGroupName1 = "hello_my_group1"; channelGroupName2 = "hello_my_group2"; string channelName1 = "hello_my_channel1"; string channelName2 = "hello_my_channel2"; string channel1 = "hello_my_channel1"; subscribeManualEvent = new ManualResetEvent(false); pubnub.AddChannelsToChannelGroup <string>(new string[] { channelName1 }, channelGroupName1, ChannelGroupAddCallback, DummySubscribeErrorCallback); Thread.Sleep(1000); subscribeManualEvent.WaitOne(manualResetEventsWaitTimeout); subscribeManualEvent = new ManualResetEvent(false); pubnub.AddChannelsToChannelGroup <string>(new string[] { channelName2 }, channelGroupName2, ChannelGroupAddCallback, DummySubscribeErrorCallback); Thread.Sleep(1000); subscribeManualEvent.WaitOne(manualResetEventsWaitTimeout); if (receivedChannelGroupMessage1 && receivedChannelGroupMessage2) { subscribeManualEvent = new ManualResetEvent(false); pubnub.Subscribe <string>("", string.Format("{0},{1}", channelGroupName1, channelGroupName2), ReceivedMessageCallbackWhenSubscribed, SubscribeConnectCallback, DummySubscribeErrorCallback); subscribeManualEvent.WaitOne(manualResetEventsWaitTimeout); pubnub.EndPendingRequests(); Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(receivedMessage, "WhenSubscribedToAChannelGroup --> ThenMultiSubscribeShouldReturnConnectStatusFailed"); TestComplete(); }); } else { Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(receivedChannelGroupMessage1 && receivedChannelGroupMessage2, "WhenSubscribedToAChannelGroup --> ThenMultiSubscribeShouldReturnConnectStatusFailed"); TestComplete(); }); } }); }
public void ThenEncryptObjectPublishShouldReturnSuccessCodeAndInfo() { ThreadPool.QueueUserWorkItem((s) => { isEncryptObjectPublished = false; Pubnub pubnub = new Pubnub("demo", "demo", "", "enigma", false); string channel = "my/channel"; object message = new SecretCustomClass(); messageObjectForEncryptPublish = JsonConvert.SerializeObject(message); PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenAMessageIsPublished"; unitTest.TestCaseName = "ThenEncryptObjectPublishShouldReturnSuccessCodeAndInfo"; pubnub.PubnubUnitTest = unitTest; pubnub.Publish<string>(channel, message, ReturnSuccessEncryptObjectPublishCodeCallback); mreEncryptObjectPublish.WaitOne(310 * 1000); if (!isEncryptObjectPublished) { Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(isEncryptObjectPublished, "Encrypt Object Publish Failed"); TestComplete(); }); } else { pubnub.DetailedHistory<string>(channel, -1, encryptObjectPublishTimetoken, -1, false, CaptureEncryptObjectDetailedHistoryCallback); mreEncryptObjectDetailedHistory.WaitOne(310 * 1000); Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(isEncryptObjectDetailedHistory, "Unable to match the successful encrypt object Publish"); TestComplete(); }); } }); }
public void ThenOptionalSecretKeyShouldBeProvidedInConstructor() { ThreadPool.QueueUserWorkItem((s) => { isPublished2 = false; Pubnub pubnub = new Pubnub("demo", "demo", "key"); string channel = "my/channel"; string message = "Pubnub API Usage Example"; PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenAMessageIsPublished"; unitTest.TestCaseName = "ThenOptionalSecretKeyShouldBeProvidedInConstructor"; pubnub.PubnubUnitTest = unitTest; pubnub.Publish<string>(channel, message, ReturnSecretKeyPublishCallback); mreOptionalSecretKeyPublish.WaitOne(310 * 1000); Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(isPublished2, "Publish Failed with secret key"); TestComplete(); }); }); }
public void ThenMultiSubscribeShouldReturnConnectStatus() { receivedChannel1ConnectMessage = false; receivedChannel2ConnectMessage = false; Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", false); PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenSubscribedToAChannel"; unitTest.TestCaseName = "ThenMultiSubscribeShouldReturnConnectStatus"; pubnub.PubnubUnitTest = unitTest; string channel1 = "hello_my_channel1"; pubnub.Subscribe<string>(channel1, ReceivedChannelUserCallback, ReceivedChannel1ConnectCallback, DummyErrorCallback); meChannel1SubscribeConnect.WaitOne(310 * 1000); string channel2 = "hello_my_channel2"; pubnub.Subscribe<string>(channel2, ReceivedChannelUserCallback, ReceivedChannel2ConnectCallback, DummyErrorCallback); meChannel2SubscribeConnect.WaitOne(310 * 1000); Thread.Sleep(500); pubnub.EndPendingRequests(); Assert.IsTrue(receivedChannel1ConnectMessage && receivedChannel2ConnectMessage, "WhenSubscribedToAChannel --> ThenSubscribeShouldReturnConnectStatus Failed"); }
public void ThenDuplicateChannelShouldReturnAlreadySubscribed() { receivedAlreadySubscribedMessage = false; Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", false); PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenSubscribedToAChannel"; unitTest.TestCaseName = "ThenDuplicateChannelShouldReturnAlreadySubscribed"; pubnub.PubnubUnitTest = unitTest; string channel = "hello_my_channel"; pubnub.Subscribe<string>(channel, DummyMethodDuplicateChannelUserCallback1, DummyMethodDuplicateChannelConnectCallback, DummyErrorCallback); Thread.Sleep(100); pubnub.Subscribe<string>(channel, DummyMethodDuplicateChannelUserCallback2, DummyMethodDuplicateChannelConnectCallback, DuplicateChannelErrorCallback); meAlreadySubscribed.WaitOne(); pubnub.EndPendingRequests(); Assert.IsTrue(receivedAlreadySubscribedMessage, "WhenSubscribedToAChannel --> ThenDuplicateChannelShouldReturnAlreadySubscribed Failed"); }
public void ThenSubscribeShouldReturnReceivedMessage() { receivedMessage = false; Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", false); string channel = "hello_my_channel"; PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenSubscribedToAChannel"; unitTest.TestCaseName = "ThenSubscribeShouldReturnReceivedMessage"; pubnub.PubnubUnitTest = unitTest; pubnub.Subscribe<string>(channel, ReceivedMessageCallbackWhenSubscribed, SubscribeDummyMethodForConnectCallback, DummyErrorCallback); subscribeEvent.WaitOne(30 * 1000); //Thread.Sleep(500); pubnub.Publish<string>(channel, "Test for WhenSubscribedToAChannel ThenItShouldReturnReceivedMessage", dummyPublishCallback, DummyErrorCallback); mePublish.WaitOne(310 * 1000); //Thread.Sleep(500); meSubscribeNoConnect.WaitOne(310 * 1000); pubnub.Unsubscribe<string>(channel, dummyUnsubscribeCallback, SubscribeDummyMethodForConnectCallback, UnsubscribeDummyMethodForDisconnectCallback, DummyErrorCallback); Thread.Sleep(500); meUnsubscribe.WaitOne(310 * 1000); Thread.Sleep(1000); pubnub.EndPendingRequests(); Assert.IsTrue(receivedMessage, "WhenSubscribedToAChannel --> ThenItShouldReturnReceivedMessage Failed"); }
public void ThenLargeMessageShoudFailWithMessageTooLargeInfo() { ThreadPool.QueueUserWorkItem((s) => { isLargeMessagePublished = false; Pubnub pubnub = new Pubnub("demo", "demo", "", "", false); PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenAMessageIsPublished"; unitTest.TestCaseName = "ThenLargeMessageShoudFailWithMessageTooLargeInfo"; pubnub.PubnubUnitTest = unitTest; string channel = "my/channel"; string message = messageLarge2K; pubnub.Publish<string>(channel, message, ReturnPublishMessageTooLargeInfoCallback); mreLaregMessagePublish.WaitOne(310 * 1000); Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(isLargeMessagePublished, "Message Too Large is not failing as expected."); TestComplete(); }); }); }
public void ThenDisableJsonEncodeShouldSendSerializedObjectMessage() { ThreadPool.QueueUserWorkItem((s) => { isSerializedObjectMessagePublished = false; Pubnub pubnub = new Pubnub("demo", "demo", "", "", false); pubnub.EnableJsonEncodingForPublish = false; PubnubUnitTest unitTest = new PubnubUnitTest(); unitTest.TestClassName = "WhenAMessageIsPublished"; unitTest.TestCaseName = "ThenDisableJsonEncodeShouldSendSerializedObjectMessage"; pubnub.PubnubUnitTest = unitTest; string channel = "my/channel"; object message = "{\"operation\":\"ReturnData\",\"channel\":\"Mobile1\",\"sequenceNumber\":0,\"data\":[\"ping 1.0.0.1\"]}"; serializedObjectMessageForPublish = message.ToString(); pubnub.Publish<string>(channel, message, ReturnSuccessSerializedObjectMessageForPublishCallback); mreSerializedObjectMessageForPublish.WaitOne(310 * 1000); if (!isSerializedObjectMessagePublished) { Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(isSerializedObjectMessagePublished, "Serialized Object Message Publish Failed"); TestComplete(); }); } else { pubnub.DetailedHistory<string>(channel, -1, serializedMessagePublishTimetoken, -1, false, CaptureSerializedMessagePublishDetailedHistoryCallback); mreSerializedMessagePublishDetailedHistory.WaitOne(310 * 1000); Deployment.Current.Dispatcher.BeginInvoke(() => { Assert.IsTrue(isSerializedObjectMessageDetailedHistory, "Unable to match the successful serialized object message Publish"); TestComplete(); }); } }); }