Ejemplo n.º 1
0
        public void AttachDetach()
        {
            ConsumedCapability GetCap(object obj) => ((Proxy)obj).ConsumedCap;

            var a        = new MyPolicy("a");
            var b        = new MyPolicy("b");
            var c        = new MyPolicy("c");
            var proxy    = Proxy.Share <ITestInterface>(new TestInterfaceImpl2());
            var attached = a.Attach(b.Attach(c.Attach(proxy)));

            Assert.AreEqual(GetCap(attached), GetCap(b.Attach(attached)));
            var detached = c.Detach(a.Detach(b.Detach(attached)));

            Assert.AreEqual(GetCap(proxy), GetCap(detached));
        }
Ejemplo n.º 2
0
        public void MultiAttachAndDetach()
        {
            var a = new MyPolicy("a");
            var b = new MyPolicy("b");
            var c = new MyPolicy("c");

            var counters = new Counters();
            var impl     = new TestInterfaceImpl(counters);

            var implA   = a.Attach <ITestInterface>(impl);
            var implAbc = b.Attach(a.Attach(b.Attach(c.Attach(implA))));
            var implAc  = b.Detach(implAbc);

            (var server, var client) = SetupClientServerPair();

            using (server)
                using (client)
                {
                    //client.WhenConnected.Wait();

                    server.Main = implAc;
                    using (var main = client.GetMain <ITestInterface>())
                    {
                        var foof = main.Foo(123, true);

                        var ccf1 = c.Calls.ReceiveAsync();
                        Assert.IsTrue(ccf1.Wait(MediumNonDbgTimeout));
                        var cc1 = ccf1.Result;
                        cc1.ForwardToBob();

                        var ccf2 = a.Calls.ReceiveAsync();
                        Assert.IsTrue(ccf2.Wait(MediumNonDbgTimeout));
                        var cc2 = ccf2.Result;
                        cc2.ForwardToBob();

                        Assert.IsTrue(a.Returns.ReceiveAsync().Wait(MediumNonDbgTimeout));
                        cc2.ReturnToAlice();

                        Assert.IsTrue(c.Returns.ReceiveAsync().Wait(MediumNonDbgTimeout));
                        cc1.ReturnToAlice();

                        Assert.IsTrue(foof.Wait(MediumNonDbgTimeout));
                    }
                }
        }