hey Roy, first off... I watched your videos on Unit testing, a little harsh, but ultimately good b/c better testing practices == better code out there... nice work.
secondly, I just had a discussion with one of the techs at TypeMock about using it to do IoC and AOP on external libraries (with post-compilation headaches), and he directed me here. Looks like i'm in the right place. I figured you might be interested in
the discussion (I omitted the tech's name to respect his/her privacy)
Thanks <<TypeMock Tech>>,
The CThru project looks really interesting. I’ll take a closer look at that, though it seems to be too early in alpha stages to be considered for a production level project. I’d still like to watch how it progresses, and perhaps contribute too.
By the way… I think it was watching Roy’s screencasts on unit testing that got me looking at TypeMock in the first place… small world.
Thanks again… it’s nice to see this level of help from the community.
/~~> t-dizzle <~~\
I will answer your questions, but first have a look at CThru, an open-source project built on top of Isolator. It is an AOP engine, so you can do exactly what you described. And the reason we're the only one doing it (apart from the patent of course) is
that it took 2 years to get there. It's just too hard.
- The change is not persistent. It's done only at runtime, so nothing done then is persisted.
- No, the hooks are only at the C++ level. No managed profilers, since well, they tie into the CLR loader.
- You can use the Isolate.WhenCalled().DoInstead() method. The DoInstead clause gets parameters and reference to the object whose method is running. So at runtime you can do custom code based on these parameters. Read more here.
If you'r looking for an AOP solution, CThru is your best bet, since it allows put hooks into everything. Let me know if you need further questions.
Hi <<TypeMock Tech>>,
Thanks for your response. I found TypeMock while hunting around for better unit testing procedures. I like how TypeMock enables things happening behind the scenes in a test to not have to specifically have “mock” objects injected into them,
the Isolater seems to intercept “normal” C# code (i.e. if some test requires underlying objects to be configured, TypeMock allows you to do that entirely within the test code).
Your simple explanation seems to be exactly what I was looking to do. It’s targeted at a project that would only be used internally by my company, so in response to your question, no it’s not published. What I was trying to do was introduce an AOP element
to external pre-compiled assemblies (containing pluggable services) without having to modify the source classes to derive from ContextBoundObject or markup the methods with advice attributes. From what I understand, this can only be done using hooks in the
profiling (or debugger API) and using some type of “Reflection.Emit” block to generate dynamic proxy methods with the interceptors built in. Everything I’ve seen either requires modifying the source of the external library, or running some type of post-compilation
tool, making the dependency injection a build time activity instead of something that can be configured per app and made use of at runtime. What I really want, is the ability to intercept ANY method call on ANY class loaded in the runtime, and call my own
code either prior to entering or just prior to exiting the method. It sounds like you guys do something like that, and so I can understand protecting your secret, as it doesn’t seem to be a menial task. Maybe you guys could roll that type of functionality
into another product, specifically targeting the “AOP/IoC/Dependency Injection” mantra.
When the methods get transformed, is the change persisted in the current appdomain, or does the process happen every time a targeted method is called?
Are there .NET level hooks for the JIT events, or is that done at a C++/Win32 level?
Is there a way for the Isolater to run stubs around the method being intercepted (getting passed the arguments of the original call), while still calling the original method? Or does it just replace the call with the mock body?
/~~> t-dizzle <~~\
Nice to meet you. My name is <<TypeMock Tech>> and I'm a <<TypeMock Tech>>.
You can download Isolator for open source projects here. You need it if your open source project includes unit tests using Isolator. Then anyone who wants to contribute can use Isolator to run the tests, and that license is free.
While we can't show you the code, here's a quick overview of how Isolator works:
Isolator is a profiler. It's a DLL that's loaded in to the test runner process (NUnit, MSTest) and listens to the JITting events. Every method, when JITted gets its IL transformed so it goes through Isolator at runtime. So when a method gets called, prior to
running the original call Isolator gets a chance to intervene and change its behavior. It's a very simple explanation, with a lot of work under the covers.
This way, we can fake any method and any type, because we're working at the lowest level possible.
Let me know if you want to discuss this further.
May I ask- is your project already published? And how did you hear about Typemock in the first place?
Thanks… I appreciate it.
/~~> t-dizzle <~~\
I'm not in the habit of ignoring emails, certainly not ones like yours (Nigerian entrepreneurs have less luck :)).
Typemock Isolator isn't open source, but we do have a free license for developers working on open source if that's any help. I'll put you in touch with our technical evangelist, and we'll see what we can do to help out.
<<TypeMock Sales Guy>>
Is TypeMock open source? If so, how can I get the source code… it’s for personal evaluation use, I’m trying to do some runtime DI stuff, and am interested how TypeMock hijacks the .NET type system and intercepts methods on non ContextBound objects. If I’m way
off base… you can just ignore this.
/~~> t-dizzle <~~\