示例#1
0
        public void ShouldDisposeInvokeTest()
        {
            MockRuntimeInterception mockRuntimeInterception;
            IRuntimeInvocation      mockRuntimeInvocation;
            IRuntimeContext         mockRuntimeContext;
            object     proxyInstance;
            Type       proxiedType;
            MethodInfo invokedMethodInfo;

            object[] invocationParameters;
            object   returnValue;

            proxyInstance         = new object();
            proxiedType           = typeof(IDisposable);
            invokedMethodInfo     = typeof(IDisposable).GetMethod(nameof(IDisposable.Dispose));
            invocationParameters  = new object[] { };
            mockRuntimeInvocation = new RuntimeInvocation(proxyInstance, proxiedType, invokedMethodInfo, invocationParameters, null);
            mockRuntimeContext    = null;

            mockRuntimeInterception = new MockRuntimeInterception();
            mockRuntimeInterception.Invoke(mockRuntimeInvocation, mockRuntimeContext);
            returnValue = mockRuntimeInvocation.InvocationReturnValue;

            Assert.IsNull(returnValue);
            Assert.IsTrue(mockRuntimeInterception.IsDisposed);
        }
示例#2
0
        public void ShouldToStringInvokeTest()
        {
            MockRuntimeInterception mockRuntimeInterception;
            IRuntimeInvocation      mockRuntimeInvocation;
            IRuntimeContext         mockRuntimeContext;
            object     proxyInstance;
            Type       proxiedType;
            MethodInfo invokedMethodInfo;

            object[] invocationParameters;
            object   returnValue;

            proxyInstance         = new object();
            proxiedType           = typeof(IMockObject);
            invokedMethodInfo     = typeof(object).GetMethod(nameof(this.ToString));
            invocationParameters  = new object[] { };
            mockRuntimeInvocation = new RuntimeInvocation(proxyInstance, proxiedType, invokedMethodInfo, invocationParameters, null);
            mockRuntimeContext    = null;

            mockRuntimeInterception = new MockRuntimeInterception();
            mockRuntimeInterception.Invoke(mockRuntimeInvocation, mockRuntimeContext);
            returnValue = mockRuntimeInvocation.InvocationReturnValue;

            Assert.AreEqual(typeof(MockRuntimeInterception).FullName, returnValue);
        }
示例#3
0
        public void ShouldCloneInvokeTest()
        {
            MockRuntimeInterception mockRuntimeInterception;
            IRuntimeInvocation      mockRuntimeInvocation;
            IRuntimeContext         mockRuntimeContext;
            object     proxyInstance;
            Type       proxiedType;
            MethodInfo invokedMethodInfo;

            object[] invocationParameters;
            object   returnValue;

            proxyInstance         = new MockCloneable();
            proxiedType           = typeof(IMockCloneable);
            invokedMethodInfo     = typeof(IMockCloneable).GetMethod(nameof(IMockCloneable.Clone));
            invocationParameters  = new object[] { };
            mockRuntimeInvocation = new RuntimeInvocation(proxyInstance, proxiedType, invokedMethodInfo, invocationParameters, null);
            mockRuntimeContext    = null;

            mockRuntimeInterception = new MockRuntimeInterception();
            mockRuntimeInterception.Invoke(mockRuntimeInvocation, mockRuntimeContext);
            returnValue = mockRuntimeInvocation.InvocationReturnValue;

            Assert.IsNull(returnValue);
            Assert.AreEqual("IMockCloneable::Clone", mockRuntimeInterception.LastOperationName);
        }
示例#4
0
        public void ShouldNotFailOnDoubleDisposeTest()
        {
            MockRuntimeInterception mockRuntimeInterception;

            mockRuntimeInterception = new MockRuntimeInterception();

            Assert.IsNotNull(mockRuntimeInterception);

            mockRuntimeInterception.Dispose();
            mockRuntimeInterception.Dispose();
        }
示例#5
0
        public void ShouldFailOnNullInputParameterInvokeTest()
        {
            MockRuntimeInterception mockRuntimeInterception;
            IRuntimeInvocation      mockRuntimeInvocation;
            IRuntimeContext         mockRuntimeContext;
            object     proxyInstance;
            Type       proxiedType;
            MethodInfo invokedMethodInfo;

            object[] invocationParameters;

            proxyInstance         = new object();
            proxiedType           = typeof(IMockObject);
            invokedMethodInfo     = typeof(IMockObject).GetMethod(nameof(this.ToString));
            invocationParameters  = null;
            mockRuntimeInvocation = new RuntimeInvocation(proxyInstance, proxiedType, invokedMethodInfo, invocationParameters, null);
            mockRuntimeContext    = null;

            mockRuntimeInterception = new MockRuntimeInterception();
            mockRuntimeInterception.Invoke(mockRuntimeInvocation, mockRuntimeContext);
        }