INonPublicMethodHandlerWithGenericArguments Method

Typemock Isolator Developer Guide
Specifies generic type arguments that apply to a non-public method to set behavior on. The behavior will be set only for a method bound to the passed type arguments

Namespace:  TypeMock.ArrangeActAssert.Fluent
Assembly:  Typemock.ArrangeActAssert (in Typemock.ArrangeActAssert.dll) Version: 9.4.1.0 (9.4.1.0)
Syntax

INonPublicMethodBehavior WithGenericArguments(
	Type genericType,
	params Type[] additionalGenericTypes
)

Parameters

genericType
Type: SystemType
The first generic type argument the method binds to
additionalGenericTypes
Type: SystemType
Optional. Further generic type arguments the method binds to.

Return Value

Type: INonPublicMethodBehavior
an INonPublicMethodBehavior interface reference

Implements

INonPublicArgHandlerWithGenericArguments(Type, Type)
Remarks

WithGenericArguments() modifies a call to Isolate.NonPublic.WhenCalled(Object, String, Object). Due to the fluent nature of the AAA API it should be used with its proceeding methods; see INonPublicMethodBehavior.
Examples

Here is an example how to use WhenCalled with WithGenericArguments in order to simulate an error creating a factory generated object:
[TestMethod]
[Isolated]
public void ThrowExceptionFromGenericMethod_SimulateErrorCreatingLogger()
{
    LoggerFactory fake = Isolate.Fake.Instance<LoggerFactory>();

    // Set the logger factory to throw an exception when trying to retrieve a RealLogger
    Isolate.NonPublic.WhenCalled(fake, "GetLogger").
        WithGenericArguments(typeof(RealLogger)).
        WillThrow(new ArgumentNullException());

    // The following method call is not faked because it does not match the specified generic 
    // type arguments - no exception is thrown
    DiskLogger logger = fake.GetLogger<DiskLogger>();

    // This call will throws an exception as specified
    try 
    {
        fake.GetLogger<RealLogger>();
        Assert.Fail("Retrieving a RealLogger should have failed with an ArgumentNullException");
    }
    catch(ArgumentNullException)
    {
    }
}
See Also

Reference