Пример #1
0
        public void ClearRunningMethod_Sets_Running_Method_Null()
        {
            ShimLibrary.SetRunningMethod(_currentReferenceGuid.ToString());

            try
            {
                ShimLibrary.AddCallResultToShim(new object[] { });
            }
            catch (Exception)
            {
                Assert.Fail("Method should now be running.");
            }

            ShimLibrary.ClearRunningMethod();

            try
            {
                ShimLibrary.AddCallResultToShim(new object[] { });
                Assert.Fail("Expected NullReferenceException - no method should be running.");
            }
            catch (NullReferenceException)
            {
                // do nothing
            }
        }
Пример #2
0
        public void SetUp()
        {
            ShimLibrary.ClearRunningMethod();
            var methodInfo = typeof(SharedTestClasses.StaticMethodsTestClass).GetMethod("MethodWithParamAndReturn");

            _currentShimmedMethod = new ShimmedMethod <int>(methodInfo);
            _currentReferenceGuid = ShimLibrary.Add(_currentShimmedMethod);
        }
Пример #3
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
        }
Пример #4
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);
        }
Пример #5
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);
            }
        }