Example #1
0
        public void TestBuildHereNowRequestCommon(bool testCh, bool testCg, bool ssl, bool showUUIDList, bool includeUserState, string authKey)
        {
            string channel         = "here_now_channel";
            string channelGroup    = "here_now_channelGroup";
            string channelGroupStr = string.Format("&channel-group={0}", Utility.EncodeUricomponent(channelGroup, PNOperationType.PNHereNowOperation, true, false));

            if (testCh && testCg)
            {
                // test both
            }
            else if (testCg)
            {
                channel = ",";
            }
            else
            {
                channelGroup    = "";
                channelGroupStr = "";
            }
            string uuid = "customuuid";

            PNConfiguration pnConfiguration = new PNConfiguration();

            pnConfiguration.Origin           = EditorCommon.Origin;
            pnConfiguration.SubscribeKey     = EditorCommon.SubscribeKey;
            pnConfiguration.PublishKey       = EditorCommon.PublishKey;
            pnConfiguration.Secure           = ssl;
            pnConfiguration.CipherKey        = "enigma";
            pnConfiguration.LogVerbosity     = PNLogVerbosity.BODY;
            pnConfiguration.PresenceTimeout  = 60;
            pnConfiguration.PresenceInterval = 30;
            pnConfiguration.UUID             = uuid;
            pnConfiguration.AuthKey          = authKey;

            PubNubUnity pnUnity = new PubNubUnity(pnConfiguration, null, null);

            string authKeyString = "";

            if (!string.IsNullOrEmpty(authKey))
            {
                authKeyString = string.Format("&auth={0}", pnConfiguration.AuthKey);
            }

            int    disableUUID = (showUUIDList) ? 0 : 1;
            int    userState   = (includeUserState) ? 1 : 0;
            string parameters  = string.Format("disable_uuids={0}&state={1}", disableUUID, userState);

            Uri uri = BuildRequests.BuildHereNowRequest(channel, channelGroup, showUUIDList, includeUserState, pnUnity);

            //http://ps.pndsn.com/v2/presence/sub_key/demo/channel/here_now_channel?disable_uuids=1&state=0&uuid=customuuid&auth=authKey&pnsdk=PubNub-CSharp-UnityOSX/3.6.9.0
            string expected = string.Format("http{0}://{1}/v2/presence/sub_key/{2}/channel/{3}?{4}{8}&uuid={5}{6}&pnsdk={7}",
                                            ssl?"s":"", pnConfiguration.Origin, EditorCommon.SubscribeKey, channel, parameters,
                                            uuid, authKeyString,
                                            Utility.EncodeUricomponent(pnUnity.Version, PNOperationType.PNHereNowOperation, false, true),
                                            channelGroupStr
                                            );
            string received = uri.OriginalString;

            EditorCommon.LogAndCompare(expected, received);
        }
Example #2
0
        public void TestBuildHereNowRequestCommon(bool testCh, bool testCg, bool ssl, bool showUUIDList, bool includeUserState, string authKey)
        {
            string channel         = "here_now_channel";
            string channelGroup    = "here_now_channelGroup";
            string channelGroupStr = string.Format("&channel-group={0}", Utility.EncodeUricomponent(channelGroup, ResponseType.HereNow, true, false));

            if (testCh && testCg)
            {
                // test both
            }
            else if (testCg)
            {
                channel = ",";
            }
            else
            {
                channelGroup    = "";
                channelGroupStr = "";
            }
            string uuid = "customuuid";

            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                "",
                "",
                ssl
                );

            pubnub.AuthenticationKey = authKey;
            string authKeyString = "";

            if (!string.IsNullOrEmpty(authKey))
            {
                authKeyString = string.Format("&auth={0}", pubnub.AuthenticationKey);
            }

            int    disableUUID = (showUUIDList) ? 0 : 1;
            int    userState   = (includeUserState) ? 1 : 0;
            string parameters  = string.Format("disable_uuids={0}&state={1}", disableUUID, userState);

            Uri uri = BuildRequests.BuildHereNowRequest(channel, channelGroup, showUUIDList, includeUserState,
                                                        uuid, ssl, pubnub.Origin, pubnub.AuthenticationKey, Common.SubscribeKey
                                                        );

            //http://ps.pndsn.com/v2/presence/sub_key/demo-36/channel/here_now_channel?disable_uuids=1&state=0&uuid=customuuid&auth=authKey&pnsdk=PubNub-CSharp-UnityOSX/3.6.9.0
            string expected = string.Format("http{0}://{1}/v2/presence/sub_key/{2}/channel/{3}?{4}{8}&uuid={5}{6}&pnsdk={7}",
                                            ssl?"s":"", pubnub.Origin, Common.SubscribeKey, channel, parameters,
                                            uuid, authKeyString,
                                            Utility.EncodeUricomponent(PubnubUnity.Version, ResponseType.HereNow, false, true),
                                            channelGroupStr
                                            );
            string received = uri.OriginalString;

            Common.LogAndCompare(expected, received);
        }
        public void TestBuildGlobalHereNowRequestCommon(bool ssl, bool showUUIDList, bool includeUserState, string authKey, bool sendQueryParams)
        {
            Dictionary <string, string> queryParams = new Dictionary <string, string>();
            string queryParamString = "";

            if (sendQueryParams)
            {
                queryParams.Add("d", "f");
                queryParamString = "&d=f";
            }
            else
            {
                queryParams = null;
            }
            string uuid = "customuuid";

            PNConfiguration pnConfiguration = new PNConfiguration();

            pnConfiguration.Origin           = EditorCommon.Origin;
            pnConfiguration.SubscribeKey     = EditorCommon.SubscribeKey;
            pnConfiguration.PublishKey       = EditorCommon.PublishKey;
            pnConfiguration.Secure           = ssl;
            pnConfiguration.CipherKey        = "enigma";
            pnConfiguration.LogVerbosity     = PNLogVerbosity.BODY;
            pnConfiguration.PresenceTimeout  = 60;
            pnConfiguration.PresenceInterval = 30;
            pnConfiguration.UUID             = uuid;
            pnConfiguration.AuthKey          = authKey;

            PubNubUnity pnUnity = new PubNubUnity(pnConfiguration, null, null);

            string authKeyString = "";

            if (!string.IsNullOrEmpty(authKey))
            {
                authKeyString = string.Format("&auth={0}", pnConfiguration.AuthKey);
            }

            int    disableUUID = (showUUIDList) ? 0 : 1;
            int    userState   = (includeUserState) ? 1 : 0;
            string parameters  = string.Format("disable_uuids={0}&state={1}", disableUUID, userState);

            Uri uri = BuildRequests.BuildHereNowRequest("", "", showUUIDList, includeUserState, pnUnity, queryParams);

            //http://ps.pndsn.com/v2/presence/sub_key/demo?disable_uuids=1&state=0&uuid=customuuid&auth=authKey&pnsdk=PubNub-CSharp-UnityOSX/3.6.9.0
            string expected = string.Format("http{0}://{1}/v2/presence/sub_key/{2}?{3}&uuid={4}{5}&pnsdk={6}{7}",
                                            ssl?"s":"", pnConfiguration.Origin, EditorCommon.SubscribeKey, parameters,
                                            uuid, authKeyString,
                                            Utility.EncodeUricomponent(pnUnity.Version, PNOperationType.PNHereNowOperation, false, true),
                                            queryParamString
                                            );
            string received = uri.OriginalString;

            EditorCommon.LogAndCompare(expected, received);
        }
        public void TestBuildHereNowRequestCommon(bool ssl, bool showUUIDList, bool includeUserState, string authKey)
        {
            string channel = "here_now_channel";
            string uuid    = "customuuid";

            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                "",
                "",
                ssl
                );

            pubnub.AuthenticationKey = authKey;
            string authKeyString = "";

            if (!string.IsNullOrEmpty(authKey))
            {
                authKeyString = string.Format("&auth={0}", pubnub.AuthenticationKey);
            }

            int    disableUUID = (showUUIDList) ? 0 : 1;
            int    userState   = (includeUserState) ? 1 : 0;
            string parameters  = string.Format("disable_uuids={0}&state={1}", disableUUID, userState);

            Uri uri = BuildRequests.BuildHereNowRequest(channel, showUUIDList, includeUserState,
                                                        uuid, ssl, pubnub.Origin, pubnub.AuthenticationKey, Common.SubscribeKey
                                                        );

            //http://pubsub.pubnub.com/v2/presence/sub_key/demo-36/channel/here_now_channel?disable_uuids=1&state=0&uuid=customuuid&auth=authKey&pnsdk=PubNub-CSharp-UnityOSX/3.6.9.0
            string expected = string.Format("http{0}://{1}/v2/presence/sub_key/{2}/channel/{3}?{4}&uuid={5}{6}&pnsdk={7}",
                                            ssl?"s":"", pubnub.Origin, Common.SubscribeKey, channel, parameters,
                                            uuid, authKeyString, PubnubUnity.Version
                                            );
            string received = uri.ToString();

            Common.LogAndCompare(expected, received);
        }