Esempio n. 1
0
        public void ShouldDisposeInvokeTest()
        {
            MockDynamicInvoker mockDynamicInvoker;
            object proxyInstance;
            Type proxiedType;
            MethodInfo invokedMethodInfo;
            object[] invocationParameters;
            object returnValue;

            proxyInstance = new object();
            proxiedType = typeof(IDisposable);
            invokedMethodInfo = (MethodInfo)MemberInfoProxy<IDisposable>.GetLastMemberInfo(exec => exec.Dispose());
            invocationParameters = new object[] { };

            mockDynamicInvoker = new MockDynamicInvoker();
            returnValue = mockDynamicInvoker.Invoke(proxiedType, invokedMethodInfo, proxyInstance, invocationParameters);

            Assert.IsNull(returnValue);
            Assert.IsTrue(mockDynamicInvoker.Disposed);
        }
Esempio n. 2
0
        public void ShouldCloneInvokeTest()
        {
            MockDynamicInvoker mockDynamicInvoker;
            object proxyInstance;
            Type proxiedType;
            MethodInfo invokedMethodInfo;
            object[] invocationParameters;
            object returnValue;

            proxyInstance = new object();
            proxiedType = typeof(ICloneable);
            invokedMethodInfo = (MethodInfo)MemberInfoProxy<ICloneable>.GetLastMemberInfo(exec => exec.Clone());
            invocationParameters = new object[] { };

            mockDynamicInvoker = new MockDynamicInvoker();
            returnValue = mockDynamicInvoker.Invoke(proxiedType, invokedMethodInfo, proxyInstance, invocationParameters);

            Assert.IsNull(returnValue);
            Assert.AreEqual("ICloneable::Clone", mockDynamicInvoker.lastOperationName);
        }
Esempio n. 3
0
        public void ShouldEqualsInvokeOnObjectTest()
        {
            MockDynamicInvoker mockDynamicInvoker;
            object proxyInstance;
            Type proxiedType;
            MethodInfo invokedMethodInfo;
            object[] invocationParameters;
            object returnValue;

            proxyInstance = new object();
            proxiedType = typeof(IMockObject);
            invokedMethodInfo = (MethodInfo)MemberInfoProxy<IMockObject>.GetLastMemberInfo(exec => exec.Equals(null));
            invocationParameters = new object[] { null };

            mockDynamicInvoker = new MockDynamicInvoker();
            returnValue = mockDynamicInvoker.BypassInvokeOnObject(proxiedType, invokedMethodInfo, proxyInstance, invocationParameters);

            Assert.AreEqual(false, returnValue);
        }
Esempio n. 4
0
        public void ShouldToStringInvokeTest()
        {
            MockDynamicInvoker mockDynamicInvoker;
            object proxyInstance;
            Type proxiedType;
            MethodInfo invokedMethodInfo;
            object[] invocationParameters;
            object returnValue;

            proxyInstance = new object();
            proxiedType = typeof(IMockObject);
            invokedMethodInfo = (MethodInfo)MemberInfoProxy<IMockObject>.GetLastMemberInfo(exec => exec.ToString());
            invocationParameters = new object[] { };

            mockDynamicInvoker = new MockDynamicInvoker();
            returnValue = mockDynamicInvoker.Invoke(proxiedType, invokedMethodInfo, proxyInstance, invocationParameters);

            Assert.AreEqual(typeof(IMockObject).FullName, returnValue);
        }
Esempio n. 5
0
        public void ShouldNotFailOnDoubleDisposeTest()
        {
            MockDynamicInvoker mockDynamicInvoker;

            mockDynamicInvoker = new MockDynamicInvoker();

            Assert.IsNotNull(mockDynamicInvoker);

            mockDynamicInvoker.Dispose();
            mockDynamicInvoker.Dispose();
        }
Esempio n. 6
0
        public void ShouldFailOnNullTargetInstanceInvokeTest()
        {
            MockDynamicInvoker mockDynamicInvoker;
            object proxyInstance;
            Type proxiedType;
            MethodInfo invokedMethodInfo;
            object[] invocationParameters;

            proxyInstance = null;
            proxiedType = typeof(IMockObject);
            invokedMethodInfo = (MethodInfo)MemberInfoProxy<IMockObject>.GetLastMemberInfo(exec => exec.ToString());
            invocationParameters = new object[] { };

            mockDynamicInvoker = new MockDynamicInvoker();
            mockDynamicInvoker.Invoke(proxiedType, invokedMethodInfo, proxyInstance, invocationParameters);
        }
Esempio n. 7
0
        public void ShouldFailOnNullProxyTypeInvokeOnObjectTest()
        {
            MockDynamicInvoker mockDynamicInvoker;
            object proxyInstance;
            Type proxiedType;
            MethodInfo invokedMethodInfo;
            object[] invocationParameters;

            proxyInstance = new object();
            proxiedType = null;
            invokedMethodInfo = (MethodInfo)MemberInfoProxy<IMockObject>.GetLastMemberInfo(exec => exec.GetType());
            invocationParameters = new object[] { };

            mockDynamicInvoker = new MockDynamicInvoker();
            mockDynamicInvoker.BypassInvokeOnObject(proxiedType, invokedMethodInfo, proxyInstance, invocationParameters);
        }
Esempio n. 8
0
        public void ShouldFailOnNullMethodInfoInvokeTest()
        {
            MockDynamicInvoker mockDynamicInvoker;
            object proxyInstance;
            Type proxiedType;
            MethodInfo invokedMethodInfo;
            object[] invocationParameters;

            proxyInstance = new object();
            proxiedType = typeof(IMockObject);
            invokedMethodInfo = null;
            invocationParameters = new object[] { };

            mockDynamicInvoker = new MockDynamicInvoker();
            mockDynamicInvoker.BypassInvokeOnObject(proxiedType, invokedMethodInfo, proxyInstance, invocationParameters);
        }
Esempio n. 9
0
        public void ShouldFailOnBadMethodNameInvokeOnObjectTest()
        {
            MockDynamicInvoker mockDynamicInvoker;
            object proxyInstance;
            Type proxiedType;
            MethodInfo invokedMethodInfo;
            object[] invocationParameters;

            proxyInstance = new object();
            proxiedType = typeof(IMockObject);
            invokedMethodInfo = (MethodInfo)typeof(object).GetMethod("MemberwiseClone", BindingFlags.Instance | BindingFlags.NonPublic);
            invocationParameters = new object[] { };

            mockDynamicInvoker = new MockDynamicInvoker();
            mockDynamicInvoker.BypassInvokeOnObject(proxiedType, invokedMethodInfo, proxyInstance, invocationParameters);
        }
Esempio n. 10
0
        public void ShouldFailOnBadInputParameterCountToStringInvokeOnObjectTest()
        {
            MockDynamicInvoker mockDynamicInvoker;
            object proxyInstance;
            Type proxiedType;
            MethodInfo invokedMethodInfo;
            object[] invocationParameters;

            proxyInstance = new object();
            proxiedType = typeof(IMockObject);
            invokedMethodInfo = (MethodInfo)MemberInfoProxy<IMockObject>.GetLastMemberInfo(exec => exec.ToString());
            invocationParameters = new object[] { 0 };

            mockDynamicInvoker = new MockDynamicInvoker();
            mockDynamicInvoker.BypassInvokeOnObject(proxiedType, invokedMethodInfo, proxyInstance, invocationParameters);
        }
Esempio n. 11
0
        public void ShouldFailOnBadDeclaringTypeInvokeOnObjectTest()
        {
            MockDynamicInvoker mockDynamicInvoker;
            object proxyInstance;
            Type proxiedType;
            MethodInfo invokedMethodInfo;
            object[] invocationParameters;

            proxyInstance = new object();
            proxiedType = typeof(IDisposable);
            invokedMethodInfo = (MethodInfo)MemberInfoProxy<IDisposable>.GetLastMemberInfo(exec => exec.Dispose());
            invocationParameters = new object[] { };

            mockDynamicInvoker = new MockDynamicInvoker();
            mockDynamicInvoker.BypassInvokeOnObject(proxiedType, invokedMethodInfo, proxyInstance, invocationParameters);
        }