public void ShouldValidateAssumptionAboutRealProxyObjectIdTest()
        {
            MockDynamicInvokerRealProxy realProxy;
            IMockObject        transparentProxy0, transparentProxy1;
            Mockery            mockery;
            IDynamicInvocation mockDynamicInvocation;

            mockery = new Mockery();
            mockDynamicInvocation = mockery.NewMock <IDynamicInvocation>();

            realProxy = new MockDynamicInvokerRealProxy(mockDynamicInvocation);
            Assert.IsNotNull(realProxy);

            transparentProxy0 = (IMockObject)realProxy.GetTransparentProxy();
            Assert.IsNotNull(transparentProxy0);
            Assert.IsTrue(RemotingServices.IsTransparentProxy((object)transparentProxy0));
            Assert.IsTrue(RemotingServices.GetRealProxy((object)transparentProxy0) == (object)realProxy);
            Assert.IsFalse((object)realProxy == (object)transparentProxy0);

            transparentProxy1 = (IMockObject)realProxy.GetTransparentProxy();
            Assert.IsNotNull(transparentProxy1);
            Assert.IsTrue(RemotingServices.IsTransparentProxy((object)transparentProxy1));
            Assert.IsTrue(RemotingServices.GetRealProxy((object)transparentProxy1) == (object)realProxy);
            Assert.IsFalse((object)realProxy == (object)transparentProxy1);

            Assert.IsTrue((object)transparentProxy0 == (object)transparentProxy1);

            mockery.VerifyAllExpectationsHaveBeenMet();
        }
        public void ShouldValidateAssumptionAboutRealProxyObjectCastingTest()
        {
            MockDynamicInvokerRealProxy realProxy;
            IMockObject        transparentProxy;
            Mockery            mockery;
            IDynamicInvocation mockDynamicInvocation;
            IDisposable        disposable;
            MethodInfo         invokedMethodInfo;

            mockery = new Mockery();
            mockDynamicInvocation = mockery.NewMock <IDynamicInvocation>();

            invokedMethodInfo = (MethodInfo)MemberInfoProxy <IDisposable> .GetLastMemberInfo(exec => exec.Dispose());

            realProxy = new MockDynamicInvokerRealProxy(mockDynamicInvocation);
            Assert.IsNotNull(realProxy);

            Expect.Once.On(mockDynamicInvocation).Method("Invoke").With(new EqualMatcher(typeof(IMockObject)), new EqualMatcher(invokedMethodInfo), new EqualMatcher(realProxy.GetTransparentProxy()), new EqualMatcher(new object[] { })).Will(Return.Value(null));

            transparentProxy = (IMockObject)realProxy.GetTransparentProxy();
            Assert.IsNotNull(transparentProxy);
            Assert.IsTrue(RemotingServices.IsTransparentProxy((object)transparentProxy));
            Assert.IsTrue(RemotingServices.GetRealProxy((object)transparentProxy) == (object)realProxy);
            Assert.IsFalse((object)realProxy == (object)transparentProxy);

            Assert.IsTrue(realProxy.CanCastTo(typeof(IDisposable), null));
            Assert.IsFalse(realProxy.CanCastTo(typeof(IConvertible), null));
            Assert.IsTrue(transparentProxy is IDisposable);

            disposable = (IDisposable)transparentProxy;
            disposable.Dispose();

            mockery.VerifyAllExpectationsHaveBeenMet();
        }
        public void ShouldValidateAssumptionAboutRealProxyObjectIdTest()
        {
            MockDynamicInvokerRealProxy realProxy;
            IMockObject transparentProxy0, transparentProxy1;
            Mockery mockery;
            IDynamicInvocation mockDynamicInvocation;

            mockery = new Mockery();
            mockDynamicInvocation = mockery.NewMock<IDynamicInvocation>();

            realProxy = new MockDynamicInvokerRealProxy(mockDynamicInvocation);
            Assert.IsNotNull(realProxy);

            transparentProxy0 = (IMockObject)realProxy.GetTransparentProxy();
            Assert.IsNotNull(transparentProxy0);
            Assert.IsTrue(RemotingServices.IsTransparentProxy((object)transparentProxy0));
            Assert.IsTrue(RemotingServices.GetRealProxy((object)transparentProxy0) == (object)realProxy);
            Assert.IsFalse((object)realProxy == (object)transparentProxy0);

            transparentProxy1 = (IMockObject)realProxy.GetTransparentProxy();
            Assert.IsNotNull(transparentProxy1);
            Assert.IsTrue(RemotingServices.IsTransparentProxy((object)transparentProxy1));
            Assert.IsTrue(RemotingServices.GetRealProxy((object)transparentProxy1) == (object)realProxy);
            Assert.IsFalse((object)realProxy == (object)transparentProxy1);

            Assert.IsTrue((object)transparentProxy0 == (object)transparentProxy1);

            mockery.VerifyAllExpectationsHaveBeenMet();
        }
        public void ShouldValidateAssumptionAboutRealProxyObjectCastingTest()
        {
            MockDynamicInvokerRealProxy realProxy;
            IMockObject transparentProxy;
            Mockery mockery;
            IDynamicInvocation mockDynamicInvocation;
            IDisposable disposable;
            MethodInfo invokedMethodInfo;

            mockery = new Mockery();
            mockDynamicInvocation = mockery.NewMock<IDynamicInvocation>();

            invokedMethodInfo = (MethodInfo)MemberInfoProxy<IDisposable>.GetLastMemberInfo(exec => exec.Dispose());

            realProxy = new MockDynamicInvokerRealProxy(mockDynamicInvocation);
            Assert.IsNotNull(realProxy);

            Expect.Once.On(mockDynamicInvocation).Method("Invoke").With(new EqualMatcher(typeof(IMockObject)), new EqualMatcher(invokedMethodInfo), new EqualMatcher(realProxy.GetTransparentProxy()), new EqualMatcher(new object[] { })).Will(Return.Value(null));

            transparentProxy = (IMockObject)realProxy.GetTransparentProxy();
            Assert.IsNotNull(transparentProxy);
            Assert.IsTrue(RemotingServices.IsTransparentProxy((object)transparentProxy));
            Assert.IsTrue(RemotingServices.GetRealProxy((object)transparentProxy) == (object)realProxy);
            Assert.IsFalse((object)realProxy == (object)transparentProxy);

            Assert.IsTrue(realProxy.CanCastTo(typeof(IDisposable), null));
            Assert.IsFalse(realProxy.CanCastTo(typeof(IConvertible), null));
            Assert.IsTrue(transparentProxy is IDisposable);

            disposable = (IDisposable)transparentProxy;
            disposable.Dispose();

            mockery.VerifyAllExpectationsHaveBeenMet();
        }
        public void ShouldInvokeAsObjectTest()
        {
            Mockery mockery;
            MockDynamicInvokerRealProxy mockDynamicInvokerRealProxy;
            IDynamicInvocation mockDynamicInvocation;
            IMethodCallMessage mockMessage;
            MethodInfo invokedMethodInfo;

            mockery = new Mockery();
            mockDynamicInvocation = mockery.NewMock<IDynamicInvocation>();
            mockMessage = mockery.NewMock<IMethodCallMessage>();

            invokedMethodInfo = (MethodInfo)MemberInfoProxy<IMockObject>.GetLastMemberInfo(exec => exec.GetType());

            Expect.Once.On(mockMessage).GetProperty("Args").Will(Return.Value(new object[] { }));
            Expect.Exactly(2).On(mockMessage).GetProperty("MethodBase").Will(Return.Value(invokedMethodInfo));
            Expect.Once.On(mockMessage).GetProperty("LogicalCallContext").Will(Return.Value(null));
            Expect.Once.On(mockMessage).GetProperty("Uri").Will(Return.Value(null));
            Expect.Once.On(mockMessage).GetProperty("MethodName").Will(Return.Value(null));
            Expect.Once.On(mockMessage).GetProperty("TypeName").Will(Return.Value(null));
            Expect.Once.On(mockMessage).GetProperty("HasVarArgs").Will(Return.Value(false));

            mockDynamicInvokerRealProxy = new MockDynamicInvokerRealProxy(mockDynamicInvocation);

            Expect.Once.On(mockDynamicInvocation).Method("Invoke").With(new EqualMatcher(typeof(IMockObject)), new EqualMatcher(invokedMethodInfo), new EqualMatcher(mockDynamicInvokerRealProxy.GetTransparentProxy()), new EqualMatcher(new object[] { })).Will(Return.Value(null));

            Assert.IsNotNull(mockDynamicInvokerRealProxy);

            mockDynamicInvokerRealProxy.Invoke(mockMessage);

            mockery.VerifyAllExpectationsHaveBeenMet();
        }
        public void ShouldInvokeAsIMockObjectTest()
        {
            Mockery mockery;
            MockDynamicInvokerRealProxy mockDynamicInvokerRealProxy;
            IDynamicInvocation mockDynamicInvocation;
            IMethodCallMessage mockMessage;
            MethodInfo invokedMethodInfo;

            mockery = new Mockery();
            mockDynamicInvocation = mockery.NewMock<IDynamicInvocation>();
            mockMessage = mockery.NewMock<IMethodCallMessage>();

            invokedMethodInfo = (MethodInfo)MemberInfoProxy<IMockObject>.GetLastMemberInfo(exec =>
                                                                                           {
                                                                                           	byte bdummy = default(byte);
                                                                                           	int idummy = default(int);
                                                                                           	string sdummy = default(string);
                                                                                           	object odummy = default(object);
                                                                                           	bdummy = exec.SomeMethodWithVarietyOfParameters(idummy, out sdummy, ref odummy);
                                                                                           });

            Expect.Once.On(mockMessage).GetProperty("Args").Will(Return.Value(new object[] { 10, "100", (object)"1000" }));
            Expect.Exactly(2).On(mockMessage).GetProperty("MethodBase").Will(Return.Value(invokedMethodInfo));
            Expect.Once.On(mockMessage).GetProperty("LogicalCallContext").Will(Return.Value(null));
            Expect.Once.On(mockMessage).GetProperty("Uri").Will(Return.Value(null));
            Expect.Once.On(mockMessage).GetProperty("MethodName").Will(Return.Value(null));
            Expect.Once.On(mockMessage).GetProperty("TypeName").Will(Return.Value(null));
            Expect.Once.On(mockMessage).GetProperty("HasVarArgs").Will(Return.Value(false));

            mockDynamicInvokerRealProxy = new MockDynamicInvokerRealProxy(mockDynamicInvocation);
            Assert.IsNotNull(mockDynamicInvokerRealProxy);

            Expect.Once.On(mockDynamicInvocation).Method("Invoke").With(new EqualMatcher(typeof(IMockObject)), new EqualMatcher(invokedMethodInfo), new EqualMatcher(mockDynamicInvokerRealProxy.GetTransparentProxy()), new EqualMatcher(new object[] { 10, "100", (object)"1000" })).Will(Return.Value(null));

            mockDynamicInvokerRealProxy.Invoke(mockMessage);

            mockery.VerifyAllExpectationsHaveBeenMet();
        }
        public void ShouldIFailOnNullMethodInfoInGetOutputParametersTest()
        {
            Mockery mockery;
            MockDynamicInvokerRealProxy mockDynamicInvokerRealProxy;
            IDynamicInvocation mockDynamicInvocation;
            IMethodCallMessage mockMessage;
            MethodInfo invokedMethodInfo;

            mockery = new Mockery();
            mockDynamicInvocation = mockery.NewMock<IDynamicInvocation>();
            mockMessage = mockery.NewMock<IMethodCallMessage>();

            invokedMethodInfo = null;

            Expect.Once.On(mockMessage).GetProperty("Args").Will(Return.Value(new object[] { 10, "100", (object)"1000" }));
            Expect.Exactly(2).On(mockMessage).GetProperty("MethodBase").Will(Return.Value(invokedMethodInfo));
            Expect.Once.On(mockMessage).GetProperty("LogicalCallContext").Will(Return.Value(null));
            Expect.Once.On(mockMessage).GetProperty("Uri").Will(Return.Value(null));
            Expect.Once.On(mockMessage).GetProperty("MethodName").Will(Return.Value(null));
            Expect.Once.On(mockMessage).GetProperty("TypeName").Will(Return.Value(null));
            Expect.Once.On(mockMessage).GetProperty("HasVarArgs").Will(Return.Value(false));

            mockDynamicInvokerRealProxy = new MockDynamicInvokerRealProxy(mockDynamicInvocation);
            Assert.IsNotNull(mockDynamicInvokerRealProxy);

            Expect.Once.On(mockDynamicInvocation).Method("Invoke").With(new EqualMatcher(typeof(IMockObject)), new EqualMatcher(invokedMethodInfo), new EqualMatcher(mockDynamicInvokerRealProxy.GetTransparentProxy()), new EqualMatcher(new object[] { 10, "100", (object)"1000" })).Will(Return.Value(null));

            mockDynamicInvokerRealProxy.Invoke(mockMessage);
        }
        public void ShouldInvokeAsObjectTest()
        {
            Mockery mockery;
            MockDynamicInvokerRealProxy mockDynamicInvokerRealProxy;
            IDynamicInvocation          mockDynamicInvocation;
            IMethodCallMessage          mockMessage;
            MethodInfo invokedMethodInfo;

            mockery = new Mockery();
            mockDynamicInvocation = mockery.NewMock <IDynamicInvocation>();
            mockMessage           = mockery.NewMock <IMethodCallMessage>();

            invokedMethodInfo = (MethodInfo)MemberInfoProxy <IMockObject> .GetLastMemberInfo(exec => exec.GetType());

            Expect.Once.On(mockMessage).GetProperty("Args").Will(Return.Value(new object[] { }));
            Expect.Exactly(2).On(mockMessage).GetProperty("MethodBase").Will(Return.Value(invokedMethodInfo));
            Expect.Once.On(mockMessage).GetProperty("LogicalCallContext").Will(Return.Value(null));
            Expect.Once.On(mockMessage).GetProperty("Uri").Will(Return.Value(null));
            Expect.Once.On(mockMessage).GetProperty("MethodName").Will(Return.Value(null));
            Expect.Once.On(mockMessage).GetProperty("TypeName").Will(Return.Value(null));
            Expect.Once.On(mockMessage).GetProperty("HasVarArgs").Will(Return.Value(false));

            mockDynamicInvokerRealProxy = new MockDynamicInvokerRealProxy(mockDynamicInvocation);

            Expect.Once.On(mockDynamicInvocation).Method("Invoke").With(new EqualMatcher(typeof(IMockObject)), new EqualMatcher(invokedMethodInfo), new EqualMatcher(mockDynamicInvokerRealProxy.GetTransparentProxy()), new EqualMatcher(new object[] { })).Will(Return.Value(null));

            Assert.IsNotNull(mockDynamicInvokerRealProxy);

            mockDynamicInvokerRealProxy.Invoke(mockMessage);

            mockery.VerifyAllExpectationsHaveBeenMet();
        }
        public void ShouldInvokeAsIMockObjectTest()
        {
            Mockery mockery;
            MockDynamicInvokerRealProxy mockDynamicInvokerRealProxy;
            IDynamicInvocation          mockDynamicInvocation;
            IMethodCallMessage          mockMessage;
            MethodInfo invokedMethodInfo;

            mockery = new Mockery();
            mockDynamicInvocation = mockery.NewMock <IDynamicInvocation>();
            mockMessage           = mockery.NewMock <IMethodCallMessage>();

            invokedMethodInfo = (MethodInfo)MemberInfoProxy <IMockObject> .GetLastMemberInfo(exec =>
            {
                byte bdummy   = default(byte);
                int idummy    = default(int);
                string sdummy = default(string);
                object odummy = default(object);
                bdummy        = exec.SomeMethodWithVarietyOfParameters(idummy, out sdummy, ref odummy);
            });

            Expect.Once.On(mockMessage).GetProperty("Args").Will(Return.Value(new object[] { 10, "100", (object)"1000" }));
            Expect.Exactly(2).On(mockMessage).GetProperty("MethodBase").Will(Return.Value(invokedMethodInfo));
            Expect.Once.On(mockMessage).GetProperty("LogicalCallContext").Will(Return.Value(null));
            Expect.Once.On(mockMessage).GetProperty("Uri").Will(Return.Value(null));
            Expect.Once.On(mockMessage).GetProperty("MethodName").Will(Return.Value(null));
            Expect.Once.On(mockMessage).GetProperty("TypeName").Will(Return.Value(null));
            Expect.Once.On(mockMessage).GetProperty("HasVarArgs").Will(Return.Value(false));

            mockDynamicInvokerRealProxy = new MockDynamicInvokerRealProxy(mockDynamicInvocation);
            Assert.IsNotNull(mockDynamicInvokerRealProxy);

            Expect.Once.On(mockDynamicInvocation).Method("Invoke").With(new EqualMatcher(typeof(IMockObject)), new EqualMatcher(invokedMethodInfo), new EqualMatcher(mockDynamicInvokerRealProxy.GetTransparentProxy()), new EqualMatcher(new object[] { 10, "100", (object)"1000" })).Will(Return.Value(null));

            mockDynamicInvokerRealProxy.Invoke(mockMessage);

            mockery.VerifyAllExpectationsHaveBeenMet();
        }
        public void ShouldIFailOnNullMethodInfoInGetOutputParametersTest()
        {
            Mockery mockery;
            MockDynamicInvokerRealProxy mockDynamicInvokerRealProxy;
            IDynamicInvocation          mockDynamicInvocation;
            IMethodCallMessage          mockMessage;
            MethodInfo invokedMethodInfo;

            mockery = new Mockery();
            mockDynamicInvocation = mockery.NewMock <IDynamicInvocation>();
            mockMessage           = mockery.NewMock <IMethodCallMessage>();

            invokedMethodInfo = null;

            Expect.Once.On(mockMessage).GetProperty("Args").Will(Return.Value(new object[] { 10, "100", (object)"1000" }));
            Expect.Exactly(2).On(mockMessage).GetProperty("MethodBase").Will(Return.Value(invokedMethodInfo));
            Expect.Once.On(mockMessage).GetProperty("LogicalCallContext").Will(Return.Value(null));
            Expect.Once.On(mockMessage).GetProperty("Uri").Will(Return.Value(null));
            Expect.Once.On(mockMessage).GetProperty("MethodName").Will(Return.Value(null));
            Expect.Once.On(mockMessage).GetProperty("TypeName").Will(Return.Value(null));
            Expect.Once.On(mockMessage).GetProperty("HasVarArgs").Will(Return.Value(false));

            mockDynamicInvokerRealProxy = new MockDynamicInvokerRealProxy(mockDynamicInvocation);
            Assert.IsNotNull(mockDynamicInvokerRealProxy);

            Expect.Once.On(mockDynamicInvocation).Method("Invoke").With(new EqualMatcher(typeof(IMockObject)), new EqualMatcher(invokedMethodInfo), new EqualMatcher(mockDynamicInvokerRealProxy.GetTransparentProxy()), new EqualMatcher(new object[] { 10, "100", (object)"1000" })).Will(Return.Value(null));

            mockDynamicInvokerRealProxy.Invoke(mockMessage);
        }