Verifying non–public methods have been called using Typemock Isolator in VB.Net

I am currently writing some training material for a client on mocking showing how life is so much easier if software is designed with testing in mind. As part of this material I showing that though we aim for nice design patterns which allow testing we have to deal with legacy systems that were not designed this way. However, there are tools that allow us to write unit tests for poorly designed (with testing in mind) legacy systems, specifically Typemock Isolator. Using Isolator means we can write tests that we can use to make sure the code is not broken whilst refactoring to new structures.

Just to add a bit of interest the material needs to be in VB.NET not my usual language, so I have spent some time porting the demos I use at conference sessions on Isolator from C# to VB.NET.

Whilst doing this I had to get used to the fact that  the Typemock syntax used in VB in a different C#. Using ‘using’ blocks for most things, so the C# lamda expression syntax

1Isolate.Verify.WasCalledWithExactArguments(() => fake.IsEmailAddessInDB.SendEmail(“fred@home.com"));   

becomes

 1Using AssertCalls.HappenedWithExactArguments()   
 2     fake.IsEmailAddessInDB("fred@home.com") End Using
 3```
 4
 5But this is not an issue I had. The problem was that I was trying to show a real worst case where you need to mock private methods. One the [dirtiest tricks](http://blogs.blackmarble.co.uk/blogs/rfennell/archive/2009/05/24/everytime-i-have-to-use-typemock-i-need-to-ask-does-my-code-stinks.aspx) of Isolator. Setting up the non-public Isolator behaviour is easy in VB
 6
 7```
 8Isolator.VisualBasic.NonPublicWillReturn (fakeProcessor, "GetOrderForClient",fakeOrder) Isolator.VisualBasic.NonPublicWillBeIgnored(fakeProcessor, "SendEmail")
 9```
10
11Problem is there seems to be no non-public verify methods in the Isolator VB syntax. I found an [old forum post on the subject](http://forums.typemock.com/viewtopic.php?p=5714), but nothing since. However, I did find [answer hinted at in another post](http://forums.typemock.com/viewtopic.php?t=1140&view=previous), but it might be a bit obscure if you are new to Isolator. The process is as follows
12
131.  In your test project as well as the references to **Typemock**  and **Typemock.Isolator.VisualBasic** also add one to the C# Isolator API **Typemock.ActAssertArrange**
142.  You can now use the C# methods to do the job. So the verification becomes
15
16```
17TypeMock.ArrangeActAssert.Isolate.Verify.NonPublic.WasCalled(fakeProcessor, "GetOrderForClient") TypeMock.ArrangeActAssert.Isolate.Verify.NonPublic.WasCalled(fakeProcessor, "SendEmail").WithArguments(“abc@home.com")       
18```
19
20Now don’t think for a second I am suggesting it is a good idea to be mocking private methods, or frankly using any of the Isolator dirty tricks. I still think if you find yourself using any of the Isolator features that all the other mocking frameworks cannot do then you seriously need to look at your code bases design. However, there are just cases when you can’t change the design and the use of Isolator is the only option you have if you wish to write any tests. In these cases it is great to a tool to give at least some test coverage.