public void ShouldProxifyInterface()
        {
            Object proxy = Proxifier.WithoutBaseClass(new FuncProxyAction((instance, method, args) => null))
                           .WithInterfaces(typeof(TestInterface)).Build();

            Assert.IsAssignableFrom(typeof(TestInterface), proxy);
        }
 public void ShouldThrowArgumentExceptionIfBaseTypeIsAInterface()
 {
     Assert.Throws <ArgumentException>(() =>
     {
         Proxifier.For <BaseInterface>(new FuncProxyAction((instance, method, args) => null));
     });
 }
 public void ShouldThrowArgumentNullExceptionIfProxyCallbackIsNull()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         Proxifier.For <Object>(null);
     });
 }
 public void ShouldThrowArgumentNullExceptionWhenCallingWithInterfacesWithNull()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         Proxifier.For <Object>(new FuncProxyAction((instance, method, args) => null))
         .WithInterfaces(typeof(BaseInterface), null);
     });
 }
 public void ShouldThrowArgumentExceptionWhenPassingAClassAsInterface()
 {
     Assert.Throws <ArgumentException>(() =>
     {
         Proxifier.For <Object>(new FuncProxyAction((instance, method, args) => null))
         .WithInterfaces(typeof(ClassAsInterface));
     });
 }
Esempio n. 6
0
        public void ShouldUseProxyCallbackValueOnMethodWithValueTypeReturnValue()
        {
            const int     ReturnValue = 1234;
            AbstractClass proxy       = Proxifier.For <AbstractClass>(new FuncProxyAction((instance, method, args) => {
                return(1234);
            })).Build();
            int result = proxy.MethodWithValueTypeReturnValue();

            Assert.Equal(ReturnValue, result);
        }
Esempio n. 7
0
        public void ShouldUseProxyCallbackValueOnMethodWithReferenceTypeReturnValue()
        {
            const string  ReturnValue = "Test string";
            AbstractClass proxy       = Proxifier.For <AbstractClass>(new FuncProxyAction((instance, method, args) => {
                return(ReturnValue);
            })).Build();
            String result = proxy.MethodWithReferenceTypeReturnValue();

            Assert.Equal(ReturnValue, result);
        }
Esempio n. 8
0
        public void ShouldWireCallback()
        {
            bool          proxyCalled = false;
            AbstractClass proxy       = Proxifier.For <AbstractClass>(new FuncProxyAction((instance, method, args) => {
                proxyCalled = true;
                return(null);
            })).Build();

            proxy.Method();
            Assert.True(proxyCalled, "The proxy callback was not invoked");
        }
        public void ShouldUseProxyCallbackValueOnMethodWithValueTypeReturnValue()
        {
            const int     ReturnValue = 1234;
            TestInterface proxy       = Proxifier.WithoutBaseClass(new FuncProxyAction((instance, method, args) => {
                return(1234);
            }))
                                        .WithInterfaces(typeof(TestInterface))
                                        .Build <TestInterface>();
            int result = proxy.MethodWithValueTypeReturnValue();

            Assert.Equal(ReturnValue, result);
        }
        public void ShouldUseProxyCallbackValueOnMethodWithReferenceTypeReturnValue()
        {
            const string  ReturnValue = "Test string";
            TestInterface proxy       = Proxifier.WithoutBaseClass(new FuncProxyAction((instance, method, args) => {
                return(ReturnValue);
            }))
                                        .WithInterfaces(typeof(TestInterface))
                                        .Build <TestInterface>();
            String result = proxy.MethodWithReferenceTypeReturnValue();

            Assert.Equal(ReturnValue, result);
        }
        public void ShouldWireCallback()
        {
            bool          proxyCalled = false;
            TestInterface proxy       = Proxifier.WithoutBaseClass(new FuncProxyAction((instance, method, args) => {
                proxyCalled = true;
                return(null);
            }))
                                        .WithInterfaces(typeof(TestInterface))
                                        .Build <TestInterface>();

            proxy.Method();
            Assert.True(proxyCalled, "The proxy callback was not invoked");
        }
Esempio n. 12
0
        public void ShouldWireCallbackOnMethodWithArgs()
        {
            bool proxyCalled = false;

            Object[]      proxyArgs = null;
            AbstractClass proxy     = Proxifier.For <AbstractClass>(new FuncProxyAction((instance, method, args) => {
                proxyCalled = true;
                proxyArgs   = args;
                return(null);
            })).Build();

            proxy.MethodWithArgs(100, "Proxy method test");
            Assert.True(proxyCalled, "The proxy callback was not invoked");
            Assert.Equal(new object[] { 100, "Proxy method test" }, proxyArgs);
        }
        public void ShouldWireCallbackOnMethodWithArgs()
        {
            bool proxyCalled = false;

            Object[]      proxyArgs = null;
            TestInterface proxy     = Proxifier.WithoutBaseClass(new FuncProxyAction((instance, method, args) => {
                proxyCalled = true;
                proxyArgs   = args;
                return(null);
            }))
                                      .WithInterfaces(typeof(TestInterface))
                                      .Build <TestInterface>();

            proxy.MethodWithArgs(100, "Proxy method test");
            Assert.True(proxyCalled, "The proxy callback was not invoked");
            Assert.Equal(new object[] { 100, "Proxy method test" }, proxyArgs);
        }
Esempio n. 14
0
        public void ShouldConstructProxyForAbstractClass()
        {
            AbstractClass proxy = Proxifier.For <AbstractClass>(new FuncProxyAction((instance, method, args) => null)).Build();

            Assert.IsAssignableFrom(typeof(object), proxy);
        }