Esempio n. 1
0
        public void GetAttributeProxy_IsCached()
        {
            var provider = new StableBindingProxyProvider(
                new TypeLevelTypeFilter(new[] { typeof(ProxiedChild) }), CreateModuleScope("GetTypeMemberProxy"));

            var proxied0 = new ProxiedChildChildChild("ABCccccccccccccccccc");
            var proxied1 = new ProxiedChildChildChild("xyzzzzzzzzz");

            const string attributeName       = "PrependName";
            var          typeMemberProxy0    = provider.GetAttributeProxy(proxied0, attributeName);
            var          customMemberTester0 = new GetCustomMemberTester(typeMemberProxy0);
            var          result0             = ScriptingHelper.ExecuteScriptExpression <string> ("p0.XYZ('simsalbum',2)", customMemberTester0);

            Assert.That(result0, Is.EqualTo("ProxiedChild ProxiedChild: ABCccccccccccccccccc simsalbum, THE NUMBER=2"));


            var typeMemberProxy1 = provider.GetAttributeProxy(proxied1, attributeName);

            Assert.That(typeMemberProxy0, Is.SameAs(typeMemberProxy1));

            var customMemberTester1 = new GetCustomMemberTester(typeMemberProxy1);
            var result1             = ScriptingHelper.ExecuteScriptExpression <string> ("p0.ABCDEFG('Schlaf')", customMemberTester1);

            Assert.That(result1, Is.EqualTo("xyzzzzzzzzz Schlaf"));
        }
        public void BuildProxyType_AmbigousExplicitInterfaceProperties_With_PublicInterfaceImplementation()
        {
            var knownBaseTypes            = new[] { typeof(ProxiedChildChild) };
            var knownInterfaceTypes       = new[] { typeof(IProperty), typeof(IPropertyAmbigous2) };
            var knownTypes                = knownBaseTypes.Union(knownInterfaceTypes).ToArray();
            var typeFilter                = new TypeLevelTypeFilter(knownTypes);
            var proxiedType               = typeof(ProxiedChildChildChild);
            var stableBindingProxyBuilder = new StableBindingProxyBuilder(proxiedType, typeFilter, CreateModuleScope("BuildProxyType_ExplicitInterfaceProperty"));
            var proxyType = stableBindingProxyBuilder.BuildProxyType();

            Assert.That(proxyType.GetInterface("IPropertyAmbigous2"), Is.Not.Null);
            Assert.That(proxyType.GetInterface("IPropertyAmbigous1"), Is.Null);

            // Create proxy instance, initializing it with class to be proxied
            var proxied = new ProxiedChildChildChild("PC");

            object proxy = Activator.CreateInstance(proxyType, proxied);

            const string expectedPropertyValue = "ProxiedChildChild::IPropertyAmbigous2::PropertyAmbigous PC";

            Assert.That(((IPropertyAmbigous2)proxied).PropertyAmbigous, Is.EqualTo(expectedPropertyValue));

            //To.ConsoleLine.e ("proxyType.GetAllProperties()", proxyType.GetAllProperties ()).nl ().e (proxyType.GetAllProperties ().Select(pi => pi.Attributes)).nl (2).e ("proxyType.GetAllMethods()", proxyType.GetAllMethods ());


            var proxyPropertyInfoPublicProperty = proxyType.GetProperty("PropertyAmbigous", _publicInstanceFlags);

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

            Assert.That(ScriptingHelper.ExecuteScriptExpression <string> ("p0.PropertyAmbigous", proxy), Is.EqualTo("ProxiedChildChild::PropertyAmbigous PC"));

            var proxyPropertyInfo = proxyType.GetProperty(
                "Remotion.Scripting.UnitTests.TestDomain.ProxiedChild.Remotion.Scripting.UnitTests.TestDomain.IPropertyAmbigous2.PropertyAmbigous", _nonPublicInstanceFlags);

            Assert.That(proxyPropertyInfo, Is.Not.Null);
            Assert.That(proxyPropertyInfo.GetValue(proxy, null), Is.EqualTo(expectedPropertyValue));
            //AssertPropertyInfoEqual (proxyPropertyInfo, propertyInfo);

            ((IPropertyAmbigous2)proxied).PropertyAmbigous = "aBc";
            const string expectedPropertyValue2 = "ProxiedChildChild::IPropertyAmbigous2::PropertyAmbigous aBc-ProxiedChildChild::IPropertyAmbigous2::PropertyAmbigous";

            Assert.That(((IPropertyAmbigous2)proxied).PropertyAmbigous, Is.EqualTo(expectedPropertyValue2));
            Assert.That(proxyPropertyInfo.GetValue(proxy, null), Is.EqualTo(expectedPropertyValue2));

            proxyPropertyInfo.SetValue(proxy, "XXyyZZ", null);
            const string expectedPropertyValue3 = "ProxiedChildChild::IPropertyAmbigous2::PropertyAmbigous XXyyZZ-ProxiedChildChild::IPropertyAmbigous2::PropertyAmbigous";

            Assert.That(((IPropertyAmbigous2)proxied).PropertyAmbigous, Is.EqualTo(expectedPropertyValue3));
            Assert.That(proxyPropertyInfo.GetValue(proxy, null), Is.EqualTo(expectedPropertyValue3));

            var proxyPropertyInfo2 = proxyType.GetProperty(
                "Remotion.Scripting.UnitTests.TestDomain.ProxiedChild.Remotion.Scripting.UnitTests.TestDomain.IPropertyAmbigous1.PropertyAmbigous", _nonPublicInstanceFlags);

            Assert.That(proxyPropertyInfo2, Is.Null);
        }
Esempio n. 3
0
        public void GetTypeMemberProxy()
        {
            var provider = new StableBindingProxyProvider(
                new TypeLevelTypeFilter(new[] { typeof(ProxiedChild) }), CreateModuleScope("GetTypeMemberProxy"));

            var          proxied       = new ProxiedChildChildChild("abrakadava");
            const string attributeName = "PrependName";

            var typeMemberProxy = provider.GetAttributeProxy(proxied, attributeName);

            var customMemberTester = new GetCustomMemberTester(typeMemberProxy);

            var result = ScriptingHelper.ExecuteScriptExpression <string> ("p0.XYZ('simsalbum',2)", customMemberTester);

            Assert.That(result, Is.EqualTo("ProxiedChild ProxiedChild: abrakadava simsalbum, THE NUMBER=2"));
        }
Esempio n. 4
0
        public void BuildProxy()
        {
            var provider = new StableBindingProxyProvider(
                new TypeLevelTypeFilter(new[] { typeof(ProxiedChild) }), CreateModuleScope("BuildProxy"));

            var proxied = new ProxiedChildChildChild("abrakadava");

            var proxy = provider.BuildProxy(proxied);

            // Necessary since a newly built proxy has an empty proxied field
            // TODO: Introduce BuildProxyFromType(proxiedType)
            ScriptingHelper.SetProxiedFieldValue(proxy, proxied);

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

            var result = ScriptingHelper.ExecuteScriptExpression <string> ("p0.PrependName('simsalbum',2)", proxy);

            Assert.That(result, Is.EqualTo("ProxiedChild ProxiedChild: abrakadava simsalbum, THE NUMBER=2"));
        }
 private void ExecuteScriptAccessPropertyAmbigous(Object obj)
 {
     ScriptingHelper.ExecuteScriptExpression <string> ("p0.PropertyAmbigous", obj);
 }