示例#1
0
        public void SetUp()
        {
            ShimLibrary.ClearRunningMethod();
            var methodInfo = typeof(SharedTestClasses.StaticMethodsTestClass).GetMethod("MethodWithParamAndReturn");

            _currentShimmedMethod = new ShimmedMethod <int>(methodInfo);
            _currentReferenceGuid = ShimLibrary.Add(_currentShimmedMethod);
        }
示例#2
0
        public void GetReturnValueAndClearRunningMethod_Returns_Correct_Default_Value_for_Constructor()
        {
            ShimLibrary.ClearRunningMethod();
            var constructorInfo = typeof(InstanceMethodsTestClass).GetConstructor(Type.EmptyTypes);

            _currentShimmedMethod = new ShimmedConstructor <InstanceMethodsTestClass>(constructorInfo);
            _currentReferenceGuid = ShimLibrary.Add(_currentShimmedMethod);
            ShimLibrary.SetRunningMethod(_currentReferenceGuid.ToString());

            var result = ShimLibrary.GetReturnValueAndClearRunningMethod <InstanceMethodsTestClass>();

            Assert.IsNotNull(result); // would be null if there was no parameterless constructor
        }
示例#3
0
        public void GetReturnValueAndClearRunningMethod_Returns_Correct_Custom_Value_for_Constructor()
        {
            var a = new InstanceMethodsTestClass();

            ShimLibrary.ClearRunningMethod();
            var constructorInfo = typeof(InstanceMethodsTestClass).GetConstructor(Type.EmptyTypes);

            _currentShimmedMethod = new ShimmedConstructor <InstanceMethodsTestClass>(constructorInfo);
            _currentReferenceGuid = ShimLibrary.Add(_currentShimmedMethod);
            ShimLibrary.SetRunningMethod(_currentReferenceGuid.ToString());
            _currentShimmedMethod.ReturnValue = a;

            var result = ShimLibrary.GetReturnValueAndClearRunningMethod <InstanceMethodsTestClass>();

            Assert.AreEqual(a.InstanceGuid, result.InstanceGuid);
            Assert.AreEqual(a, result);
        }
示例#4
0
        public void GetReturnValueAndClearRunningMethod_Execpts_When_Running_Method_Has_Void_Return_Type()
        {
            // setup a void return type method to run
            ShimLibrary.ClearRunningMethod();
            var methodInfo = typeof(SharedTestClasses.StaticMethodsTestClass).GetMethod("EmptyMethod");

            _currentShimmedMethod = new ShimmedMethod(methodInfo);
            _currentReferenceGuid = ShimLibrary.Add(_currentShimmedMethod);
            ShimLibrary.SetRunningMethod(_currentReferenceGuid.ToString());

            try
            {
                ShimLibrary.GetReturnValueAndClearRunningMethod <int>();
                Assert.Fail("Expected InvalidOperationException - running method is of type void.");
            }
            catch (InvalidOperationException e)
            {
                Assert.AreEqual(ShimLibrary.CannotGetReturnValueNonMatchingTypeError, e.Message);
            }
        }