Exemplo n.º 1
0
        public void GetReturnValueAndClearRunningMethod_Returns_Correct_Default_Return_Value()
        {
            ShimLibrary.SetRunningMethod(_currentReferenceGuid.ToString());
            var result = ShimLibrary.GetReturnValueAndClearRunningMethod <int>();

            Assert.AreEqual(0, result);
        }
Exemplo n.º 2
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
            }
        }
Exemplo n.º 3
0
        public void SetRunningMethod_Sets_Method_From_Guid()
        {
            // At first, a call result should except, as no method is running
            try
            {
                ShimLibrary.AddCallResultToShim(new object[] { });
                Assert.Fail("Expected NullReferenceException - no method should be running.");
            }
            catch (NullReferenceException)
            {
                // do nothing
            }

            ShimLibrary.SetRunningMethod(_currentReferenceGuid.ToString());

            // Now, it should pass, because a method is running
            try
            {
                ShimLibrary.AddCallResultToShim(new object[] { });
            }
            catch (Exception)
            {
                Assert.Fail("Method should now be running.");
            }
        }
Exemplo n.º 4
0
 public void AddCallResultToShim_Adds_Call_Result_With_Parameters()
 {
     Assert.IsFalse(_currentShimmedMethod.CallResults.Any());
     ShimLibrary.SetRunningMethod(_currentReferenceGuid.ToString());
     ShimLibrary.AddCallResultToShim(new object[] { 5 });
     Assert.AreEqual(1, _currentShimmedMethod.CallResults.Count);
     Assert.AreEqual(5, _currentShimmedMethod.CallResults.First().Parameters[0]);
 }
Exemplo n.º 5
0
        public void GetReturnValueAndClearRunningMethod_Returns_Correct_Custom_Return_Value()
        {
            _currentShimmedMethod.ReturnValue = 6;
            ShimLibrary.SetRunningMethod(_currentReferenceGuid.ToString());
            var result = ShimLibrary.GetReturnValueAndClearRunningMethod <int>();

            Assert.AreEqual(6, result);
        }
Exemplo n.º 6
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
        }
Exemplo n.º 7
0
 public void GetReturnValueAndClearRunningMethod_Execpts_When_Running_Method_Has_Wrong_Return_Type()
 {
     ShimLibrary.SetRunningMethod(_currentReferenceGuid.ToString());
     try
     {
         ShimLibrary.GetReturnValueAndClearRunningMethod <string>();
         Assert.Fail("Expected InvalidOperationException - method type doesn't match generic type.");
     }
     catch (InvalidOperationException e)
     {
         Assert.AreEqual(ShimLibrary.CannotGetReturnValueNonMatchingTypeError, e.Message);
     }
 }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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);
            }
        }