Exemplo n.º 1
0
        public void ThenSubKeyLevelWithReadShouldReturnSuccess()
        {
            grantAccessCallbackInvoked = false;

            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)
            {
                EnqueueCallback(() => pubnub.GrantAccess<string>("", true, false, 5, AccessToSubKeyLevelCallback, DummyErrorCallback));
                //Thread.Sleep(1000);

                EnqueueConditional(() => grantAccessCallbackInvoked);

                EnqueueCallback(() => Assert.IsTrue(receivedGrantMessage, "WhenGrantIsRequested -> ThenSubKeyLevelWithReadShouldReturnSuccess failed."));
            }
            else
            {
                EnqueueCallback(() => Assert.Inconclusive("PAM Not Enabled for WhenGrantIsRequested -> ThenSubKeyLevelWithReadShouldReturnSuccess."));
            }
            EnqueueTestComplete();
        }
Exemplo n.º 2
0
        public void ThenChannelLevelShouldReturnSuccess()
        {
            auditAccessCallbackInvoked = false;

            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)
            {
                EnqueueCallback(() => pubnub.AuditAccess<string>(channel, AccessToChannelLevelCallback, DummyErrorCallback));
                //Thread.Sleep(1000);
                EnqueueConditional(() => auditAccessCallbackInvoked);
                EnqueueCallback(() => Assert.IsTrue(receivedAuditMessage, "WhenAuditIsRequested -> ThenChannelLevelShouldReturnSuccess failed."));
            }
            else
            {
                EnqueueCallback(() => Assert.Inconclusive("PAM Not Enabled for WhenAuditIsRequested -> ThenChannelLevelShouldReturnSuccess"));
            }
            EnqueueTestComplete();
        }
        public void ThenSubKeyLevelWithReadShouldReturnSuccess()
        {
            currentUnitTestCase = "ThenSubKeyLevelWithReadShouldReturnSuccess";
            mreGrant = new ManualResetEvent(false);

            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 = "ThenSubKeyLevelWithReadShouldReturnSuccess";
                    pubnub.PubnubUnitTest = unitTest;
                    if (PubnubCommon.PAMEnabled)
                    {
                        EnqueueCallback(() => pubnub.GrantAccess<string>("", true, false, 5, AccessToSubKeyLevelCallback, DummyErrorCallback));
                        mreGrant.WaitOne(310 * 1000);
                        EnqueueCallback(() => Assert.IsTrue(receivedGrantMessage, "WhenGrantIsRequested -> ThenSubKeyLevelWithReadShouldReturnSuccess failed."));
                    }
                    else
                    {
                        EnqueueCallback(() => Assert.Inconclusive("PAM Not Enabled for WhenGrantIsRequested -> ThenSubKeyLevelWithReadShouldReturnSuccess."));
                    }
                    EnqueueTestComplete();
                });
        }
Exemplo n.º 4
0
        public void Init()
        {
            if (!PubnubCommon.PAMEnabled)
            {
                EnqueueTestComplete();
                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 = "Init2";
                    pubnub.PubnubUnitTest = unitTest;

                    string channel = "hello_my_channel,hello_my_channel-pnpres";
                    EnqueueCallback(() => pubnub.GrantAccess<string>(channel, true, true, 20, ThenPresenceInitializeShouldReturnGrantMessage, DummyErrorCallback));
                    mreGrant.WaitOne(310 * 1000);

                    EnqueueCallback(() => Assert.IsTrue(receivedGrantMessage, "WhenAClientIsPresent Grant access failed."));
                    EnqueueTestComplete();
                });
        }
Exemplo n.º 5
0
        public void ThenUnencryptPublishShouldReturnSuccessCodeAndInfo()
        {
            isUnencryptPublished = false;
            Pubnub pubnub = new Pubnub("demo","demo","","",false);
            string channel = "hello_my_channel";
            string message = messageForUnencryptPublish;

            PubnubUnitTest unitTest = new PubnubUnitTest();
            unitTest.TestClassName = "WhenAMessageIsPublished";
            unitTest.TestCaseName = "ThenUnencryptPublishShouldReturnSuccessCodeAndInfo";
            pubnub.PubnubUnitTest = unitTest;

            EnqueueCallback(() => pubnub.Publish<string>(channel, message, ReturnSuccessUnencryptPublishCodeCallback, DummyErrorCallback));
            EnqueueConditional(() => isCheck);

            EnqueueCallback(() => 
            {
                if (!isUnencryptPublished)
                {
                    Assert.IsTrue(isUnencryptPublished, "Unencrypt Publish Failed");
                }
                else
                {
                    EnqueueCallback(() => pubnub.DetailedHistory<string>(channel, -1, unEncryptPublishTimetoken, -1, false, CaptureUnencryptDetailedHistoryCallback, DummyErrorCallback));
                    EnqueueConditional(() => isUnencryptCheck);
                    EnqueueCallback(() => Assert.IsTrue(isUnencryptDH, "Unable to match the successful unencrypt Publish"));
                }
            });

            EnqueueTestComplete();
        }
        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";

                    EnqueueCallback(() => pubnub.AddChannelsToChannelGroup<string>(new string[] { channelName }, channelGroupName, ChannelGroupCRUDCallback, DummyErrorCallback));
                    channelGroupManualEvent.WaitOne(310*1000);

                    EnqueueCallback(() => Assert.IsTrue(receivedChannelGroupMessage, "WhenChannelGroupIsRequested -> ThenAddChannelShouldReturnSuccess failed."));
                    EnqueueCallback(() =>
                            {
                                pubnub.PubnubUnitTest = null;
                                pubnub = null;
                            }
                        );
                    EnqueueTestComplete();
                });
        }
        public void ThenNoExistChannelShouldReturnNotSubscribed()
        {
            receivedNotSubscribedMessage = false;
            mreUnsubscribe = new ManualResetEvent(false);

            ThreadPool.QueueUserWorkItem((s) =>
                {
                    Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", false);

                    PubnubUnitTest unitTest = new PubnubUnitTest();
                    unitTest.TestClassName = "WhenUnsubscribedToAChannel";
                    unitTest.TestCaseName = "ThenNoExistChannelShouldReturnNotSubscribed";

                    pubnub.PubnubUnitTest = unitTest;

                    string channel = "hello_my_channel";

                    EnqueueCallback(() => pubnub.Unsubscribe<string>(channel, DummyMethodNoExistChannelUnsubscribeChannelUserCallback, DummyMethodNoExistChannelUnsubscribeChannelConnectCallback, DummyMethodNoExistChannelUnsubscribeChannelDisconnectCallback1, NoExistChannelErrorCallback));
                    mreUnsubscribe.WaitOne(310 * 1000);

                    EnqueueCallback(() => pubnub.EndPendingRequests());
                    EnqueueCallback(() => Assert.IsTrue(receivedNotSubscribedMessage, "WhenUnsubscribedToAChannel --> ThenNoExistChannelShouldReturnNotSubscribed Failed"));
                    EnqueueTestComplete();
                });
        }
Exemplo n.º 8
0
        public void Init()
        {
            if (!PubnubCommon.PAMEnabled)
            {
                EnqueueTestComplete();
                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,hello_my_channel1,hello_my_channel2";

            EnqueueCallback(() => pubnub.GrantAccess<string>(channel, true, true, 20, ThenSubscribeInitializeShouldReturnGrantMessage, DummyErrorCallback));
            //Thread.Sleep(1000);

            EnqueueConditional(() => grantInitCallbackInvoked);

            EnqueueCallback(() => Assert.IsTrue(receivedGrantMessage, "WhenSubscribedToAChannel Grant access failed."));
            EnqueueTestComplete();
        }
        public void ThenChannelLevelShouldReturnSuccess()
        {
            currentUnitTestCase = "ThenChannelLevelShouldReturnSuccess";

            receivedAuditMessage = false;
            mreAudit = new ManualResetEvent(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)
                    {
                        EnqueueCallback(() => pubnub.AuditAccess<string>(channel, AccessToChannelLevelCallback, DummyErrorCallback));
                        mreAudit.WaitOne(310 * 1000);

                        EnqueueCallback(() => Assert.IsTrue(receivedAuditMessage, "WhenAuditIsRequested -> ThenChannelLevelShouldReturnSuccess failed."));
                    }
                    else
                    {
                        EnqueueCallback(() => Assert.Inconclusive("PAM Not Enabled for WhenAuditIsRequested -> ThenChannelLevelShouldReturnSuccess"));
                    }
                    EnqueueTestComplete();
                });
        }
        public void Init()
        {
            if (!PubnubCommon.PAMEnabled)
            {
                EnqueueTestComplete();
                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;

                    EnqueueCallback(() => pubnub.ChannelGroupGrantAccess<string>(channelGroupName, true, true, 20, ThenChannelGroupInitializeShouldReturnGrantMessage, DummySubscribeErrorCallback));
                    grantManualEvent.WaitOne(310 * 1000);

                    EnqueueCallback(() => Assert.IsTrue(receivedGrantMessage, "WhenSubscribedToAChannelGroup Grant access failed."));
                    EnqueueCallback(() =>
                            {
                                pubnub.PubnubUnitTest = null;
                                pubnub = null;
                            }
                        );
                    EnqueueTestComplete();
                });
        }
Exemplo n.º 11
0
        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;

            EnqueueCallback(() => pubnub.Time<string>(ReturnTimeStampCallback, DummyErrorCallback));
            EnqueueConditional(() => isTimeStamp);
            EnqueueCallback(() => Assert.IsTrue(timeReceived, "time() Failed"));
            EnqueueTestComplete();
        }
        public void ThenItShouldReturnTimeStamp()
        {
            mreTime = new ManualResetEvent(false);

            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;

                    EnqueueCallback(() => pubnub.Time<string>(ReturnTimeStampCallback, DummyErrorCallback));
                    mreTime.WaitOne(310 * 1000);
                    EnqueueCallback(() => Assert.IsTrue(timeReceived, "time() Failed"));
                    EnqueueTestComplete();
                });
        }
        public void DetailHistoryCount10ReverseTrueReturnsRecords()
        {
            message10ReverseTrueReceived = false;

            Pubnub pubnub = new Pubnub("demo", "demo", "", "", false);
            string channel = "my/channel";

            PubnubUnitTest unitTest = new PubnubUnitTest();
            unitTest.TestClassName = "WhenDetailedHistoryIsRequested";
            unitTest.TestCaseName = "DetailHistoryCount10ReverseTrueReturnsRecords";
            pubnub.PubnubUnitTest = unitTest;

            EnqueueCallback(() => pubnub.DetailedHistory<string>(channel, -1, -1, 10, true, DetailedHistoryCount10ReverseTrueCallback));
            EnqueueConditional(() => detailedHistoryCount10ReverseCallbackInvoked);
            EnqueueCallback(() => Assert.IsTrue(message10ReverseTrueReceived, "Detailed History Failed"));

            EnqueueTestComplete();
        }
Exemplo n.º 14
0
        public void ThenNoExistChannelShouldReturnNotSubscribed()
        {
            receivedNotSubscribedMessage = false;
            Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", false);

            PubnubUnitTest unitTest = new PubnubUnitTest();
            unitTest.TestClassName = "WhenUnsubscribedToAChannel";
            unitTest.TestCaseName = "ThenNoExistChannelShouldReturnNotSubscribed";

            pubnub.PubnubUnitTest = unitTest;

            string channel = "hello_my_channel";

            EnqueueCallback(() => pubnub.Unsubscribe<string>(channel, DummyMethodNoExistChannelUnsubscribeChannelUserCallback, DummyMethodNoExistChannelUnsubscribeChannelConnectCallback, DummyMethodNoExistChannelUnsubscribeChannelDisconnectCallback1, NoExistChannelErrorCallback));
            EnqueueConditional(() => nochannelUnsubscribeInvoked);
            EnqueueCallback(() => pubnub.EndPendingRequests());
            EnqueueCallback(() => Assert.IsTrue(receivedNotSubscribedMessage, "WhenUnsubscribedToAChannel --> ThenNoExistChannelShouldReturnNotSubscribed Failed"));
            EnqueueTestComplete();
        }
Exemplo n.º 15
0
        public void ThenSubscribeShouldReturnConnectStatus()
        {
            receivedConnectMessage = false;
            Pubnub pubnub = new Pubnub("demo", "demo", "", "", false);

            PubnubUnitTest unitTest = new PubnubUnitTest();
            unitTest.TestClassName = "WhenSubscribedToAChannel";
            unitTest.TestCaseName = "ThenSubscribeShouldReturnConnectStatus";

            pubnub.PubnubUnitTest = unitTest;

            string channel = "my/channel";

            EnqueueCallback(() => pubnub.Subscribe<string>(channel, ReceivedMessageCallbackYesConnect, ConnectStatusCallback));
            EnqueueConditional(() => receivedConnectMessage);

            EnqueueCallback(() => pubnub.EndPendingRequests());
            EnqueueCallback(() => Thread.Sleep(200));

            EnqueueCallback(() => Assert.IsTrue(receivedConnectMessage, "WhenSubscribedToAChannel --> ThenSubscribeShouldReturnConnectStatus Failed"));
            EnqueueTestComplete();
        }
Exemplo n.º 16
0
        public void ThenPresenceShouldReturnReceivedMessage()
        {
            receivedPresenceMessage = false;

            Pubnub pubnub = new Pubnub("demo", "demo", "", "", false);
            string channel = "hello_my_channel";

            PubnubUnitTest unitTest = new PubnubUnitTest();
            unitTest.TestClassName = "WhenAClientIsPresented";
            unitTest.TestCaseName = "ThenPresenceShouldReturnReceivedMessage";
            pubnub.PubnubUnitTest = unitTest;

            EnqueueCallback(() => pubnub.Presence<string>(channel, ThenPresenceShouldReturnMessage, PresenceDummyMethodForConnectCallback, DummyErrorCallback));
            EnqueueCallback(() => pubnub.Subscribe<string>(channel, DummyMethodForSubscribe, SubscribeDummyMethodForConnectCallback, DummyErrorCallback));
            EnqueueConditional(() => subscribeConnectStatusCallbackInvoked);
            EnqueueConditional(() => subscribeCallbackInvoked);
            EnqueueCallback(() => pubnub.EndPendingRequests());
            EnqueueConditional(() => presenceReturnMessageCallbackInvoked);
            EnqueueCallback(() => Assert.IsTrue(receivedPresenceMessage, "Presence message not received"));

            EnqueueTestComplete();
        }
Exemplo n.º 17
0
        public void ThenSubscribeShouldReturnReceivedMessage()
        {
            receivedSubscribeMessage = false;
            Pubnub pubnub = new Pubnub("demo", "demo", "", "", false);

            string channel = "my/channel";
            PubnubUnitTest unitTest = new PubnubUnitTest();
            unitTest.TestClassName = "WhenSubscribedToAChannel";
            unitTest.TestCaseName = "ThenSubscribeShouldReturnReceivedMessage";
            pubnub.PubnubUnitTest = unitTest;

            EnqueueCallback(() => pubnub.Subscribe<string>(channel, ReceivedMessageCallbackWhenSubscribed, SubscribeDummyMethodForConnectCallback));
            EnqueueConditional(() => receivedSubscribeMessage);
            //EnqueueConditional(() => subscribeConnected);
            EnqueueCallback(() => pubnub.Publish<string>(channel, "Test for WhenSubscribedToAChannel ThenItShouldReturnReceivedMessage", dummyPublishCallback));
            EnqueueConditional(() => publishInCallback);
            //EnqueueConditional(() => receivedMessageInCallback);
            EnqueueCallback(() => pubnub.EndPendingRequests());
            EnqueueCallback(() => Assert.IsTrue(receivedSubscribeMessage, "WhenSubscribedToAChannel --> ThenItShouldReturnReceivedMessage Failed"));

            EnqueueTestComplete();
        }
Exemplo n.º 18
0
        public void ThenPublishMpnsCycleTileShouldReturnSuccess()
        {
            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 = "ThenPublishMpnsCycleTileShouldReturnSuccess";
                pubnub.PubnubUnitTest = unitTest;

                mrePublish = new ManualResetEvent(false);

                MpnsCycleTileNotification tile = new MpnsCycleTileNotification();
                tile.title = "front title";
                tile.count = 2;
                tile.images = new string[] { "Assets/Tiles/pubnub1.png", "Assets/Tiles/pubnub2.png", "Assets/Tiles/pubnub3.png", "Assets/Tiles/pubnub4.png" };

                Dictionary<string, object> dicTile = new Dictionary<string, object>();
                dicTile.Add("pn_mpns", tile);

                pubnub.EnableDebugForPushPublish = true;
                EnqueueCallback(() => pubnub.Publish<string>(channel, dicTile, PublishCallbackResult, DummyErrorCallback));
                mrePublish.WaitOne(60 * 1000);

                EnqueueCallback(() => Assert.IsTrue(receivedSuccessMessage, "Cycle Tile Publish Failed"));

                EnqueueCallback(() =>
                        {
                            pubnub.PubnubUnitTest = null;
                            pubnub = null;
                        }
                    );
                EnqueueTestComplete();
            });
        }
Exemplo n.º 19
0
        public void ThenSubscribeShouldReturnConnectStatus()
        {
            receivedConnectMessage = false;
            Pubnub pubnub = new Pubnub("demo", "demo", "", "", false);

            PubnubUnitTest unitTest = new PubnubUnitTest();

            unitTest.TestClassName = "WhenSubscribedToAChannel";
            unitTest.TestCaseName  = "ThenSubscribeShouldReturnConnectStatus";

            pubnub.PubnubUnitTest = unitTest;

            string channel = "hello_my_channel";

            EnqueueCallback(() => pubnub.Subscribe <string>(channel, ReceivedMessageCallbackYesConnect, ConnectStatusCallback, DummyErrorCallback));
            EnqueueConditional(() => receivedConnectMessage);

            EnqueueCallback(() => pubnub.EndPendingRequests());
            EnqueueCallback(() => Thread.Sleep(200));

            EnqueueCallback(() => Assert.IsTrue(receivedConnectMessage, "WhenSubscribedToAChannel --> ThenSubscribeShouldReturnConnectStatus Failed"));
            EnqueueTestComplete();
        }
Exemplo n.º 20
0
        public void ThenSubscribeShouldReturnReceivedMessage()
        {
            receivedSubscribeMessage = false;
            Pubnub pubnub = new Pubnub("demo", "demo", "", "", false);

            string         channel  = "hello_my_channel";
            PubnubUnitTest unitTest = new PubnubUnitTest();

            unitTest.TestClassName = "WhenSubscribedToAChannel";
            unitTest.TestCaseName  = "ThenSubscribeShouldReturnReceivedMessage";
            pubnub.PubnubUnitTest  = unitTest;

            EnqueueCallback(() => pubnub.Subscribe <string>(channel, ReceivedMessageCallbackWhenSubscribed, SubscribeDummyMethodForConnectCallback, DummyErrorCallback));
            EnqueueConditional(() => receivedSubscribeMessage);
            //EnqueueConditional(() => subscribeConnected);
            EnqueueCallback(() => pubnub.Publish <string>(channel, "Test for WhenSubscribedToAChannel ThenItShouldReturnReceivedMessage", dummyPublishCallback, DummyErrorCallback));
            EnqueueConditional(() => publishInCallback);
            //EnqueueConditional(() => receivedMessageInCallback);
            EnqueueCallback(() => pubnub.EndPendingRequests());
            EnqueueCallback(() => Assert.IsTrue(receivedSubscribeMessage, "WhenSubscribedToAChannel --> ThenItShouldReturnReceivedMessage Failed"));

            EnqueueTestComplete();
        }
Exemplo n.º 21
0
        public void ThenOptionalSecretKeyShouldBeProvidedInConstructor()
        {
            isPublished2 = false;
            mrePublish   = new ManualResetEvent(false);

            ThreadPool.QueueUserWorkItem((s) =>
            {
                Pubnub pubnub  = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "key");
                string channel = "hello_my_channel";
                string message = "Pubnub API Usage Example";

                PubnubUnitTest unitTest = new PubnubUnitTest();
                unitTest.TestClassName  = "WhenAMessageIsPublished";
                unitTest.TestCaseName   = "ThenOptionalSecretKeyShouldBeProvidedInConstructor";
                pubnub.PubnubUnitTest   = unitTest;

                EnqueueCallback(() => pubnub.Publish <string>(channel, message, ReturnSecretKeyPublishCallback, DummyErrorCallback));
                mrePublish.WaitOne(310 * 1000);
                EnqueueCallback(() => Assert.IsTrue(isPublished2, "Publish Failed with secret key"));

                EnqueueTestComplete();
            });
        }
Exemplo n.º 22
0
        public void IfSSLNotProvidedThenDefaultShouldBeFalse()
        {
            isPublished3 = false;
            mrePublish   = new ManualResetEvent(false);

            ThreadPool.QueueUserWorkItem((s) =>
            {
                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;

                EnqueueCallback(() => pubnub.Publish <string>(channel, message, ReturnNoSSLDefaultFalseCallback, DummyErrorCallback));
                mrePublish.WaitOne(310 * 1000);
                EnqueueCallback(() => Assert.IsTrue(isPublished3, "Publish Failed with no SSL"));

                EnqueueTestComplete();
            });
        }
Exemplo n.º 23
0
        public void ThenPresenceShouldReturnReceivedMessage()
        {
            receivedPresenceMessage = false;

            Pubnub pubnub  = new Pubnub("demo", "demo", "", "", false);
            string channel = "hello_my_channel";

            PubnubUnitTest unitTest = new PubnubUnitTest();

            unitTest.TestClassName = "WhenAClientIsPresented";
            unitTest.TestCaseName  = "ThenPresenceShouldReturnReceivedMessage";
            pubnub.PubnubUnitTest  = unitTest;

            EnqueueCallback(() => pubnub.Presence <string>(channel, ThenPresenceShouldReturnMessage, PresenceDummyMethodForConnectCallback, DummyErrorCallback));
            EnqueueCallback(() => pubnub.Subscribe <string>(channel, DummyMethodForSubscribe, SubscribeDummyMethodForConnectCallback, DummyErrorCallback));
            EnqueueConditional(() => subscribeConnectStatusCallbackInvoked);
            EnqueueConditional(() => subscribeCallbackInvoked);
            EnqueueCallback(() => pubnub.EndPendingRequests());
            EnqueueConditional(() => presenceReturnMessageCallbackInvoked);
            EnqueueCallback(() => Assert.IsTrue(receivedPresenceMessage, "Presence message not received"));

            EnqueueTestComplete();
        }
Exemplo n.º 24
0
        public void ThenLargeMessageShoudFailWithMessageTooLargeInfo()
        {
            isLargeMessagePublished = false;
            mrePublish = new ManualResetEvent(false);

            ThreadPool.QueueUserWorkItem((s) =>
            {
                Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", true);

                PubnubUnitTest unitTest = new PubnubUnitTest();
                unitTest.TestClassName  = "WhenAMessageIsPublished";
                unitTest.TestCaseName   = "ThenLargeMessageShoudFailWithMessageTooLargeInfo";
                pubnub.PubnubUnitTest   = unitTest;

                string channel = "hello_my_channel";
                string message = messageLarge2K.Substring(0, 1320);
                EnqueueCallback(() => pubnub.Publish <string>(channel, message, DummyPublishMessageTooLargeInfoCallback, PublishMessageTooLargeErrorCallback));
                mrePublish.WaitOne(310 * 100);
                EnqueueCallback(() => Assert.IsTrue(isLargeMessagePublished, "Message Too Large is not failing as expected."));

                EnqueueTestComplete();
            });
        }
Exemplo n.º 25
0
        public void ThenShouldReturnUnsubscribedMessage()
        {
            receivedChannelConnectedMessage = false;
            receivedUnsubscribedMessage     = false;

            mreSubscribe   = new ManualResetEvent(false);
            mreUnsubscribe = new ManualResetEvent(false);

            ThreadPool.QueueUserWorkItem((s) =>
            {
                Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", false);

                PubnubUnitTest unitTest = new PubnubUnitTest();
                unitTest.TestClassName  = "WhenUnsubscribedToAChannel";
                unitTest.TestCaseName   = "ThenShouldReturnUnsubscribedMessage";

                pubnub.PubnubUnitTest = unitTest;

                string channel = "hello_my_channel";

                EnqueueCallback(() => pubnub.Subscribe <string>(channel, DummyMethodChannelSubscribeUserCallback, DummyMethodChannelSubscribeConnectCallback, DummyErrorCallback));
                mreSubscribe.WaitOne(310 * 1000);

                EnqueueCallback(() => pubnub.Unsubscribe <string>(channel, DummyMethodUnsubscribeChannelUserCallback, DummyMethodUnsubscribeChannelConnectCallback, DummyMethodUnsubscribeChannelDisconnectCallback, DummyErrorCallback));
                mreUnsubscribe.WaitOne(310 * 1000);

                EnqueueCallback(() => pubnub.EndPendingRequests());
                EnqueueCallback(() => Assert.IsTrue(receivedChannelConnectedMessage && receivedUnsubscribedMessage, "WhenUnsubscribedToAChannel --> ThenShouldReturnUnsubscribedMessage Failed"));
                EnqueueCallback(() =>
                {
                    pubnub.PubnubUnitTest = null;
                    pubnub = null;
                }
                                );
                EnqueueTestComplete();
            });
        }
Exemplo n.º 26
0
        public void ThenSubscribeShouldReturnReceivedMessage()
        {
            receivedSubscribeMessage = false;
            mreConnect   = new ManualResetEvent(false);
            mreSubscribe = new ManualResetEvent(false);
            mrePublish   = 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;

                EnqueueCallback(() => pubnub.Subscribe <string>(channel, ReceivedMessageCallbackWhenSubscribed, SubscribeDummyMethodForConnectCallback, DummyErrorCallback));
                mreConnect.WaitOne(310 * 1000);

                EnqueueCallback(() => pubnub.Publish <string>(channel, "Test for WhenSubscribedToAChannel ThenItShouldReturnReceivedMessage", dummyPublishCallback, DummyErrorCallback));
                mrePublish.WaitOne(310 * 1000);

                mreSubscribe.WaitOne(310 * 1000);

                EnqueueCallback(() => pubnub.EndPendingRequests());
                EnqueueCallback(() => Assert.IsTrue(receivedSubscribeMessage, "WhenSubscribedToAChannel --> ThenItShouldReturnReceivedMessage Failed"));

                EnqueueCallback(() =>
                {
                    pubnub.PubnubUnitTest = null;
                    pubnub = null;
                }
                                );
                EnqueueTestComplete();
            });
        }
Exemplo n.º 27
0
        public void ThenDisableJsonEncodeShouldSendSerializedObjectMessage()
        {
            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 = "hello_my_channel";
            object message = "{\"operation\":\"ReturnData\",\"channel\":\"Mobile1\",\"sequenceNumber\":0,\"data\":[\"ping 1.0.0.1\"]}";

            serializedObjectMessageForPublish = message.ToString();

            EnqueueCallback(() => pubnub.Publish <string>(channel, message, ReturnSuccessSerializedObjectMessageForPublishCallback, DummyErrorCallback));
            EnqueueConditional(() => isSerializedObjectMessageCheck);

            EnqueueCallback(() =>
            {
                if (!isSerializedObjectMessagePublished)
                {
                    EnqueueCallback(() => Assert.IsTrue(isSerializedObjectMessagePublished, "Serialized Object Message Publish Failed"));
                }
                else
                {
                    EnqueueCallback(() => pubnub.DetailedHistory <string>(channel, -1, serializedMessagePublishTimetoken, -1, false, CaptureSerializedMessagePublishDetailedHistoryCallback, DummyErrorCallback));
                    EnqueueConditional(() => isSerializedMessageDetailedHistoryCheck);
                    EnqueueCallback(() => Assert.IsTrue(isSerializedObjectMessageDetailedHistory, "Unable to match the successful serialized object message Publish"));
                }
            });

            EnqueueTestComplete();
        }
Exemplo n.º 28
0
        public void ThenSecretKeyWithEncryptPublishShouldReturnSuccessCodeAndInfo()
        {
            isSecretEncryptPublished = false;
            mrePublish         = new ManualResetEvent(false);
            mreDetailedHistory = new ManualResetEvent(false);

            ThreadPool.QueueUserWorkItem((s) =>
            {
                Pubnub pubnub  = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "key", "enigma", false);
                string channel = "hello_my_channel";
                string message = messageForSecretEncryptPublish;

                PubnubUnitTest unitTest = new PubnubUnitTest();
                unitTest.TestClassName  = "WhenAMessageIsPublished";
                unitTest.TestCaseName   = "ThenSecretKeyWithEncryptPublishShouldReturnSuccessCodeAndInfo";
                pubnub.PubnubUnitTest   = unitTest;

                EnqueueCallback(() => pubnub.Publish <string>(channel, message, ReturnSuccessSecretEncryptPublishCodeCallback, DummyErrorCallback));
                mrePublish.WaitOne(310 * 1000);

                EnqueueCallback(() =>
                {
                    if (!isSecretEncryptPublished)
                    {
                        Assert.IsTrue(isSecretEncryptPublished, "Secret Encrypt Publish Failed");
                    }
                    else
                    {
                        pubnub.DetailedHistory <string>(channel, -1, secretEncryptPublishTimetoken, -1, false, CaptureSecretEncryptDetailedHistoryCallback, DummyErrorCallback);
                        mreDetailedHistory.WaitOne(310 * 1000);
                        Assert.IsTrue(isSecretEncryptDH, "Unable to decrypt the successful Secret key Publish");
                    }
                });

                EnqueueTestComplete();
            });
        }
Exemplo n.º 29
0
        public void IfGlobalHereNowIsCalledThenItShouldReturnInfo()
        {
            mrePresence = new ManualResetEvent(false);

            ThreadPool.QueueUserWorkItem((s) =>
            {
                Pubnub pubnub           = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", false);
                PubnubUnitTest unitTest = new PubnubUnitTest();
                unitTest.TestClassName  = "WhenAClientIsPresented";
                unitTest.TestCaseName   = "IfGlobalHereNowIsCalledThenItShouldReturnInfo";
                pubnub.PubnubUnitTest   = unitTest;

                EnqueueCallback(() => pubnub.GlobalHereNow <string>(true, true, ThenGlobalHereNowShouldReturnMessage, DummyErrorCallback));
                mrePresence.WaitOne(310 * 1000);
                EnqueueCallback(() => Assert.IsTrue(receivedGlobalHereNowMessage, "global_here_now message not received"));
                EnqueueCallback(() =>
                {
                    pubnub.PubnubUnitTest = null;
                    pubnub = null;
                }
                                );
                EnqueueTestComplete();
            });
        }
Exemplo n.º 30
0
        public void ThenItShouldReturnTimeStamp()
        {
            mreTime = new ManualResetEvent(false);

            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;

                EnqueueCallback(() => pubnub.Time <string>(ReturnTimeStampCallback, DummyErrorCallback));
                mreTime.WaitOne(310 * 1000);
                EnqueueCallback(() => Assert.IsTrue(timeReceived, "time() Failed"));
                EnqueueCallback(() =>
                {
                    pubnub.PubnubUnitTest = null;
                    pubnub = null;
                }
                                );
                EnqueueTestComplete();
            });
        }
Exemplo n.º 31
0
        public void ThenPresenceShouldReturnReceivedMessage()
        {
            receivedPresenceMessage = false;
            mrePresence             = 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  = "WhenAClientIsPresented";
                unitTest.TestCaseName   = "ThenPresenceShouldReturnReceivedMessage";
                pubnub.PubnubUnitTest   = unitTest;

                EnqueueCallback(() => pubnub.Presence <string>(channel, ThenPresenceShouldReturnMessage, PresenceDummyMethodForConnectCallback, DummyErrorCallback));
                EnqueueCallback(() => pubnub.Subscribe <string>(channel, DummyMethodForSubscribe, SubscribeDummyMethodForConnectCallback, DummyErrorCallback));

                mrePresence.WaitOne(310 * 1000);
                EnqueueCallback(() => pubnub.EndPendingRequests());
                EnqueueCallback(() => Assert.IsTrue(receivedPresenceMessage, "Presence message not received"));
                EnqueueTestComplete();
            });
        }
        public void IfGlobalHereNowIsCalledThenItShouldReturnInfo()
        {
            mrePresence = new ManualResetEvent(false);

            ThreadPool.QueueUserWorkItem((s) =>
                {
                    Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", false);
                    PubnubUnitTest unitTest = new PubnubUnitTest();
                    unitTest.TestClassName = "WhenAClientIsPresented";
                    unitTest.TestCaseName = "IfGlobalHereNowIsCalledThenItShouldReturnInfo";
                    pubnub.PubnubUnitTest = unitTest;

                    EnqueueCallback(() => pubnub.GlobalHereNow<string>(true, true, ThenGlobalHereNowShouldReturnMessage, DummyErrorCallback));
                    mrePresence.WaitOne(310 * 1000);
                    EnqueueCallback(() => Assert.IsTrue(receivedGlobalHereNowMessage, "global_here_now message not received"));
                    EnqueueCallback(() =>
                            {
                                pubnub.PubnubUnitTest = null;
                                pubnub = null;
                            }
                        );
                    EnqueueTestComplete();
                });
        }
Exemplo n.º 33
0
        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);
                EnqueueCallback(() => pubnub.AddChannelsToChannelGroup <string>(new string[] { channelName1 }, channelGroupName1, ChannelGroupAddCallback, DummySubscribeErrorCallback));
                Thread.Sleep(1000);
                subscribeManualEvent.WaitOne(manualResetEventsWaitTimeout);

                subscribeManualEvent = new ManualResetEvent(false);
                EnqueueCallback(() => pubnub.AddChannelsToChannelGroup <string>(new string[] { channelName2 }, channelGroupName2, ChannelGroupAddCallback, DummySubscribeErrorCallback));
                Thread.Sleep(1000);
                subscribeManualEvent.WaitOne(manualResetEventsWaitTimeout);

                if (receivedChannelGroupMessage1 && receivedChannelGroupMessage2)
                {
                    subscribeManualEvent = new ManualResetEvent(false);
                    EnqueueCallback(() => pubnub.Subscribe <string>("", string.Format("{0},{1}", channelGroupName1, channelGroupName2), ReceivedMessageCallbackWhenSubscribed, SubscribeConnectCallback, DummySubscribeErrorCallback));
                    subscribeManualEvent.WaitOne(manualResetEventsWaitTimeout);

                    EnqueueCallback(() => pubnub.EndPendingRequests());

                    EnqueueCallback(() => Assert.IsTrue(receivedMessage, "WhenSubscribedToAChannelGroup --> ThenMultiSubscribeShouldReturnConnectStatusFailed. Subscribe failed"));
                }
                else
                {
                    EnqueueCallback(() => Assert.IsTrue(receivedChannelGroupMessage1 && receivedChannelGroupMessage2, "WhenSubscribedToAChannelGroup --> ThenMultiSubscribeShouldReturnConnectStatusFailed. May be add channel failed."));
                }
                EnqueueCallback(() =>
                {
                    pubnub.PubnubUnitTest = null;
                    pubnub = null;
                }
                                );
                EnqueueTestComplete();
            });
        }
        public void ThenMultipleAuthGrantShouldReturnSuccess()
        {
            currentUnitTestCase = "ThenMultipleAuthGrantShouldReturnSuccess";

            receivedGrantMessage = false;
            mreGrant = new ManualResetEvent(false);

            ThreadPool.QueueUserWorkItem((s) =>
                {
                    Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, PubnubCommon.SecretKey, "", false);

                    PubnubUnitTest unitTest = new PubnubUnitTest();
                    unitTest.TestClassName = "WhenGrantIsRequested";
                    unitTest.TestCaseName = "ThenMultipleAuthGrantShouldReturnSuccess";
                    pubnub.PubnubUnitTest = unitTest;

                    StringBuilder authKeyBuilder = new StringBuilder();
                    for (int index = 0; index < multipleAuthGrantCount; index++)
                    {
                        if (index == multipleAuthGrantCount - 1)
                        {
                            authKeyBuilder.AppendFormat("csharp-auth_key-{0}", index);
                        }
                        else
                        {
                            authKeyBuilder.AppendFormat("csharp-auth_key-{0},", index);
                        }
                    }
                    string channel = "hello_my_channel";
                    string auth = "";
                    if (!unitTest.EnableStubTest)
                    {
                        auth = authKeyBuilder.ToString();
                    }
                    else
                    {
                        multipleAuthGrantCount = 5;
                        auth = "csharp-auth_key-0,csharp-auth_key-1,csharp-auth_key-2,csharp-auth_key-3,csharp-auth_key-4";
                    }
                    if (PubnubCommon.PAMEnabled)
                    {
                        pubnub.AuthenticationKey = auth;
                        EnqueueCallback(() => pubnub.GrantAccess<string>(channel, true, true, 5, AccessToMultiAuthGrantCallback, DummyErrorCallback));
                        mreGrant.WaitOne(310 * 1000);

                        EnqueueCallback(() => Assert.IsTrue(receivedGrantMessage, "WhenGrantIsRequested -> ThenMultipleAuthGrantShouldReturnSuccess failed."));
                    }
                    else
                    {
                        EnqueueCallback(() => Assert.Inconclusive("PAM Not Enabled for WhenGrantIsRequested -> ThenMultipleAuthGrantShouldReturnSuccess."));
                    }
                    EnqueueTestComplete();
                });
        }
        public void ThenRevokeAtUserLevelReturnSuccess()
        {
            currentUnitTestCase = "ThenRevokeAtUserLevelReturnSuccess";

            receivedGrantMessage = false;
            receivedRevokeMessage = false;

            mreGrant = new ManualResetEvent(false);

            ThreadPool.QueueUserWorkItem((s) =>
                {
                    Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, PubnubCommon.SecretKey, "", false);

                    PubnubUnitTest unitTest = new PubnubUnitTest();
                    unitTest.TestClassName = "WhenGrantIsRequested";
                    unitTest.TestCaseName = "ThenRevokeAtUserLevelReturnSuccess";
                    pubnub.PubnubUnitTest = unitTest;

                    string channel = "hello_my_authchannel";
                    string authKey = "hello_my_authkey";
                    if (PubnubCommon.PAMEnabled)
                    {
                        if (!unitTest.EnableStubTest)
                        {
                            pubnub.AuthenticationKey = authKey;
                            EnqueueCallback(() => pubnub.GrantAccess<string>(channel, true, true, 5, AccessToUserLevelCallback, DummyErrorCallback));
                            mreGrant.WaitOne(310 * 1000);
                        }
                        else
                        {
                            receivedGrantMessage = true;
                        }
                        if (receivedGrantMessage)
                        {
                            mreGrant = new ManualResetEvent(false);
                            EnqueueCallback(() => pubnub.GrantAccess<string>("", false, false, 5, RevokeToUserLevelCallback, DummyErrorCallback));
                            mreGrant.WaitOne(310 * 1000);
                            
                            EnqueueCallback(() => Assert.IsTrue(receivedRevokeMessage, "WhenGrantIsRequested -> ThenRevokeAtUserLevelReturnSuccess -> Grant success but revoke failed."));
                        }
                        else
                        {
                            EnqueueCallback(() => Assert.IsTrue(receivedGrantMessage, "WhenGrantIsRequested -> ThenRevokeAtUserLevelReturnSuccess failed. -> Grant not occured, so is revoke"));
                        }
                    }
                    else
                    {
                        EnqueueCallback(() => Assert.Inconclusive("PAM Not Enabled for WhenGrantIsRequested -> ThenRevokeAtUserLevelReturnSuccess."));
                    }
                    EnqueueTestComplete();
                });
        }
        public void DetailedHistoryStartWithReverseTrue()
        {
            expectedCountAtStartTimeWithReverseTrue = 0;
            messageStartReverseTrue = false;
            Pubnub pubnub = new Pubnub("demo", "demo", "", "", false);

            PubnubUnitTest unitTest = new PubnubUnitTest();
            unitTest.TestClassName = "WhenDetailedHistoryIsRequested";
            unitTest.TestCaseName = "DetailedHistoryStartWithReverseTrue";
            pubnub.PubnubUnitTest = unitTest;

            string channel = "my/channel";
            startTimeWithReverseTrue = Pubnub.TranslateDateTimeToPubnubUnixNanoSeconds(DateTime.UtcNow);

            EnqueueCallback(() =>
            {
                for (int index = 0; index < 10; index++)
                {
                    pubnub.Publish<string>(channel,
                                        string.Format("DetailedHistoryStartTimeWithReverseTrue {0}", index),
                                        DetailedHistorySamplePublishCallback);
                    Thread.Sleep(100);
                    EnqueueConditional(() => detailedHistoryPublishCallbackInvoked);
                }
            });

            EnqueueCallback(() => pubnub.DetailedHistory<string>(channel, startTimeWithReverseTrue, DetailedHistoryStartWithReverseTrueCallback, true));
            EnqueueConditional(() => isDetailedHistoryStartReverseTrue);
            EnqueueCallback(() => Assert.IsTrue(messageStartReverseTrue, "Detailed History with Start and Reverse True Failed"));

            EnqueueTestComplete();
        }
        public void IfSSLNotProvidedThenDefaultShouldBeFalse()
        {
            isPublished3 = false;
            mrePublish = new ManualResetEvent(false);

            ThreadPool.QueueUserWorkItem((s) =>
                {
                    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;

                    EnqueueCallback(() => pubnub.Publish<string>(channel, message, ReturnNoSSLDefaultFalseCallback, DummyPublishErrorCallback));
                    mrePublish.WaitOne(310 * 1000);
                    EnqueueCallback(() => Assert.IsTrue(isPublished3, "Publish Failed with no SSL"));

                    EnqueueCallback(() =>
                            {
                                pubnub.PubnubUnitTest = null;
                                pubnub = null;
                            }
                        );
                    EnqueueTestComplete();
                });
        }
Exemplo n.º 38
0
        public void ThenPresenceShouldReturnCustomUUID()
        {
            receivedCustomUUID = false;
            mrePresence = new ManualResetEvent(false);
            ThreadPool.QueueUserWorkItem((s) =>
                {
                    Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", false);

                    PubnubUnitTest unitTest = new PubnubUnitTest();
                    unitTest.TestClassName = "WhenAClientIsPresented";
                    unitTest.TestCaseName = "ThenPresenceShouldReturnCustomUUID";
                    pubnub.PubnubUnitTest = unitTest;

                    pubnub.SessionUUID = customUUID;

                    string channel = "hello_my_channel";

                    EnqueueCallback(() => pubnub.Presence<string>(channel, ThenPresenceWithCustomUUIDShouldReturnMessage, PresenceUUIDDummyMethodForConnectCallback, DummyErrorCallback));

                    //since presence expects from stimulus from sub/unsub...
                    EnqueueCallback(() =>
                    {
                        pubnub.Subscribe<string>(channel, DummyMethodForSubscribeUUID, SubscribeUUIDDummyMethodForConnectCallback, DummyErrorCallback);
                    });
                    mrePresence.WaitOne(310 * 1000);
                    EnqueueCallback(() => pubnub.EndPendingRequests());
                    EnqueueCallback(() => Assert.IsTrue(receivedCustomUUID, "Custom UUID not received"));
                    EnqueueTestComplete();
                });
        }
        public void ThenDisableJsonEncodeShouldSendSerializedObjectMessage()
        {
            isSerializedObjectMessagePublished = false;
            mrePublish = new ManualResetEvent(false);
            mreDetailedHistory = new ManualResetEvent(false);

            ThreadPool.QueueUserWorkItem((s) =>
                {
                    Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", false);
                    pubnub.EnableJsonEncodingForPublish = false;

                    PubnubUnitTest unitTest = new PubnubUnitTest();
                    unitTest.TestClassName = "WhenAMessageIsPublished";
                    unitTest.TestCaseName = "ThenDisableJsonEncodeShouldSendSerializedObjectMessage";
                    pubnub.PubnubUnitTest = unitTest;

                    string channel = "hello_my_channel";
                    object message = "{\"operation\":\"ReturnData\",\"channel\":\"Mobile1\",\"sequenceNumber\":0,\"data\":[\"ping 1.0.0.1\"]}";
                    serializedObjectMessageForPublish = message.ToString();

                    EnqueueCallback(() => pubnub.Publish<string>(channel, message, ReturnSuccessSerializedObjectMessageForPublishCallback, DummyPublishErrorCallback));
                    mrePublish.WaitOne(310 * 1000);

                    EnqueueCallback(() =>
                        {
                            if (!isSerializedObjectMessagePublished)
                            {
                                EnqueueCallback(() => Assert.IsTrue(isSerializedObjectMessagePublished, "Serialized Object Message Publish Failed"));
                            }
                            else
                            {
                                Thread.Sleep(1000); //Adding 1 sec wait because sometimes I am getting empty array from server
                                pubnub.DetailedHistory<string>(channel, -1, serializedMessagePublishTimetoken, -1, false, CaptureSerializedMessagePublishDetailedHistoryCallback, DummyDetailedHistoryErrorCallback);
                                mreDetailedHistory.WaitOne(310 * 1000);
                                Assert.IsTrue(isSerializedObjectMessageDetailedHistory, "Unable to match the successful serialized object message Publish");
                            }
                        });

                    EnqueueCallback(() =>
                            {
                                pubnub.PubnubUnitTest = null;
                                pubnub = null;
                            }
                        );
                    EnqueueTestComplete();
                });
        }
Exemplo n.º 40
0
        public void ThenPresenceShouldReturnReceivedMessage()
        {
            receivedPresenceMessage = false;
            mrePresence = 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 = "WhenAClientIsPresented";
                    unitTest.TestCaseName = "ThenPresenceShouldReturnReceivedMessage";
                    pubnub.PubnubUnitTest = unitTest;

                    EnqueueCallback(() => pubnub.Presence<string>(channel, ThenPresenceShouldReturnMessage, PresenceDummyMethodForConnectCallback, DummyErrorCallback));
                    EnqueueCallback(() => pubnub.Subscribe<string>(channel, DummyMethodForSubscribe, SubscribeDummyMethodForConnectCallback, DummyErrorCallback));

                    mrePresence.WaitOne(310 * 1000);
                    EnqueueCallback(() => pubnub.EndPendingRequests());
                    EnqueueCallback(() => Assert.IsTrue(receivedPresenceMessage, "Presence message not received"));
                    EnqueueTestComplete();
                    
                });
        }
        //[TestMethod, Asynchronous] This test case is commented because Silverlight do not support URL length > 2050 encoded characters
        public void ThenLargeMessageShoudFailWithMessageTooLargeInfo()
        {
            isLargeMessagePublished = false;
            mrePublish = new ManualResetEvent(false);

            ThreadPool.QueueUserWorkItem((s) =>
                {
                    Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", true);

                    PubnubUnitTest unitTest = new PubnubUnitTest();
                    unitTest.TestClassName = "WhenAMessageIsPublished";
                    unitTest.TestCaseName = "ThenLargeMessageShoudFailWithMessageTooLargeInfo";
                    pubnub.PubnubUnitTest = unitTest;

                    string channel = "hello_my_channel";
                    //NOTE: Eventhough Pubnub Server allows 32K characters, Silverlight allows max 2050 characters after encoding including http or https
                    string message = messageLarge32K.Substring(0, 1432);
                    EnqueueCallback(() => pubnub.Publish<string>(channel, message, DummyPublishMessageTooLargeInfoCallback, PublishMessageTooLargeErrorCallback));
                    mrePublish.WaitOne(310 * 100);
                    EnqueueCallback(() => Assert.IsTrue(isLargeMessagePublished, "Message Too Large is not failing as expected."));

                    EnqueueCallback(() =>
                            {
                                pubnub.PubnubUnitTest = null;
                                pubnub = null;
                            }
                        );
                    EnqueueTestComplete();
                });
        }
Exemplo n.º 42
0
        public void ThenPublishMpnsToastShouldReturnSuccess()
        {
            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 = "ThenPublishMpnsToastShouldReturnSuccess";
                pubnub.PubnubUnitTest = unitTest;

                mrePublish = new ManualResetEvent(false);

                MpnsToastNotification toast = new MpnsToastNotification();
                toast.text1 = "hardcode message";
                Dictionary<string, object> dicToast = new Dictionary<string, object>();
                dicToast.Add("pn_mpns", toast);

                pubnub.EnableDebugForPushPublish = true;
                EnqueueCallback(() => pubnub.Publish<string>(channel, dicToast, PublishCallbackResult, DummyErrorCallback));
                mrePublish.WaitOne(60 * 1000);

                EnqueueCallback(() => Assert.IsTrue(receivedSuccessMessage, "Toast Publish Failed"));

                EnqueueCallback(() =>
                        {
                            pubnub.PubnubUnitTest = null;
                            pubnub = null;
                        }
                    );
                EnqueueTestComplete();
            });
        }
        public void ThenUnencryptPublishShouldReturnSuccessCodeAndInfo()
        {
            isUnencryptPublished = false;
            mrePublish = new ManualResetEvent(false);
            mreDetailedHistory = new ManualResetEvent(false);

            ThreadPool.QueueUserWorkItem((s) =>
                {
                    Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", false);
                    string channel = "hello_my_channel";
                    string message = messageForUnencryptPublish;

                    PubnubUnitTest unitTest = new PubnubUnitTest();
                    unitTest.TestClassName = "WhenAMessageIsPublished";
                    unitTest.TestCaseName = "ThenUnencryptPublishShouldReturnSuccessCodeAndInfo";
                    pubnub.PubnubUnitTest = unitTest;

                    EnqueueCallback(() => pubnub.Publish<string>(channel, message, ReturnSuccessUnencryptPublishCodeCallback, DummyPublishErrorCallback));
                    mrePublish.WaitOne(310 * 1000);

                    EnqueueCallback(() =>
                    {
                        if (!isUnencryptPublished)
                        {
                            Assert.IsTrue(isUnencryptPublished, "Unencrypt Publish Failed");
                        }
                        else
                        {
                            pubnub.DetailedHistory<string>(channel, -1, unEncryptPublishTimetoken, -1, false, CaptureUnencryptDetailedHistoryCallback, DummyDetailedHistoryErrorCallback);
                            mreDetailedHistory.WaitOne(310 * 1000);
                            Assert.IsTrue(isUnencryptDH, "Unable to match the successful unencrypt Publish");
                        }
                    });

                    EnqueueCallback(() =>
                            {
                                pubnub.PubnubUnitTest = null;
                                pubnub = null;
                            }
                        );
                    EnqueueTestComplete();
                });
        }
        public void ThenOptionalSecretKeyShouldBeProvidedInConstructor()
        {
            isPublished2 = false;
            mrePublish = new ManualResetEvent(false);

            ThreadPool.QueueUserWorkItem((s) =>
                {
                    Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "key");
                    string channel = "hello_my_channel";
                    string message = "Pubnub API Usage Example";

                    PubnubUnitTest unitTest = new PubnubUnitTest();
                    unitTest.TestClassName = "WhenAMessageIsPublished";
                    unitTest.TestCaseName = "ThenOptionalSecretKeyShouldBeProvidedInConstructor";
                    pubnub.PubnubUnitTest = unitTest;

                    EnqueueCallback(() => pubnub.Publish<string>(channel, message, ReturnSecretKeyPublishCallback, DummyPublishErrorCallback));
                    mrePublish.WaitOne(310 * 1000);
                    EnqueueCallback(() => Assert.IsTrue(isPublished2, "Publish Failed with secret key"));

                    EnqueueCallback(() =>
                            {
                                pubnub.PubnubUnitTest = null;
                                pubnub = null;
                            }
                        );
                    EnqueueTestComplete();
                });
        }