Пример #1
0
        public static void Proxy_Declares_Interface_Properties()
        {
            TestType_IPropertyService proxy = DispatchProxy.Create <TestType_IPropertyService, TestDispatchProxy>();
            PropertyInfo propertyInfo       = proxy.GetType().GetTypeInfo().GetDeclaredProperty("ReadWrite");

            Assert.NotNull(propertyInfo);
        }
Пример #2
0
        public static void Invoke_Property_Setter_And_Getter_Invokes_Correct_Methods()
        {
            List <MethodInfo> invokedMethods = new List <MethodInfo>();

            TestType_IPropertyService proxy = DispatchProxy.Create <TestType_IPropertyService, TestDispatchProxy>();

            ((TestDispatchProxy)proxy).CallOnInvoke = (method, args) =>
            {
                invokedMethods.Add(method);
                return(null);
            };


            proxy.ReadWrite = "testValue";
            string actualValue = proxy.ReadWrite;

            Assert.True(invokedMethods.Count == 2, String.Format("Expected 2 method invocations but received {0}", invokedMethods.Count));

            PropertyInfo propertyInfo = typeof(TestType_IPropertyService).GetTypeInfo().GetDeclaredProperty("ReadWrite");

            Assert.NotNull(propertyInfo);

            MethodInfo expectedMethod = propertyInfo.SetMethod;

            Assert.True(invokedMethods[0] != null && expectedMethod == invokedMethods[0], String.Format("First invoke should have been {0} but actual was {1}",
                                                                                                        expectedMethod.Name, invokedMethods[0]));

            expectedMethod = propertyInfo.GetMethod;
            Assert.True(invokedMethods[1] != null && expectedMethod == invokedMethods[1], String.Format("Second invoke should have been {0} but actual was {1}",
                                                                                                        expectedMethod.Name, invokedMethods[1]));

            Assert.Null(actualValue);
        }