Wednesday, December 18, 2013
Auto-mocking with AutoMoq
AutoMoq is a nice little package I came across today. The AutoMoq home page describes it as follows:
AutoMoq is an "auto-mocking" container that creates objects for you. Just tell it what class to create and it will create it.
Why is this useful? Consider the following scenario. We have a BananaCakeFactory class, that relies on a Banana Repository. Here is the constructor:
If we want to run Unit Tests on methods in BananaCakeFactory, we will have to write all the mocking code to mock IBananaRepo. That's fine.
Time goes on, our app grows more complex. Now our BananaCakeFactory needs to Sugar Repo as well...
We add mocks for our Sugar Repo, and update all our constructor calls for BananaCakeFactory. When we have a large solution, time spent adding new mocks and updating constructors really adds up. AutoMoq can take the pain away.
Here is an example of how we use AutoMoq to create a mocked class, ready for testing:
Now if we want to add our Sugar Repo, all that's needed is the following additional line:Happy Coding!
Reference URLs
Tuesday, December 10, 2013
VS2013 Web Essentials - Zen Coding is a huge time saver for web developers
...and then hit the tab key, I get:
A div has been added for me. But what if I need to add a CSS Id?
We can add a CSS class too:
Maybe we need some test data to check our layout? Zen even supports Lorem Ipsum!
This part is cool. What if we want 3 table rows, each with 2 columns? (yes, I know, you all use pure CSS now - not tables)..
If you find it isn't working after installing Web Extensions, make sure you are using the release copy of Visual Studio 2013 (the latest version of Web Extensions doesn't work with VS2013 pre-release). Let me know if you find more handy short cuts.