Example #1
0
        public void InheritedConstructorTest()
        {
            var mockBase = new Mock <BaseWithConstructor>();

            var mockInvoker = new Mock <IAdvancedInvoker>();
            var invoker     = mockInvoker.Object;

            var proxy = ProxyBuilder.CreateAdvanced <ISimple>(invoker.Invoke, new ProxyOptions {
                BaseClass = typeof(BaseWithConstructor)
            });

            Assert.AreEqual(5, ((BaseWithConstructor)proxy).X);

            mockInvoker.Verify();
        }
Example #2
0
        public void MultipleInterfacesTest()
        {
            var mockInvoker = new Mock <IAdvancedInvoker>();

            mockInvoker.Setup(mock => mock.Invoke(It.Is <MethodInfo>(m => m.Name == "OtherMethod"), It.Is <object>(i => i is ISimple)))
            .Returns(null)
            .Verifiable();

            var invoker = mockInvoker.Object;
            var proxy   = ProxyBuilder.CreateAdvanced <ISimple>(invoker.Invoke, new ProxyOptions {
                AdditionalInterfaces = new[] { typeof(IOther) }
            });

            ((IOther)proxy).OtherMethod();

            mockInvoker.Verify();
        }
Example #3
0
        public void BaseImplementedTest()
        {
            var mockBase = new Mock <ImplementingBase>();

            mockBase.Setup(mock => mock.OtherMethod()).Verifiable();

            var mockInvoker = new Mock <IAdvancedInvoker>();

            mockInvoker.Setup(mock => mock.Invoke(It.IsAny <MethodInfo>(), It.Is <object>(i => i is ISimple), It.IsAny <object[]>()))
            .Throws(new Exception("Proxy's Invoke for OtherMethod shouldn't be called."));
            var invoker = mockInvoker.Object;

            var proxy = ProxyBuilder.CreateAdvanced <IOther>(invoker.Invoke, new ProxyOptions {
                BaseClass = typeof(ImplementingBase)
            });

            proxy.OtherMethod();

            mockInvoker.Verify();
        }
Example #4
0
        public void InheritedInvocationTest()
        {
            var mockBase = new Mock <SimpleBase>();

            mockBase.Setup(mock => mock.BaseMethod()).Verifiable();

            var mockInvoker = new Mock <IAdvancedInvoker>();

            mockInvoker.Setup(mock => mock.Invoke(It.Is <MethodInfo>(m => m == typeof(SimpleBase).GetMethod("BaseMethod")), It.Is <object>(i => i is ISimple)))
            .Returns(null);
            var invoker = mockInvoker.Object;

            var proxy = ProxyBuilder.CreateAdvanced <ISimple>(invoker.Invoke, new ProxyOptions {
                BaseClass = typeof(SimpleBase)
            });

            ((SimpleBase)proxy).BaseMethod();

            mockInvoker.Verify();
        }