示例#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);
        }