--
You received this message because you are subscribed to the Google Groups "NSubstitute" group.
To post to this group, send email to nsubs...@googlegroups.com.
To unsubscribe from this group, send email to nsubstitute...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nsubstitute?hl=en.
On Mon, Nov 8, 2010 at 4:09 PM, Simon Cropp <simon...@gmail.com> wrote:
> Cant think of a way to fix DP2
>
> But you could have a helper method that validates peoples unit tests.
> Attached is a proof of concept using Mono Cecil.
what you are suggesting would involve the following
1 a stack walk to get the calling method (Easy)
2 somehow map that location in the stack to an IL instruction (Not
sure how difficult)
3 check forward in the IL to see if the next call is on a non virtual
method (Easy)
Off the top of my head I am not sure how to do step 2 but all the
information is there so with a big enough hammer it should be
possible.
As for "crazily slow". I think after the first call it would be
feasible. But the first call would be expensive. The initial parse of
the assemblies IL as well as loading all the required types would mean
the first time u do this check it would add some fairly significant
time. I know I am talking in relative terms so let me try to equate it
to some real numbers. My machine is a 2.8GHz I7. With my initial
sample from the attachment the execution takes 200ms for a first run.
0ms (after rounding down) for a second run. So you suggestion should
be possible in under a ms per call. But are u willing to take the
initial hit?
You could have an API that people should call at startup that
"Initialises" everything. But if u are forcing them to do this u may
as well just do the testing at that point as per my initial
suggestion.
Of course the bigger hammer is to just take the target assembly and
change all instance members to virtual using Cecil. :)
I had a chat to philiplaureano on twitter and it looks like LinFu AOP
wont work for you either. It basically re-writes the target assembly
at post build time. So you would be forcing a hard dependency on Linfu
whenever someone wants to use NSubstitute ie their real production
code needs to be processed by linfu to make it unit testable. Not
something you would want?? And the scenario where you want to mock a
type from a 3rd party assembly is even more complicated.
And I agree with you "I just want to reference a DLL and go". I really
like that I dont need have anything installed or hack proj files to
get nsubstitute work.
I think the first step it would suffice to tell people when they are
mocking something that is not virtual.