MOQ
No i am not mocking you!!. MOQ is a mocking framework for .net and can be downloaded here.
What is a mocking framework?
It is basically a small piece of software that simulates the behavior of an interface, it is generally used for creating unit tests.
Confused??? let us just visualise a problem. let us visualise it as if you encountered it.
A Story to start using MOQ
You have a requirement to design a code generation application, for which you will be using some xml files with data required to generate the code. Now you get into work, do a lot of RND, work your brain day in and out and finish the code generation.
To test this out you write over 200 xml files and run your code, the code generation just takes 10 mins. Wow great, an entire application in 10 mins,
Your team lead is impressed, he calls out for your manager, he comes over take a look and says, "Hey the application looks great but you have forgotten to put the Billing address for the customer". You smile and say "Just a minute" and while the manager is there you make a slight change in the xml file and click generate. Voila in another 10 minutes, the issue is fixed. The manager is head over heels and you are sure of your next hike.
Next day the manager calls you into the room and says "Man you are great!! and that work is so good that i am going to use it in my next meeting with the client. So get ready for the trip."
You are excited, tell your friends about it, make purchases for the trip and the next moment you are sitting with your manager in the flight. The next day at
the client site, you and your manager stride up to the clients office. The client invites you inside, the manager introduces himself and then says "Hey Bill, this is John, the most talented developer in my company and we are here to solve your problems and that too in real time".
You feel your head swelling with pride and you are quickly in the clouds though not the azure ones...
Your manager then starts the demo of the application, the client is impressed, then suddenly he squints and then roars "Hey don't you know english? Customer is spelled "CUSTOMER" not "CSUTOMER". You curse him in your mind, "hey that is a typing error, why the hell doesn't he understand". Your manager soothes the customer and says "Hey that is a normal typing error, give me 10 minutes" and your manager glances at you. You quickly open a xml file make the necessary changes and click generate, 10 minutes down the lane, the generation screen closes, your manager wipes off the hint of sweat forming on his head and says "Bill, it is ready". The client is impressed, "Good finally you seem to have learnt programming".
The demo is then again in progress, yet again as usual the client gets hold of another issue, you smile, tweak your xml files and the
demo continues. After 3-4 cycles of this same thing, you start noticing that the smile of your manager is slowly changing into a frown, and then Bill gets up and says "Guys! do one thing, will you just run over the application, make the required fixes and then get back, i just remembered i have a meeting with my boss.".
You and your manager slowly packup your laptops and then go back to room, on the way back, you have lunch. Your manager doesn't talk much, you too
feel the pressure. After lunch while trudging back to the room, your manager says, "Hmmm... That was a bad meeting, i thought we would close it for once and
all. now i dont know how long it is going to take, John, can we do one thing, can we make this code generation faster?", you stop in your tracks and think,
"In 10 minutes we are doing what 5-6 people did in 3 months time that too with more bugs & issues, and now he thinks 10 minutes is too much... ", you think for sometime and say "Maybe there is a way, i will check and see what can be done". Then you both re-enter into silence and go to your room.
You go, open the fridge, grab a can of beer. Still you cannot take your mind off things. to cool off a shower should be good, you quickly go in and take a
shower, now beneath the shower you start thinking about the issue, suddenly everything falls into place, Why generate all the 200 files, why not just generate the files that are modified? yes why not. Looking back, now it looks silly, you had been such a stupid idiot. You run into your room, take the laptop and begin coding.....