c# - Unit Testing - Resolution of the dependency failed -
c# - Unit Testing - Resolution of the dependency failed -
i'm new unit testing. wanted unit test existing webapi controller. within controller, i'm resolving dependencies using unitycontainer.
while running test case, getting exception
microsoft.practices.unity.resolutionfailedexception: resolution of dependency failed
can guide me resolve dependency? in advance!!
class="lang-cs prettyprint-override">public class pqcontroller : apicontroller { public ihttpactionresult getbyid(int pqid) { if (!isvalidpqids || sourceid <= 0) { homecoming badrequest(); } iunitycontainer container = new unitycontainer(); container.registertype<ipqadapter, pqadapterdesktop>(); var pqdesktopadapter = container.resolve<ipqadapter>(); var pq = pqdesktopadapter.getpqbyids<pqdesktop>(pqid); homecoming ok(pq); } }
test code:
class="lang-cs prettyprint-override">[testclass] public class testpricequotecontroller { [testmethod] public void get_pricequoebyid_should_return_valid_pricequote() { var pqcontroller = new pqcontroller(); // deed ihttpactionresult actionresult = pqcontroller.getbyid(55560); var contentresult = actionresult oknegotiatedcontentresult<pqdesktop>; // assert assert.isnotnull(contentresult); assert.isnotnull(contentresult.content); assert.areequal(55560, contentresult.content.pqid); } }
c# unit-testing asp.net-web-api controller unity-container
Comments
Post a Comment