{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"never","basic_auth":false,"params":[],"results":{"codes":[]},"try":true},"next":{"description":"","pages":[]},"title":"Verify a method was called on another object","type":"basic","slug":"verify-a-method-was-called-on-another-object","excerpt":"","body":"SpecsFor includes an auto-mocking container that will automatically create mock objects for you using the excellent [Moq](https://github.com/Moq/moq4) library.  You can then retrieve those mock objects and verify that a method was (or was not!) called by your system under test: \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"\\t\\t\\t[Test]\\n\\t\\t\\tpublic void then_it_calls_the_engine_factory()\\n\\t\\t\\t{\\n\\t\\t\\t\\tGetMockFor<IEngineFactory>()\\n\\t\\t\\t\\t\\t.Verify(x => x.GetEngine(\\\"V8\\\"));\\n\\t\\t\\t}\",\n      \"language\": \"csharp\"\n    }\n  ]\n}\n[/block]","updates":[],"order":3,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"5447ec908d7af31a00dd4115","createdAt":"2014-10-22T17:42:40.239Z","project":"54471fc9e12a270800028adc","is_link":false,"category":{"sync":{"isSync":false,"url":""},"pages":["5447be448d7af31a00dd406a","5447ea410319802200fc06df","5447ea600319802200fc06e3","5447ec908d7af31a00dd4115","5447ef6c0319802200fc070f","54485158c1b42e08005b82a1"],"title":"How do I...?","slug":"how-do-i","order":1,"from_sync":false,"reference":false,"_id":"5447be130319802200fc0620","project":"54471fc9e12a270800028adc","version":"54471fc9e12a270800028adf","createdAt":"2014-10-22T14:24:19.959Z","__v":6},"githubsync":"","user":"54471f91beb6320800da6f75","version":{"version":"1.0","version_clean":"1.0.0","codename":"","is_stable":true,"is_beta":false,"is_hidden":false,"is_deprecated":false,"categories":["54471fc9e12a270800028ae0","5447b9e7b96a63140077d747","5447be130319802200fc0620","5447ed118d7af31a00dd411c","5447ed230319802200fc0702","5448524c4544c30800241f41","544854504544c30800241f4d","544854af4544c30800241f50","544854e74544c30800241f51","54485557c1b42e08005b82bf"],"_id":"54471fc9e12a270800028adf","__v":10,"project":"54471fc9e12a270800028adc","releaseDate":"2014-10-22T03:08:57.750Z","createdAt":"2014-10-22T03:08:57.750Z"},"__v":1}

Verify a method was called on another object


SpecsFor includes an auto-mocking container that will automatically create mock objects for you using the excellent [Moq](https://github.com/Moq/moq4) library. You can then retrieve those mock objects and verify that a method was (or was not!) called by your system under test: [block:code] { "codes": [ { "code": "\t\t\t[Test]\n\t\t\tpublic void then_it_calls_the_engine_factory()\n\t\t\t{\n\t\t\t\tGetMockFor<IEngineFactory>()\n\t\t\t\t\t.Verify(x => x.GetEngine(\"V8\"));\n\t\t\t}", "language": "csharp" } ] } [/block]