{"id":356,"date":"2018-11-14T15:53:00","date_gmt":"2018-11-14T02:53:00","guid":{"rendered":"https:\/\/blog.wiseowls.co.nz\/?p=356"},"modified":"2026-03-08T00:44:42","modified_gmt":"2026-03-07T11:44:42","slug":"moq-ing-around-existing-instance","status":"publish","type":"post","link":"https:\/\/blog.wiseowls.co.nz\/index.php\/2018\/11\/14\/moq-ing-around-existing-instance\/","title":{"rendered":"Moq-ing around existing instance"},"content":{"rendered":"\n<p>We love unit testing! Seriously, it makes sense if you consider how many times a simple test had saved us from having to revisit that long forgotten project we&#8217;ve already moved on from. Not fun and not good for business.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Moq: our tool of choice<\/h2>\n\n\n\n<p>To be able to only test the code we want, we need to isolate it. Of course, there&#8217;s heaps libraries for that already. <a href=\"https:\/\/github.com\/Moq\/moq4\/wiki\/Quickstart\">Moq<\/a> is just one of them. It allows of to create objects based on given interfaces and set up the expected behaviour in a way that we can abstract away all code we don&#8217;t currently test. Extremely powerful tool<\/p>\n\n\n\n<p>Sometimes you just need a bit more of that<\/p>\n\n\n\n<p>Suppose we&#8217;re testing a object that depends on internal state that&#8217;s tricky to abstract away. We&#8217;d however like to use Mock to replace one operation without changing the others:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"csharp\" class=\"language-csharp\">public class A\n{\n    public string Test {get;set;}\n    public virtual string ReturnTest() => Test;\n}\n\/\/and some code below:\nvoid Main()\n{\n    var config = new A() {\n        Test = \"TEST\"\n    } ;\n\n    var mockedConfig = new Mock&lt;A>(); \/\/ first we run a stock standard mock\n    mockedConfig.CallBase = true; \/\/ we will enable CallBase just to point out that it makes no difference  \n    var o = mockedConfig.Object;\n    Console.WriteLine(o.ReturnTest()); \/\/ this will be null because Test has not been initialised from constructor\n    mockedConfig.Setup(c => c.ReturnTest()).Returns(\"mocked\"); \/\/ of course if you set up your mocks - you will get the value\n    Console.WriteLine(o.ReturnTest()); \/\/ this will be \"mocked\" now, no surprises\n}<\/code><\/pre>\n\n\n\n<p>The code above illustrates the problem quite nicely. You&#8217;ll know if this is your case when you see it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">General sentiment towards these problems<\/h2>\n\n\n\n<p>&#8220;It can&#8217;t be done, use something else&#8221;, they say. Some people on StackOverflow suggest to ditch Moq completely and go for it&#8217;s underlying technology <a href=\"http:\/\/www.castleproject.org\/projects\/dynamicproxy\/\">Castle DynamicProxy<\/a>. And it is a valid idea &#8211; create a proxy class around yours and intercept calls to the method under test. Easy!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Kinda easy<\/h2>\n\n\n\n<p>One advantage or Moq (which is by the way built on top of Castle DynamicProxy) is that it&#8217;s not just creating mock objects, but also tracks invocations and allows us to verify those later. Of course, we could opt to write the reuiqred bits ourselves, but why reinvent the wheel and introduce so much code that no one will maintain?<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How about we mix and match?<\/h2>\n\n\n\n<p>We know that Moq internally leverages&nbsp;Castle DynamicProxy&nbsp;and it actually allows us to generate proxies for instances (they call it&nbsp;<a href=\"https:\/\/github.com\/castleproject\/Core\/blob\/master\/docs\/dynamicproxy-kinds-of-proxy-objects.md#composition-based\">Class proxy with target<\/a>). Therefore the question is &#8211; how do we get&nbsp;Moq&nbsp;to make one for us. It seems there&#8217;s no such option out of the box, and simply injecting the override didn&#8217;t quite go well as there&#8217;s not much inversion of control inside the library and most of the types and properties are marked as&nbsp;<strong>internal<\/strong>, making inheritance virtually impossible.<\/p>\n\n\n\n<p><strong>Castle Proxy<\/strong>&nbsp;is however much more user firendly and has quite a few methods exposed and available for overriding. So let us define a&nbsp;<strong>ProxyGenerator<\/strong>&nbsp;class that would take the method&nbsp;<strong>Moq&nbsp;<\/strong>calls and add required functionality to it (just compare&nbsp;<a href=\"https:\/\/github.com\/castleproject\/Core\/blob\/master\/src\/Castle.Core\/DynamicProxy\/ProxyGenerator.cs#L1156\"><strong>CreateClassProxyWithTarget<\/strong><\/a>&nbsp;and&nbsp;<a href=\"https:\/\/github.com\/castleproject\/Core\/blob\/master\/src\/Castle.Core\/DynamicProxy\/ProxyGenerator.cs#L1420\"><strong>CreateClassProxy<\/strong><\/a>&nbsp;implementations &#8211; they are almost identical!)<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">MyProxyGenerator.cs<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"csharp\" class=\"language-csharp\">class MyProxyGenerator : ProxyGenerator\n{\n    object _target;\n\n    public MyProxyGenerator(object target) {\n        _target = target; \/\/ this is the missing piece, we'll have to pass it on to Castle proxy\n    }\n    \/\/ this method is 90% taken from the library source. I only had to tweak two lines (see below)\n    public override object CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, object[] constructorArguments, params IInterceptor[] interceptors)\n    {\n        if (classToProxy == null)\n        {\n            throw new ArgumentNullException(\"classToProxy\");\n        }\n        if (options == null)\n        {\n            throw new ArgumentNullException(\"options\");\n        }\n        if (!classToProxy.GetTypeInfo().IsClass)\n        {\n            throw new ArgumentException(\"'classToProxy' must be a class\", \"classToProxy\");\n        }\n        CheckNotGenericTypeDefinition(classToProxy, \"classToProxy\");\n        CheckNotGenericTypeDefinitions(additionalInterfacesToProxy, \"additionalInterfacesToProxy\");\n        Type proxyType = CreateClassProxyTypeWithTarget(classToProxy, additionalInterfacesToProxy, options); \/\/ these really are the two lines that matter\n        List&lt;object> list =  BuildArgumentListForClassProxyWithTarget(_target, options, interceptors);       \/\/ these really are the two lines that matter\n        if (constructorArguments != null &amp;&amp; constructorArguments.Length != 0)\n        {\n            list.AddRange(constructorArguments);\n        }\n        return CreateClassProxyInstance(proxyType, list, classToProxy, constructorArguments);\n    }\n}<\/code><\/pre>\n\n\n\n<p>if all of the above was relativaly straightforward, actually feeding it into&nbsp;<strong>Moq&nbsp;<\/strong>is going to be somewhat of a hack. As I mentioned, most of the structures are marked&nbsp;<strong>internal&nbsp;<\/strong>so we&#8217;ll have to use reflection to get through:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">MyMock.cs<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"csharp\" class=\"language-csharp\">public class MyMock&lt;T> : Mock&lt;T>, IDisposable where T : class\n{\n    void PopulateFactoryReferences()\n    {\n        \/\/ Moq tries ridiculously hard to protect their internal structures - pretty much every class that could be of interest to us is marked internal\n        \/\/ All below code is basically serving one simple purpose = to swap a `ProxyGenerator` field on the `ProxyFactory.Instance` singleton\n        \/\/ all types are internal so reflection it is\n        \/\/ I will invite you to make this a bit cleaner by obtaining the `_generatorFieldInfo` value once and caching it for later\n        var moqAssembly = Assembly.Load(nameof(Moq));\n        var proxyFactoryType = moqAssembly.GetType(\"Moq.ProxyFactory\");\n        var castleProxyFactoryType = moqAssembly.GetType(\"Moq.CastleProxyFactory\");     \n        var proxyFactoryInstanceProperty = proxyFactoryType.GetProperty(\"Instance\");\n        _generatorFieldInfo = castleProxyFactoryType.GetField(\"generator\", BindingFlags.NonPublic | BindingFlags.Instance);     \n        _castleProxyFactoryInstance = proxyFactoryInstanceProperty.GetValue(null);\n        _originalProxyFactory = _generatorFieldInfo.GetValue(_castleProxyFactoryInstance);\/\/save default value to restore it later\n    }\n\n    public MyMock(T targetInstance) {       \n        PopulateFactoryReferences();\n        \/\/ this is where we do the trick!\n        _generatorFieldInfo.SetValue(_castleProxyFactoryInstance, new MyProxyGenerator(targetInstance));\n    }\n\n    private FieldInfo _generatorFieldInfo;\n    private object _castleProxyFactoryInstance;\n    private object _originalProxyFactory;\n\n    public void Dispose()\n    {\n         \/\/ you will notice I opted to implement IDisposable here. \n         \/\/ My goal is to ensure I restore the original value on Moq's internal static class property in case you will want to mix up this class with stock standard implementation\n         \/\/ there are probably other ways to ensure reference is restored reliably, but I'll leave that as another challenge for you to tackle\n        _generatorFieldInfo.SetValue(_castleProxyFactoryInstance, _originalProxyFactory);\n    }\n}<\/code><\/pre>\n\n\n\n<p>Then, given we&#8217;ve got the above working, the actual solution would look like so:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"csharp\" class=\"language-csharp\">    var config = new A()\n    {\n        Test = \"TEST\"\n    };\n    using (var superMock = new MyMock&lt;A>(config)) \/\/ now we can pass instances!\n    {\n        superMock.CallBase = true; \/\/ you still need this, because as far as Moq is oncerned it passes control over to CastleDynamicProxy   \n        var o1 = superMock.Object;\n        Console.WriteLine(o1.ReturnTest()); \/\/ but this should return TEST\n    }<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>We love unit testing! Seriously, it makes sense if you consider how many times a simple test had saved us from having to revisit that long forgotten project we&#8217;ve already moved on from. Not fun and not good for business. Moq: our tool of choice To be able to only test the code we want, &hellip; <a href=\"https:\/\/blog.wiseowls.co.nz\/index.php\/2018\/11\/14\/moq-ing-around-existing-instance\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Moq-ing around existing instance&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":360,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[11],"tags":[12,24],"class_list":["post-356","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dev","tag-c","tag-moq"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Moq-ing around existing instance - Timur and associates<\/title>\n<meta name=\"description\" content=\"Moq lets you mock interfaces, but what about wrapping an existing object? Here&#039;s how to selectively override methods.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blog.wiseowls.co.nz\/index.php\/2018\/11\/14\/moq-ing-around-existing-instance\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Moq-ing around existing instance - Timur and associates\" \/>\n<meta property=\"og:description\" content=\"Moq lets you mock interfaces, but what about wrapping an existing object? Here&#039;s how to selectively override methods.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blog.wiseowls.co.nz\/index.php\/2018\/11\/14\/moq-ing-around-existing-instance\/\" \/>\n<meta property=\"og:site_name\" content=\"Timur and associates\" \/>\n<meta property=\"article:published_time\" content=\"2018-11-14T02:53:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-03-07T11:44:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/blog.wiseowls.co.nz\/wp-content\/uploads\/2020\/02\/helloquence-5fNmWej4tAA-unsplash-scaled-e1581823690656.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"2560\" \/>\n\t<meta property=\"og:image:height\" content=\"1292\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"timur\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@TimurKh\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/blog.wiseowls.co.nz\\\/index.php\\\/2018\\\/11\\\/14\\\/moq-ing-around-existing-instance\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blog.wiseowls.co.nz\\\/index.php\\\/2018\\\/11\\\/14\\\/moq-ing-around-existing-instance\\\/\"},\"author\":{\"name\":\"timur\",\"@id\":\"https:\\\/\\\/blog.wiseowls.co.nz\\\/#\\\/schema\\\/person\\\/34d0ed30d573b5bc317ea990bd2e0c59\"},\"headline\":\"Moq-ing around existing instance\",\"datePublished\":\"2018-11-14T02:53:00+00:00\",\"dateModified\":\"2026-03-07T11:44:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/blog.wiseowls.co.nz\\\/index.php\\\/2018\\\/11\\\/14\\\/moq-ing-around-existing-instance\\\/\"},\"wordCount\":500,\"image\":{\"@id\":\"https:\\\/\\\/blog.wiseowls.co.nz\\\/index.php\\\/2018\\\/11\\\/14\\\/moq-ing-around-existing-instance\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/blog.wiseowls.co.nz\\\/wp-content\\\/uploads\\\/2020\\\/02\\\/helloquence-5fNmWej4tAA-unsplash-scaled-e1581823690656.jpg\",\"keywords\":[\"c#\",\"moq\"],\"articleSection\":[\"Development\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/blog.wiseowls.co.nz\\\/index.php\\\/2018\\\/11\\\/14\\\/moq-ing-around-existing-instance\\\/\",\"url\":\"https:\\\/\\\/blog.wiseowls.co.nz\\\/index.php\\\/2018\\\/11\\\/14\\\/moq-ing-around-existing-instance\\\/\",\"name\":\"Moq-ing around existing instance - Timur and associates\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blog.wiseowls.co.nz\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/blog.wiseowls.co.nz\\\/index.php\\\/2018\\\/11\\\/14\\\/moq-ing-around-existing-instance\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/blog.wiseowls.co.nz\\\/index.php\\\/2018\\\/11\\\/14\\\/moq-ing-around-existing-instance\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/blog.wiseowls.co.nz\\\/wp-content\\\/uploads\\\/2020\\\/02\\\/helloquence-5fNmWej4tAA-unsplash-scaled-e1581823690656.jpg\",\"datePublished\":\"2018-11-14T02:53:00+00:00\",\"dateModified\":\"2026-03-07T11:44:42+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/blog.wiseowls.co.nz\\\/#\\\/schema\\\/person\\\/34d0ed30d573b5bc317ea990bd2e0c59\"},\"description\":\"Moq lets you mock interfaces, but what about wrapping an existing object? Here's how to selectively override methods.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/blog.wiseowls.co.nz\\\/index.php\\\/2018\\\/11\\\/14\\\/moq-ing-around-existing-instance\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/blog.wiseowls.co.nz\\\/index.php\\\/2018\\\/11\\\/14\\\/moq-ing-around-existing-instance\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/blog.wiseowls.co.nz\\\/index.php\\\/2018\\\/11\\\/14\\\/moq-ing-around-existing-instance\\\/#primaryimage\",\"url\":\"https:\\\/\\\/blog.wiseowls.co.nz\\\/wp-content\\\/uploads\\\/2020\\\/02\\\/helloquence-5fNmWej4tAA-unsplash-scaled-e1581823690656.jpg\",\"contentUrl\":\"https:\\\/\\\/blog.wiseowls.co.nz\\\/wp-content\\\/uploads\\\/2020\\\/02\\\/helloquence-5fNmWej4tAA-unsplash-scaled-e1581823690656.jpg\",\"width\":2560,\"height\":1292},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/blog.wiseowls.co.nz\\\/index.php\\\/2018\\\/11\\\/14\\\/moq-ing-around-existing-instance\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/blog.wiseowls.co.nz\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Moq-ing around existing instance\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/blog.wiseowls.co.nz\\\/#website\",\"url\":\"https:\\\/\\\/blog.wiseowls.co.nz\\\/\",\"name\":\"Timur and associates\",\"description\":\"Notes of an IT contractor\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/blog.wiseowls.co.nz\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/blog.wiseowls.co.nz\\\/#\\\/schema\\\/person\\\/34d0ed30d573b5bc317ea990bd2e0c59\",\"name\":\"timur\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/23d55e17d4f0990ee4d12bc6e5dcfb58a292934efd62a185756876379e780b16?s=96&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/23d55e17d4f0990ee4d12bc6e5dcfb58a292934efd62a185756876379e780b16?s=96&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/23d55e17d4f0990ee4d12bc6e5dcfb58a292934efd62a185756876379e780b16?s=96&r=pg\",\"caption\":\"timur\"},\"sameAs\":[\"https:\\\/\\\/x.com\\\/TimurKh\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Moq-ing around existing instance - Timur and associates","description":"Moq lets you mock interfaces, but what about wrapping an existing object? Here's how to selectively override methods.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blog.wiseowls.co.nz\/index.php\/2018\/11\/14\/moq-ing-around-existing-instance\/","og_locale":"en_US","og_type":"article","og_title":"Moq-ing around existing instance - Timur and associates","og_description":"Moq lets you mock interfaces, but what about wrapping an existing object? Here's how to selectively override methods.","og_url":"https:\/\/blog.wiseowls.co.nz\/index.php\/2018\/11\/14\/moq-ing-around-existing-instance\/","og_site_name":"Timur and associates","article_published_time":"2018-11-14T02:53:00+00:00","article_modified_time":"2026-03-07T11:44:42+00:00","og_image":[{"width":2560,"height":1292,"url":"https:\/\/blog.wiseowls.co.nz\/wp-content\/uploads\/2020\/02\/helloquence-5fNmWej4tAA-unsplash-scaled-e1581823690656.jpg","type":"image\/jpeg"}],"author":"timur","twitter_card":"summary_large_image","twitter_creator":"@TimurKh","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blog.wiseowls.co.nz\/index.php\/2018\/11\/14\/moq-ing-around-existing-instance\/#article","isPartOf":{"@id":"https:\/\/blog.wiseowls.co.nz\/index.php\/2018\/11\/14\/moq-ing-around-existing-instance\/"},"author":{"name":"timur","@id":"https:\/\/blog.wiseowls.co.nz\/#\/schema\/person\/34d0ed30d573b5bc317ea990bd2e0c59"},"headline":"Moq-ing around existing instance","datePublished":"2018-11-14T02:53:00+00:00","dateModified":"2026-03-07T11:44:42+00:00","mainEntityOfPage":{"@id":"https:\/\/blog.wiseowls.co.nz\/index.php\/2018\/11\/14\/moq-ing-around-existing-instance\/"},"wordCount":500,"image":{"@id":"https:\/\/blog.wiseowls.co.nz\/index.php\/2018\/11\/14\/moq-ing-around-existing-instance\/#primaryimage"},"thumbnailUrl":"https:\/\/blog.wiseowls.co.nz\/wp-content\/uploads\/2020\/02\/helloquence-5fNmWej4tAA-unsplash-scaled-e1581823690656.jpg","keywords":["c#","moq"],"articleSection":["Development"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/blog.wiseowls.co.nz\/index.php\/2018\/11\/14\/moq-ing-around-existing-instance\/","url":"https:\/\/blog.wiseowls.co.nz\/index.php\/2018\/11\/14\/moq-ing-around-existing-instance\/","name":"Moq-ing around existing instance - Timur and associates","isPartOf":{"@id":"https:\/\/blog.wiseowls.co.nz\/#website"},"primaryImageOfPage":{"@id":"https:\/\/blog.wiseowls.co.nz\/index.php\/2018\/11\/14\/moq-ing-around-existing-instance\/#primaryimage"},"image":{"@id":"https:\/\/blog.wiseowls.co.nz\/index.php\/2018\/11\/14\/moq-ing-around-existing-instance\/#primaryimage"},"thumbnailUrl":"https:\/\/blog.wiseowls.co.nz\/wp-content\/uploads\/2020\/02\/helloquence-5fNmWej4tAA-unsplash-scaled-e1581823690656.jpg","datePublished":"2018-11-14T02:53:00+00:00","dateModified":"2026-03-07T11:44:42+00:00","author":{"@id":"https:\/\/blog.wiseowls.co.nz\/#\/schema\/person\/34d0ed30d573b5bc317ea990bd2e0c59"},"description":"Moq lets you mock interfaces, but what about wrapping an existing object? Here's how to selectively override methods.","breadcrumb":{"@id":"https:\/\/blog.wiseowls.co.nz\/index.php\/2018\/11\/14\/moq-ing-around-existing-instance\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blog.wiseowls.co.nz\/index.php\/2018\/11\/14\/moq-ing-around-existing-instance\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blog.wiseowls.co.nz\/index.php\/2018\/11\/14\/moq-ing-around-existing-instance\/#primaryimage","url":"https:\/\/blog.wiseowls.co.nz\/wp-content\/uploads\/2020\/02\/helloquence-5fNmWej4tAA-unsplash-scaled-e1581823690656.jpg","contentUrl":"https:\/\/blog.wiseowls.co.nz\/wp-content\/uploads\/2020\/02\/helloquence-5fNmWej4tAA-unsplash-scaled-e1581823690656.jpg","width":2560,"height":1292},{"@type":"BreadcrumbList","@id":"https:\/\/blog.wiseowls.co.nz\/index.php\/2018\/11\/14\/moq-ing-around-existing-instance\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blog.wiseowls.co.nz\/"},{"@type":"ListItem","position":2,"name":"Moq-ing around existing instance"}]},{"@type":"WebSite","@id":"https:\/\/blog.wiseowls.co.nz\/#website","url":"https:\/\/blog.wiseowls.co.nz\/","name":"Timur and associates","description":"Notes of an IT contractor","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blog.wiseowls.co.nz\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blog.wiseowls.co.nz\/#\/schema\/person\/34d0ed30d573b5bc317ea990bd2e0c59","name":"timur","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/23d55e17d4f0990ee4d12bc6e5dcfb58a292934efd62a185756876379e780b16?s=96&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/23d55e17d4f0990ee4d12bc6e5dcfb58a292934efd62a185756876379e780b16?s=96&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/23d55e17d4f0990ee4d12bc6e5dcfb58a292934efd62a185756876379e780b16?s=96&r=pg","caption":"timur"},"sameAs":["https:\/\/x.com\/TimurKh"]}]}},"_links":{"self":[{"href":"https:\/\/blog.wiseowls.co.nz\/index.php\/wp-json\/wp\/v2\/posts\/356","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.wiseowls.co.nz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.wiseowls.co.nz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.wiseowls.co.nz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.wiseowls.co.nz\/index.php\/wp-json\/wp\/v2\/comments?post=356"}],"version-history":[{"count":8,"href":"https:\/\/blog.wiseowls.co.nz\/index.php\/wp-json\/wp\/v2\/posts\/356\/revisions"}],"predecessor-version":[{"id":366,"href":"https:\/\/blog.wiseowls.co.nz\/index.php\/wp-json\/wp\/v2\/posts\/356\/revisions\/366"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.wiseowls.co.nz\/index.php\/wp-json\/wp\/v2\/media\/360"}],"wp:attachment":[{"href":"https:\/\/blog.wiseowls.co.nz\/index.php\/wp-json\/wp\/v2\/media?parent=356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.wiseowls.co.nz\/index.php\/wp-json\/wp\/v2\/categories?post=356"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.wiseowls.co.nz\/index.php\/wp-json\/wp\/v2\/tags?post=356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}