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: INonPublicMethodBehavioran INonPublicMethodBehavior interface reference
Implements
INonPublicArgHandlerWithGenericArguments(Type, Type)Remarks
Examples
[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