Пример #1
0
        public void IProxy()
        {
            var  proxyBuilder = new ForwardingProxyBuilder("IProxy", ModuleScope, typeof(Proxied), new Type[0]);
            Type proxyType    = proxyBuilder.BuildProxyType();

            var    proxied = new Proxied("AAA");
            object proxy   = Activator.CreateInstance(proxyType, proxied);

            Assert.That(ScriptingHelper.GetProxiedFieldValue(proxy), Is.SameAs(proxied));

            var proxied2 = new Proxied("BBB");

            ((IProxy)proxy).SetProxied(proxied2);

            Assert.That(ScriptingHelper.GetProxiedFieldValue(proxy), Is.SameAs(proxied2));
        }
Пример #2
0
        public void GetProxy_IsCachedAndProxiedIsSet()
        {
            var provider = new StableBindingProxyProvider(
                new TypeLevelTypeFilter(new[] { typeof(GetProxyTypeIsCachedTest) }), CreateModuleScope("GetProxy_IsCachedAndProxiedSet"));

            var proxied0 = new GetProxyTypeIsCachedTest("abrakadava");
            var proxied1 = new GetProxyTypeIsCachedTest("simsalsabum");

            var proxy0 = provider.GetProxy(proxied0);

            Assert.That(proxy0, Is.Not.Null);

            var proxiedFieldValue0 = ScriptingHelper.GetProxiedFieldValue(proxy0);

            Assert.That(proxiedFieldValue0, Is.SameAs(proxied0));
            var proxy1 = provider.GetProxy(proxied1);

            Assert.That(proxy0, Is.SameAs(proxy1));
            Assert.That(ScriptingHelper.GetProxiedFieldValue(proxy1), Is.SameAs(proxied1));
        }