예제 #1
0
        public void TestLateBind06()
        {
            var key = RdContextBasicTest.TestKeyHeavy.Instance;

            var serverMap = new RdPerContextMap <string, RdMap <int, string> >(key, _ => new RdMap <int, string>());
            var clientMap = new RdPerContextMap <string, RdMap <int, string> >(key, _ => new RdMap <int, string>());

            var server1Cid = "Server-1";

            var log = new List <string>();

            serverMap.View(LifetimeDefinition.Lifetime, (lifetime, s, _) =>
            {
                log.Add("Add " + s);
                lifetime.OnTermination(() => log.Add("Remove " + s));
            });

            key.RegisterOn(ClientProtocol.Serializers);
            ServerProtocol.Contexts.RegisterContext(key);
            ClientProtocol.Contexts.RegisterContext(key);

            BindToClient(LifetimeDefinition.Lifetime, clientMap, 1);
            BindToServer(LifetimeDefinition.Lifetime, serverMap, 1);

            key.Value = server1Cid;
            ServerProtocol.Wire.Send(RdId.Nil.Mix(10), _ => { });
            key.Value = null;

            Assert.True(ServerProtocol.Contexts.GetValueSet(key).Contains(server1Cid));

            Assert.AreEqual(new [] { "Add " + server1Cid }, log);
        }
예제 #2
0
        public void TestLateBind04()
        {
            var key = RdContextBasicTest.TestKeyHeavy.Instance;

            var serverMap = new RdPerContextMap <string, RdMap <int, string> >(key, _ => new RdMap <int, string>());
            var clientMap = new RdPerContextMap <string, RdMap <int, string> >(key, _ => new RdMap <int, string>());

            var server1Cid = "Server-1";
            var client1Cid = "Client-1";

            key.RegisterOn(ClientProtocol.Serializers);
            ServerProtocol.Contexts.RegisterContext(key);
            ClientProtocol.Contexts.RegisterContext(key);

            ServerProtocol.Contexts.GetValueSet(key).Add(server1Cid);

            var log = new List <string>();

            serverMap.View(LifetimeDefinition.Lifetime, (lifetime, s, _) =>
            {
                log.Add("Add " + s);
                lifetime.OnTermination(() => log.Add("Remove " + s));
            });

            serverMap[server1Cid][1] = "test";
            serverMap[client1Cid][1] = "test";

            BindToClient(LifetimeDefinition.Lifetime, clientMap, 1);
            BindToServer(LifetimeDefinition.Lifetime, serverMap, 1);

            Assert.AreEqual(new [] { "Add " + server1Cid, "Add " + client1Cid, "Remove " + client1Cid }, log);
        }
예제 #3
0
        public void TestValueSetChangesInContext()
        {
            var key1 = RdContextBasicTest.TestKeyHeavy.Instance;
            var key2 = RdContextBasicTest.TestKey2.Instance;

            var serverMap = new RdPerContextMap <string, RdMap <int, string> >(key1, _ => new RdMap <int, string>());
            var clientMap = new RdPerContextMap <string, RdMap <int, string> >(key1, _ => new RdMap <int, string>());

            var server1Cid = "Server-1";
            var server2Cid = "Server-2";
            var server3Cid = "Server-3";
            var server4Cid = "Server-4";

            var log = new List <string>();

            serverMap.View(LifetimeDefinition.Lifetime, (lifetime, s, _) =>
            {
                log.Add("Add " + s);
                lifetime.OnTermination(() => log.Add("Remove " + s));
            });

            key1.Value = server1Cid;
            key2.Value = server1Cid;

            key1.RegisterOn(ClientProtocol.Serializers);
            key2.RegisterOn(ClientProtocol.Serializers);
            ServerProtocol.Contexts.RegisterContext(key1);
            ServerProtocol.Contexts.RegisterContext(key2);
            ClientProtocol.Contexts.RegisterContext(key1);

            BindToClient(LifetimeDefinition.Lifetime, clientMap, 1);
            BindToServer(LifetimeDefinition.Lifetime, serverMap, 1);

            ServerProtocol.Contexts.GetValueSet(key1).Add(server2Cid);
            key1.Value = server4Cid;
            ServerProtocol.Contexts.GetValueSet(key1).Add(server3Cid);


            key1.Value = null;
            key2.Value = null;

            Assert.False(ServerProtocol.Contexts.GetValueSet(key1).Contains(server1Cid));
            Assert.False(ServerProtocol.Contexts.GetValueSet(key2).Contains(server1Cid));

            Assert.AreEqual(new [] { "Add " + server2Cid, "Add " + server3Cid }, log);
        }