If you cannot use TypeMock to intercept a method call, it is recommended that you use a template to create a proxy server that redirects to non-virtual or static methods that interest you during testing, and then set the expected value for the proxy server. To illustrate, consider the following classes.
class TypeToTest { public void Method() { } } interface ITypeToTest { void Method(); } class TypeToTestProxy : ITypeToTest { TypeToTest m_type = new TypeToTest(); public void Method() { m_type.Method(); } }
By creating this proxy, you can now use ITypeToTest instead of where you went or installed an instance of TypeToTest , making sure that the default implementation uses TypeToTestProxy as it moves toward the actual implementation. Then you can create the ITypeToTest layout in the test code and set the expectations accordingly.
Please note that creating these proxies can be very tedious, error prone and time consuming. For this, I maintain a library and a set of tools that generate assemblies for you that contain these types. See this page for more details.
Steve Guidi Dec 24 '09 at 21:14 2009-12-24 21:14
source share