コード例 #1
0
        public void TestSubscriptionCommon <T>(Action <T> userCallback, Action <T> connectCallback,
                                               Action <T> wildcardPresenceCallback, Action <T> disconnectCallback)
        {
            Subscription.Instance.CleanUp();
            //Add CE with ch cg, ch-pres, cgpres, 2 awaiting connect callback with userstate
            List <ChannelEntity> channelEntities = Common.CreateListOfChannelEntities <T>(true, true, true, true,
                                                                                          userCallback, connectCallback,
                                                                                          wildcardPresenceCallback,
                                                                                          disconnectCallback
                                                                                          );

            Subscription.Instance.Add(channelEntities);

            // Test All
            RunAssertions("{\"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, userCallback,
                                                           connectCallback, Common.ErrorCallback, disconnectCallback, wildcardPresenceCallback
                                                           );

            Subscription.Instance.Delete(ce);
            ChannelEntity ce2 = Helpers.CreateChannelEntity("cg2", false, true, null, userCallback,
                                                            connectCallback, Common.ErrorCallback, disconnectCallback, wildcardPresenceCallback
                                                            );

            Subscription.Instance.Delete(ce2);

            // Test All
            RunAssertions("{\"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, userCallback,
                                                            connectCallback, Common.ErrorCallback, disconnectCallback, wildcardPresenceCallback
                                                            );
            var dictSMN = new Dictionary <string, object>();

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

            Subscription.Instance.UpdateOrAddUserStateOfEntity(ref ce3, dictSMN, true);

            // Test All
            RunAssertions("{\"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, userCallback,
                                                            connectCallback, Common.ErrorCallback, disconnectCallback, wildcardPresenceCallback
                                                            );
            ChannelEntity ce5 = Helpers.CreateChannelEntity("cg8", false, true, null, userCallback,
                                                            connectCallback, Common.ErrorCallback, disconnectCallback, wildcardPresenceCallback
                                                            );

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

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

            Subscription.Instance.UpdateIsAwaitingConnectCallbacksOfEntity(lstCE, false);

            // Test All
            RunAssertions("{\"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
            Subscription.Instance.CleanUp();

            // Test All

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