Example #1
0
        public void Test_ExecutePrivateMethod_WithNoArguments()
        {
            //--------------- Set up test pack ------------------
            ClassWithPrivateMethod classWithPrivateMethod = new ClassWithPrivateMethod();

            //--------------- Test Preconditions ----------------
            Assert.IsFalse(classWithPrivateMethod.PrivateMethodCalled);
            //--------------- Execute Test ----------------------
            ReflectionUtilities.ExecutePrivateMethod(classWithPrivateMethod, "MyPrivateMethod");
            //--------------- Test Result -----------------------
            Assert.IsTrue(classWithPrivateMethod.PrivateMethodCalled);
        }
Example #2
0
        public void Test_ExecutePrivateMethod_WithNoArgumentsWithReturn_ShouldReturnValue()
        {
            //--------------- Set up test pack ------------------
            ClassWithPrivateMethod classWithPrivateMethod = new ClassWithPrivateMethod();

            //--------------- Test Preconditions ----------------
            Assert.IsFalse(classWithPrivateMethod.PrivateMethodCalled);
            //--------------- Execute Test ----------------------
            var returnValue = ReflectionUtilities.ExecutePrivateMethod(classWithPrivateMethod,
                                                                       "MyPrivateMethodWithReturn");

            //--------------- Test Result -----------------------
            Assert.IsTrue(classWithPrivateMethod.PrivateMethodCalled);
            Assert.AreEqual("SomeString", returnValue);
        }
Example #3
0
        public void Test_ExecutePrivateMethod_WithArguments()
        {
            //--------------- Set up test pack ------------------
            ClassWithPrivateMethod classWithPrivateMethod = new ClassWithPrivateMethod();
            string testStringParam = TestUtil.GetRandomString();
            int    testIntParam    = TestUtil.GetRandomInt();

            //--------------- Test Preconditions ----------------
            Assert.IsFalse(classWithPrivateMethod.PrivateMethodCalled);
            Assert.IsNull(classWithPrivateMethod.StringParamValue);
            Assert.IsFalse(classWithPrivateMethod.IntParamValue.HasValue);
            //--------------- Execute Test ----------------------
            ReflectionUtilities.ExecutePrivateMethod(classWithPrivateMethod, "MyPrivateMethodWithParams",
                                                     testStringParam, testIntParam);
            //--------------- Test Result -----------------------
            Assert.IsTrue(classWithPrivateMethod.PrivateMethodCalled);
            Assert.AreEqual(testStringParam, classWithPrivateMethod.StringParamValue);
            Assert.IsTrue(classWithPrivateMethod.IntParamValue.HasValue);
            Assert.AreEqual(testIntParam, classWithPrivateMethod.IntParamValue.GetValueOrDefault());
        }
 public void Test_ExecutePrivateMethod_WithArgumentsWithReturn_ShouldReturnValue()
 {
     //--------------- Set up test pack ------------------
     ClassWithPrivateMethod classWithPrivateMethod = new ClassWithPrivateMethod();
     string testStringParam = TestUtil.GetRandomString();
     int testIntParam = TestUtil.GetRandomInt();
     //--------------- Test Preconditions ----------------
     Assert.IsFalse(classWithPrivateMethod.PrivateMethodCalled);
     Assert.IsNull(classWithPrivateMethod.StringParamValue);
     Assert.IsFalse(classWithPrivateMethod.IntParamValue.HasValue);
     //--------------- Execute Test ----------------------
     var returnValue = ReflectionUtilities.ExecutePrivateMethod(classWithPrivateMethod,
                                                                "MyPrivateMethodWithParamsWithReturn",
                                                                testStringParam, testIntParam);
     //--------------- Test Result -----------------------
     Assert.IsTrue(classWithPrivateMethod.PrivateMethodCalled);
     Assert.AreEqual(testStringParam, classWithPrivateMethod.StringParamValue);
     Assert.IsTrue(classWithPrivateMethod.IntParamValue.HasValue);
     Assert.AreEqual(testIntParam, classWithPrivateMethod.IntParamValue.Value);
     Assert.AreEqual(testStringParam, returnValue);
 }
 public void Test_ExecutePrivateMethod_WithNoArgumentsWithReturn_ShouldReturnValue()
 {
     //--------------- Set up test pack ------------------
     ClassWithPrivateMethod classWithPrivateMethod = new ClassWithPrivateMethod();
     //--------------- Test Preconditions ----------------
     Assert.IsFalse(classWithPrivateMethod.PrivateMethodCalled);
     //--------------- Execute Test ----------------------
     var returnValue = ReflectionUtilities.ExecutePrivateMethod(classWithPrivateMethod,
                                                                "MyPrivateMethodWithReturn");
     //--------------- Test Result -----------------------
     Assert.IsTrue(classWithPrivateMethod.PrivateMethodCalled);
     Assert.AreEqual("SomeString", returnValue);
 }
 public void Test_ExecutePrivateMethod_WithNoArguments()
 {
     //--------------- Set up test pack ------------------
     ClassWithPrivateMethod classWithPrivateMethod = new ClassWithPrivateMethod();
     //--------------- Test Preconditions ----------------
     Assert.IsFalse(classWithPrivateMethod.PrivateMethodCalled);
     //--------------- Execute Test ----------------------
     ReflectionUtilities.ExecutePrivateMethod(classWithPrivateMethod, "MyPrivateMethod");
     //--------------- Test Result -----------------------
     Assert.IsTrue(classWithPrivateMethod.PrivateMethodCalled);
 }