Test - call private method, or private static method

20/10/2012 21:55

 

//var underTest = new ContactListReceiverClass();
//Invoke normal method
            var result = Isolate.Invoke.Method(underTest, "ClearCache", properties);
 
//Invoke static method
            var result = Isolate.Invoke.Method("ClearCache", properties);
 
Invoking private methods
To invoke private methods using Invoke.Method call.
 
Example: invoking an instance private method 
 
CopyC# (InvokingMethods.cs)
[TestMethod]
public void InvokePrivateMethod()
{
    var underTest = new ClassUnderTest();
 
    var result = Isolate.Invoke.Method(underTest, "Sum", 2, 5);
 
    Assert.AreEqual(7, result);
}
1 Arguments are passed to the method from Invoke.Method, in this example using the 2 and 5.
 
Example: invoking a static method:
 
CopyC# (InvokingMethods.cs)
[TestMethod, Isolated]
public void InvokePrivateStaticMethod()
{
    var result = Isolate.Invoke.Method<ClassUnderTest>("Multiply", 2, 5);
 
    Assert.AreEqual(10, result);
}