I'm not even sure if there is a utility that allows this, but it seems like such a common need?
Is there a program/library/component that will generate mocked .NET objects (repositories) that will yield some mocked data as certain database calls.
Allow me to elaborate: If I'm testing a repository (not unit testing, simply testing in a console window) and when I pass a selection criteria to my repository, it returns a list of objects. I would /love/ for an ability to capture that list of objects and convert it to static setup C# code that would serve as a setup for a unit test. My objects are quiet complex and it takes a long time to set them up properly.
Is this possible? My team is using Moq & Ninject
It can be a pain to write them by hand but you only need to get it right once. Then for each successive test you can modify the inputs. I don't know of anyway to save or capture your objects at runtime. I found a webpage that talks about automocking it MAY do what you are after. http://code.google.com/p/moq-contrib/wiki/Automocking
Cheers, Andrew
There are a couple of good ways to deal with this need.
First, you could re-examine why you want to do this. If you need to have a complex object fully configured in order to run your unit test, it could be you're trying to test too much. Complex setup is a test smell, and might (or might not) indicate that you should make a design change.
Sometimes it isn't feasible to make that kind of change, and sometimes that test smell does not really indicate a design change. In those cases, your best bet is serialize the objects (when you say "convert it to static setup C# code", that could be restated as "serialize it as C# instructions for recreating it"). There are a lot of relatively simple ways to serialize to xml, I recommend DataContract or XmlSerialization, they are both very easy to implement and use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With