How to mock everything?
Asked Answered
M

2

7

I understand how to mock interfaces or virtual method calls. But frameworks like TypeMock can mock everything in the framework. Which .NET mechanisms are used to provide such functions?

Multidisciplinary answered 9/9, 2010 at 21:14 Comment(0)
S
8

Typemock Isolator for example uses the CLR profiler API to intercept .NET calls and change them during runtime:

Quote:

Typemock Isolator uses an aspect-oriented programming design that creates a mock aspect. Internally, it uses the .NET Framework profiler API to monitor an application's execution. When a method is loaded by the CLR, Typemock Isolator retrieves the IL and replaces it with instrumented IL code. Typemock Isolator does not change your original IL code, it simply inserts new code that calls the Typemock Isolator framework and returns mocked values.

Sack answered 9/9, 2010 at 21:20 Comment(2)
Thanks for your reply. Could you recommend a good article about this API?Multidisciplinary
This article is a good start.Sack
M
0

Mock Everything is one of the feature for Mock frameworks. Mock everything in short is to mock everything in a class, such as

  • mock dependent objects
  • non-virtual methods
  • sealed classes
  • static methods
  • static classes
  • non-public members
  • non-public types

JustMock & TypeMock both provide this feature.

You can actually look at source code of some open source mock frameworks such as Moq framework ,Easy Mock, Rhino Mocks etc.

Disclosure: Please note that link provided is of my own website

Merchandise answered 9/10, 2013 at 8:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.