I am trying to mock UnityContainer for writing test harness in an asp.net mvc 2 application.
are there any examples available ?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Simple Answer: Don’t. The container should be invisible to your controllers or anything else you need to test. If it is leaking into your code then you’re probably using it incorrectly and should think about redesigning your code.
That said, if you really, really need to then reference the UnityContainerBase abstract class in your code instead of the UnityContainer class itself. You’ll still be able to pass in the normal UnityContainer object when your application is running, but you’ll also be able to get RhinoMocks to generate a mock of UnityContainerBase to pass in when you are running unit tests.