예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #5
0
        public void ShouldNotFailOnDoubleDisposeTest()
        {
            MockDynamicInvoker mockDynamicInvoker;

            mockDynamicInvoker = new MockDynamicInvoker();

            Assert.IsNotNull(mockDynamicInvoker);

            mockDynamicInvoker.Dispose();
            mockDynamicInvoker.Dispose();
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }