Exemplo n.º 1
0
        public static List <ChannelEntity> CreateListOfChannelEntities(bool channelGroup, bool channel, bool presence, bool awaitingConnectCallback, PNLoggingMethod pnLog)
        {
            var dictSM = new Dictionary <string, object>();

            dictSM.Add("k", "v");
            dictSM.Add("k2", "v2");


            ChannelEntity ce1 = Helpers.CreateChannelEntity("ch1", false, false, dictSM, pnLog);

            var dictSM2 = new Dictionary <string, object>();

            dictSM2.Add("k3", "v3");
            dictSM2.Add("k4", "v4");

            ChannelEntity ce2 = Helpers.CreateChannelEntity("ch2", false, false, dictSM2, pnLog);

            var dictSM3 = new Dictionary <string, object>();

            dictSM3.Add("k5", "v5");
            dictSM3.Add("k6", "v6");

            ChannelEntity ce3 = Helpers.CreateChannelEntity("cg1", false, true, dictSM3, pnLog);

            var dictSM4 = new Dictionary <string, object>();

            dictSM4.Add("k7", "v7");
            dictSM4.Add("k8", "v8");

            ChannelEntity ce4 = Helpers.CreateChannelEntity("cg2", false, true, dictSM4, pnLog);

            var dictSM5 = new Dictionary <string, object>();

            dictSM5.Add("k7", "v7");
            dictSM5.Add("k8", "v8");

            ChannelEntity ce5 = Helpers.CreateChannelEntity("cg2-pnpres", false, true, dictSM5, pnLog);

            var dictSM6 = new Dictionary <string, object>();

            dictSM6.Add("k7", "v7");
            dictSM6.Add("k8", "v8");

            ChannelEntity ce6 = Helpers.CreateChannelEntity("ch2-pnpres", false, false, dictSM6, pnLog);

            var dictSM7 = new Dictionary <string, object>();

            dictSM7.Add("k7", "v7");
            dictSM7.Add("k8", "v8");

            ChannelEntity ce7 = Helpers.CreateChannelEntity("ch7", true, false, dictSM7, pnLog);

            var dictSM8 = new Dictionary <string, object>();

            dictSM8.Add("k7", "v7");
            dictSM8.Add("k8", "v8");

            ChannelEntity ce8 = Helpers.CreateChannelEntity("cg8", true, true, dictSM8, pnLog);

            List <ChannelEntity> lstCE = new List <ChannelEntity>();

            if (channel)
            {
                lstCE.Add(ce1);
                lstCE.Add(ce2);
                if (presence)
                {
                    lstCE.Add(ce6);
                }

                if (awaitingConnectCallback)
                {
                    lstCE.Add(ce7);
                }
            }
            if (channelGroup)
            {
                lstCE.Add(ce3);
                lstCE.Add(ce4);
                if (presence)
                {
                    lstCE.Add(ce5);
                }

                if (awaitingConnectCallback)
                {
                    lstCE.Add(ce8);
                }
            }
            return(lstCE);
        }
Exemplo n.º 2
0
        public void TestSubscription()
        {
            PNConfiguration pnConfiguration = new PNConfiguration();

            pnConfiguration.Origin           = EditorCommon.Origin;
            pnConfiguration.SubscribeKey     = EditorCommon.SubscribeKey;
            pnConfiguration.PublishKey       = EditorCommon.PublishKey;
            pnConfiguration.CipherKey        = "enigma";
            pnConfiguration.LogVerbosity     = PNLogVerbosity.BODY;
            pnConfiguration.PresenceTimeout  = 60;
            pnConfiguration.PresenceInterval = 30;
            PubNubUnity pnUnity = new PubNubUnity(pnConfiguration, null, null);

            pnUnity.SubscriptionInstance.CleanUp();
            PNLoggingMethod pnLog = new PNLoggingMethod(pnConfiguration.LogVerbosity);
            //Add CE with ch cg, ch-pres, cgpres, 2 awaiting connect callback with userstate
            List <ChannelEntity> channelEntities = EditorCommon.CreateListOfChannelEntities(true, true, true, true, pnLog);

            pnUnity.SubscriptionInstance.Add(channelEntities);

            // Test All
            RunAssertions(pnUnity, "{\"ch1\":{\"k\":\"v\",\"k2\":\"v2\"},\"ch2\":{\"k3\":\"v3\",\"k4\":\"v4\"},\"ch2-pnpres\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"ch7\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"cg1\":{\"k5\":\"v5\",\"k6\":\"v6\"},\"cg2\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"cg2-pnpres\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"cg8\":{\"k7\":\"v7\",\"k8\":\"v8\"}}",
                          false, true, true, true, true, 4, 4,
                          new string[] { "cg1", "cg2", "cg2-pnpres", "cg8" },
                          new string[] { "ch1", "ch2", "ch2-pnpres", "ch7" },
                          new string[] { "ch1", "ch2", "ch7", "cg1", "cg2", "cg8" },
                          new string[] { "cg2-pnpres", "ch2-pnpres" },
                          new string[] { "ch7", "cg8" },
                          new string[] { "ch1", "ch2", "ch2-pnpres", "ch7", "cg1", "cg2", "cg2-pnpres", "cg8" });


            // Delete 2
            ChannelEntity ce = Helpers.CreateChannelEntity("ch2", false, false, null, pnLog);

            pnUnity.SubscriptionInstance.Delete(ce);
            ChannelEntity ce2 = Helpers.CreateChannelEntity("cg2", false, true, null, pnLog);

            pnUnity.SubscriptionInstance.Delete(ce2);

            // Test All
            RunAssertions(pnUnity, "{\"ch1\":{\"k\":\"v\",\"k2\":\"v2\"},\"ch2-pnpres\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"ch7\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"cg1\":{\"k5\":\"v5\",\"k6\":\"v6\"},\"cg2-pnpres\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"cg8\":{\"k7\":\"v7\",\"k8\":\"v8\"}}",
                          false, true, true, true, true, 3, 3,
                          new string[] { "cg1", "cg2-pnpres", "cg8" },
                          new string[] { "ch1", "ch2-pnpres", "ch7" },
                          new string[] { "ch1", "ch7", "cg1", "cg8" },
                          new string[] { "cg2-pnpres", "ch2-pnpres" },
                          new string[] { "ch7", "cg8" },
                          new string[] { "ch1", "ch2-pnpres", "ch7", "cg1", "cg2-pnpres", "cg8" });


            // UpdateOrAddUserStateOfEntity
            ChannelEntity ce3     = Helpers.CreateChannelEntity("ch1", false, false, null, pnLog);
            var           dictSMN = new Dictionary <string, object>();

            dictSMN.Add("k", "v9");

            pnUnity.SubscriptionInstance.TryUpdateOrAddUserStateOfEntity(ref ce3, dictSMN, true);

            // Test All
            RunAssertions(pnUnity, "{\"ch1\":{\"k\":\"v9\",\"k2\":\"v2\"},\"ch2-pnpres\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"ch7\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"cg1\":{\"k5\":\"v5\",\"k6\":\"v6\"},\"cg2-pnpres\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"cg8\":{\"k7\":\"v7\",\"k8\":\"v8\"}}",
                          false, true, true, true, true, 3, 3,
                          new string[] { "cg1", "cg2-pnpres", "cg8" },
                          new string[] { "ch1", "ch2-pnpres", "ch7" },
                          new string[] { "ch1", "ch7", "cg1", "cg8" },
                          new string[] { "cg2-pnpres", "ch2-pnpres" },
                          new string[] { "ch7", "cg8" },
                          new string[] { "ch1", "ch2-pnpres", "ch7", "cg1", "cg2-pnpres", "cg8" });

            // UpdateIsAwaitingConnectCallbacksOfEntity
            ChannelEntity ce4 = Helpers.CreateChannelEntity("ch7", false, false, null, pnLog);
            ChannelEntity ce5 = Helpers.CreateChannelEntity("cg8", false, true, null, pnLog);

            List <ChannelEntity> lstCE = new List <ChannelEntity>();

            lstCE.Add(ce4);
            lstCE.Add(ce5);

            pnUnity.SubscriptionInstance.UpdateIsAwaitingConnectCallbacksOfEntity(lstCE, false);

            // Test All
            RunAssertions(pnUnity, "{\"ch1\":{\"k\":\"v9\",\"k2\":\"v2\"},\"ch2-pnpres\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"ch7\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"cg1\":{\"k5\":\"v5\",\"k6\":\"v6\"},\"cg2-pnpres\":{\"k7\":\"v7\",\"k8\":\"v8\"},\"cg8\":{\"k7\":\"v7\",\"k8\":\"v8\"}}",
                          true, true, true, true, true, 3, 3,
                          new string[] { "cg1", "cg2-pnpres", "cg8" },
                          new string[] { "ch1", "ch2-pnpres", "ch7" },
                          new string[] { "ch1", "ch7", "cg1", "cg8" },
                          new string[] { "cg2-pnpres", "ch2-pnpres" },
                          new string[] { "ch7", "cg8" },
                          new string[] { "ch1", "ch2-pnpres", "ch7", "cg1", "cg2-pnpres", "cg8" });

            // CleanUp
            pnUnity.SubscriptionInstance.CleanUp();

            // Test All

            RunAssertions(pnUnity, String.Empty,
                          false, false, false, false, false, 0, 0,
                          new string[] {},
                          new string[] {},
                          new string[] {},
                          new string[] {},
                          new string[] {},
                          new string[] {});
        }