{"id":61,"date":"2022-01-15T12:25:02","date_gmt":"2022-01-15T12:25:02","guid":{"rendered":"https:\/\/baldsolutions.com\/?p=61"},"modified":"2022-01-16T16:34:03","modified_gmt":"2022-01-16T16:34:03","slug":"how-to-unit-test-method-invocation-that-accepts-builder-style-parameter-with-nsubstitute","status":"publish","type":"post","link":"https:\/\/baldsolutions.com\/index.php\/2022\/01\/15\/how-to-unit-test-method-invocation-that-accepts-builder-style-parameter-with-nsubstitute\/","title":{"rendered":"Unit test for a method that accepts builder-style parameter with NSubstitute"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">Introduction<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Sometimes it happens that you should write unit tests&#8230; <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Just kidding &#8211; you HAVE TO write unit tests (me as well).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In a perfect world the method we want to write a unit-test for is well-written, concise and returns concrete value. Unfortunately, there are methods that seems to be intricate in terms of unit tests, at least at first glance. Let&#8217;s consider the following scenario:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class CustomClass\n{\n    private readonly ICustomService _customService;\n\n    public CustomClass(ICustomService customService)\n    {\n        _customService = customService;\n    }\n\n    public void RunProcess(int param_1, int param_2, int param_3)\n    {\n        _customService.Run(\n            descriptorBuilder =&gt; descriptorBuilder\n                .BuildMyProperty_1(param_1)\n                .BuildMyProperty_2(param_2)\n                .BuildMyProperty_3(param_3)\n        );\n    }\n}\n\npublic interface ICustomService\n{\n    void Run(Func&lt;IDescriptor, IDescriptor&gt; descriptorBuilder);\n}\n\npublic interface IDescriptor\n{\n    public IDescriptor BuildMyProperty_1(int myProperty_1);\n    public IDescriptor BuildMyProperty_2(int myProperty_2);\n    public IDescriptor BuildMyProperty_3(int myProperty_3);\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Having class like this we want to write unit test for the <code>RunProcess<\/code> method. The method accepts three int parameters. Eventually the parameters are passed to the <code>ICustomService.Run<\/code> method that accepts builder-style parameter. Moreover, the  <code>RunProcess<\/code> returns nothing. <\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Unit test using NSubstitute<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\"><a title=\"https:\/\/nsubstitute.github.io\/\" href=\"https:\/\/nsubstitute.github.io\/\">NSubstitute<\/a> might be your best friend when it comes to mock objects and assert received calls. The syntax is succinct and intuitive so I would suggest you to consider to experiment with the library. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s build unit test in a AAA manner &#8211; arrange, act, assert &#8211; which NSubstitute is designed for.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The test name is <em>RunProcess_CustomServiceExecutedWithPassedParameters_Success<\/em>. <br>The name follows the pattern: &lt;MethodNameThatIsBeingTested&gt;_&lt;ExpectedInternalMethodBehaviour&gt;_&lt;Status&gt;.<br>I guess there are as many test naming conventions as engineers that create it. Furthermore, I believe that as long as the convention informs you well about test internals it is good enough.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"> The test looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>&#91;Fact]\npublic void RunProcess_CustomServiceExecutedWithPassedParameters_Success()\n{\n    \/\/arrange\n    var callParameters = (111, 22, 3333);\n\n    var mockDescriptor = Substitute.For&lt;IDescriptor&gt;();\n    mockDescriptor.ReturnsForAll&lt;IDescriptor&gt;(mockDescriptor); \n\n    var customService = Substitute.For&lt;ICustomService&gt;();\n    CustomClass customClass = new CustomClass(customService);\n\n    \/\/act\n    customClass.RunProcess(\n        param_1: callParameters.Item1,\n        param_2: callParameters.Item2,\n        param_3: callParameters.Item3\n    );\n\n    \/\/assert\n    customService\n        .Received(1)\n        .Run(Arg.Is&lt;Func&lt;IDescriptor, IDescriptor&gt;&gt;(\n                descriptorBuilder =&gt; AssertDescriptorFunc(\n                    descriptorBuilder,\n                    mockDescriptor,\n                    callParameters\n                )\n            )\n        );\n}\n\nprivate bool AssertDescriptorFunc(\n    Func&lt;IDescriptor, IDescriptor&gt; descriptorFunc,\n    IDescriptor mockDescriptor,\n    (int, int, int) callParameters\n)\n{\n    descriptorFunc(mockDescriptor);\n\n    mockDescriptor.Received(1).BuildMyProperty_1(callParameters.Item1);\n    mockDescriptor.Received(1).BuildMyProperty_2(callParameters.Item2);\n    mockDescriptor.Received(1).BuildMyProperty_3(callParameters.Item3);\n\n    return true;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s briefly summarize what has happened up there. The test asserts that after the <code>customClass.RunProcess<\/code> invocation the <code>customService.Run<\/code> method received exactly one call. The invocation happened with exactly one parameter. The parameter was type of <code>Func&lt;IDescriptor,IDescriptor&gt;<\/code> and then was asserted using <code>AssertDescriptorFunc<\/code> method.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Summary<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">To sum up, thanks to the NSubstitute library we are able to write unit test even for such an unusual scenario. NSubstitute offers much more than I&#8217;ve just presented here. I highly recommend to check the  NSubstitute documentation and spend some time on playing with its functionalities.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you want to give it a try you can find attached scenario in my <a href=\"https:\/\/github.com\/tglowka\/baldsolutions\/tree\/master\/.NET\" title=\"https:\/\/github.com\/tglowka\/baldsolutions\/tree\/master\/.NET\" target=\"_blank\" rel=\"noreferrer noopener\">github<\/a>, project: nsubstitute_1, test project: nsubstitute_1-test.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"> Have a nice day, bye!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Sometimes it happens that you should write unit tests&#8230; Just kidding &#8211; you HAVE TO write unit tests (me as well). In a perfect&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/baldsolutions.com\/index.php\/2022\/01\/15\/how-to-unit-test-method-invocation-that-accepts-builder-style-parameter-with-nsubstitute\/\">Continue reading<span class=\"screen-reader-text\">Unit test for a method that accepts builder-style parameter with NSubstitute<\/span><\/a><\/div>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-61","post","type-post","status-publish","format-standard","hentry","category-net","entry"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.8 - aioseo.com -->\n\t<meta name=\"description\" content=\"Introduction Sometimes it happens that you should write unit tests... Just kidding - you HAVE TO write unit tests (me as well). In a perfect world the method we want to write a unit-test for is well-written, concise and returns concrete value. Unfortunately, there are methods that seems to be intricate in terms of unit\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Tomasz\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/baldsolutions.com\/index.php\/2022\/01\/15\/how-to-unit-test-method-invocation-that-accepts-builder-style-parameter-with-nsubstitute\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.8\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Bald Solutions -\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Unit test for a method that accepts builder-style parameter with NSubstitute - Bald Solutions\" \/>\n\t\t<meta property=\"og:description\" content=\"Introduction Sometimes it happens that you should write unit tests... Just kidding - you HAVE TO write unit tests (me as well). In a perfect world the method we want to write a unit-test for is well-written, concise and returns concrete value. Unfortunately, there are methods that seems to be intricate in terms of unit\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/baldsolutions.com\/index.php\/2022\/01\/15\/how-to-unit-test-method-invocation-that-accepts-builder-style-parameter-with-nsubstitute\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2022-01-15T12:25:02+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2022-01-16T16:34:03+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Unit test for a method that accepts builder-style parameter with NSubstitute - Bald Solutions\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Introduction Sometimes it happens that you should write unit tests... Just kidding - you HAVE TO write unit tests (me as well). In a perfect world the method we want to write a unit-test for is well-written, concise and returns concrete value. Unfortunately, there are methods that seems to be intricate in terms of unit\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"BlogPosting\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/2022\\\/01\\\/15\\\/how-to-unit-test-method-invocation-that-accepts-builder-style-parameter-with-nsubstitute\\\/#blogposting\",\"name\":\"Unit test for a method that accepts builder-style parameter with NSubstitute - Bald Solutions\",\"headline\":\"Unit test for a method that accepts builder-style parameter with NSubstitute\",\"author\":{\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/author\\\/tomasz3396\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/#organization\"},\"datePublished\":\"2022-01-15T12:25:02+00:00\",\"dateModified\":\"2022-01-16T16:34:03+00:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/2022\\\/01\\\/15\\\/how-to-unit-test-method-invocation-that-accepts-builder-style-parameter-with-nsubstitute\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/2022\\\/01\\\/15\\\/how-to-unit-test-method-invocation-that-accepts-builder-style-parameter-with-nsubstitute\\\/#webpage\"},\"articleSection\":\".NET\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/2022\\\/01\\\/15\\\/how-to-unit-test-method-invocation-that-accepts-builder-style-parameter-with-nsubstitute\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/baldsolutions.com#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/baldsolutions.com\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/category\\\/net\\\/#listItem\",\"name\":\".NET\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/category\\\/net\\\/#listItem\",\"position\":2,\"name\":\".NET\",\"item\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/category\\\/net\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/2022\\\/01\\\/15\\\/how-to-unit-test-method-invocation-that-accepts-builder-style-parameter-with-nsubstitute\\\/#listItem\",\"name\":\"Unit test for a method that accepts builder-style parameter with NSubstitute\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/baldsolutions.com#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/2022\\\/01\\\/15\\\/how-to-unit-test-method-invocation-that-accepts-builder-style-parameter-with-nsubstitute\\\/#listItem\",\"position\":3,\"name\":\"Unit test for a method that accepts builder-style parameter with NSubstitute\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/category\\\/net\\\/#listItem\",\"name\":\".NET\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/#organization\",\"name\":\"Bald Solutions\",\"url\":\"https:\\\/\\\/baldsolutions.com\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/author\\\/tomasz3396\\\/#author\",\"url\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/author\\\/tomasz3396\\\/\",\"name\":\"Tomasz\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/2022\\\/01\\\/15\\\/how-to-unit-test-method-invocation-that-accepts-builder-style-parameter-with-nsubstitute\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d72f2f7f389921b820e5ef7c2880172fc2b9ae47698a933356df224581de0cc7?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Tomasz\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/2022\\\/01\\\/15\\\/how-to-unit-test-method-invocation-that-accepts-builder-style-parameter-with-nsubstitute\\\/#webpage\",\"url\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/2022\\\/01\\\/15\\\/how-to-unit-test-method-invocation-that-accepts-builder-style-parameter-with-nsubstitute\\\/\",\"name\":\"Unit test for a method that accepts builder-style parameter with NSubstitute - Bald Solutions\",\"description\":\"Introduction Sometimes it happens that you should write unit tests... Just kidding - you HAVE TO write unit tests (me as well). In a perfect world the method we want to write a unit-test for is well-written, concise and returns concrete value. Unfortunately, there are methods that seems to be intricate in terms of unit\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/2022\\\/01\\\/15\\\/how-to-unit-test-method-invocation-that-accepts-builder-style-parameter-with-nsubstitute\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/author\\\/tomasz3396\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/author\\\/tomasz3396\\\/#author\"},\"datePublished\":\"2022-01-15T12:25:02+00:00\",\"dateModified\":\"2022-01-16T16:34:03+00:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/#website\",\"url\":\"https:\\\/\\\/baldsolutions.com\\\/\",\"name\":\"Bald Solutions\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Unit test for a method that accepts builder-style parameter with NSubstitute - Bald Solutions","description":"Introduction Sometimes it happens that you should write unit tests... Just kidding - you HAVE TO write unit tests (me as well). In a perfect world the method we want to write a unit-test for is well-written, concise and returns concrete value. Unfortunately, there are methods that seems to be intricate in terms of unit","canonical_url":"https:\/\/baldsolutions.com\/index.php\/2022\/01\/15\/how-to-unit-test-method-invocation-that-accepts-builder-style-parameter-with-nsubstitute\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BlogPosting","@id":"https:\/\/baldsolutions.com\/index.php\/2022\/01\/15\/how-to-unit-test-method-invocation-that-accepts-builder-style-parameter-with-nsubstitute\/#blogposting","name":"Unit test for a method that accepts builder-style parameter with NSubstitute - Bald Solutions","headline":"Unit test for a method that accepts builder-style parameter with NSubstitute","author":{"@id":"https:\/\/baldsolutions.com\/index.php\/author\/tomasz3396\/#author"},"publisher":{"@id":"https:\/\/baldsolutions.com\/#organization"},"datePublished":"2022-01-15T12:25:02+00:00","dateModified":"2022-01-16T16:34:03+00:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/baldsolutions.com\/index.php\/2022\/01\/15\/how-to-unit-test-method-invocation-that-accepts-builder-style-parameter-with-nsubstitute\/#webpage"},"isPartOf":{"@id":"https:\/\/baldsolutions.com\/index.php\/2022\/01\/15\/how-to-unit-test-method-invocation-that-accepts-builder-style-parameter-with-nsubstitute\/#webpage"},"articleSection":".NET"},{"@type":"BreadcrumbList","@id":"https:\/\/baldsolutions.com\/index.php\/2022\/01\/15\/how-to-unit-test-method-invocation-that-accepts-builder-style-parameter-with-nsubstitute\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/baldsolutions.com#listItem","position":1,"name":"Home","item":"https:\/\/baldsolutions.com","nextItem":{"@type":"ListItem","@id":"https:\/\/baldsolutions.com\/index.php\/category\/net\/#listItem","name":".NET"}},{"@type":"ListItem","@id":"https:\/\/baldsolutions.com\/index.php\/category\/net\/#listItem","position":2,"name":".NET","item":"https:\/\/baldsolutions.com\/index.php\/category\/net\/","nextItem":{"@type":"ListItem","@id":"https:\/\/baldsolutions.com\/index.php\/2022\/01\/15\/how-to-unit-test-method-invocation-that-accepts-builder-style-parameter-with-nsubstitute\/#listItem","name":"Unit test for a method that accepts builder-style parameter with NSubstitute"},"previousItem":{"@type":"ListItem","@id":"https:\/\/baldsolutions.com#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/baldsolutions.com\/index.php\/2022\/01\/15\/how-to-unit-test-method-invocation-that-accepts-builder-style-parameter-with-nsubstitute\/#listItem","position":3,"name":"Unit test for a method that accepts builder-style parameter with NSubstitute","previousItem":{"@type":"ListItem","@id":"https:\/\/baldsolutions.com\/index.php\/category\/net\/#listItem","name":".NET"}}]},{"@type":"Organization","@id":"https:\/\/baldsolutions.com\/#organization","name":"Bald Solutions","url":"https:\/\/baldsolutions.com\/"},{"@type":"Person","@id":"https:\/\/baldsolutions.com\/index.php\/author\/tomasz3396\/#author","url":"https:\/\/baldsolutions.com\/index.php\/author\/tomasz3396\/","name":"Tomasz","image":{"@type":"ImageObject","@id":"https:\/\/baldsolutions.com\/index.php\/2022\/01\/15\/how-to-unit-test-method-invocation-that-accepts-builder-style-parameter-with-nsubstitute\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/d72f2f7f389921b820e5ef7c2880172fc2b9ae47698a933356df224581de0cc7?s=96&d=mm&r=g","width":96,"height":96,"caption":"Tomasz"}},{"@type":"WebPage","@id":"https:\/\/baldsolutions.com\/index.php\/2022\/01\/15\/how-to-unit-test-method-invocation-that-accepts-builder-style-parameter-with-nsubstitute\/#webpage","url":"https:\/\/baldsolutions.com\/index.php\/2022\/01\/15\/how-to-unit-test-method-invocation-that-accepts-builder-style-parameter-with-nsubstitute\/","name":"Unit test for a method that accepts builder-style parameter with NSubstitute - Bald Solutions","description":"Introduction Sometimes it happens that you should write unit tests... Just kidding - you HAVE TO write unit tests (me as well). In a perfect world the method we want to write a unit-test for is well-written, concise and returns concrete value. Unfortunately, there are methods that seems to be intricate in terms of unit","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/baldsolutions.com\/#website"},"breadcrumb":{"@id":"https:\/\/baldsolutions.com\/index.php\/2022\/01\/15\/how-to-unit-test-method-invocation-that-accepts-builder-style-parameter-with-nsubstitute\/#breadcrumblist"},"author":{"@id":"https:\/\/baldsolutions.com\/index.php\/author\/tomasz3396\/#author"},"creator":{"@id":"https:\/\/baldsolutions.com\/index.php\/author\/tomasz3396\/#author"},"datePublished":"2022-01-15T12:25:02+00:00","dateModified":"2022-01-16T16:34:03+00:00"},{"@type":"WebSite","@id":"https:\/\/baldsolutions.com\/#website","url":"https:\/\/baldsolutions.com\/","name":"Bald Solutions","inLanguage":"en-US","publisher":{"@id":"https:\/\/baldsolutions.com\/#organization"}}]},"og:locale":"en_US","og:site_name":"Bald Solutions -","og:type":"article","og:title":"Unit test for a method that accepts builder-style parameter with NSubstitute - Bald Solutions","og:description":"Introduction Sometimes it happens that you should write unit tests... Just kidding - you HAVE TO write unit tests (me as well). In a perfect world the method we want to write a unit-test for is well-written, concise and returns concrete value. Unfortunately, there are methods that seems to be intricate in terms of unit","og:url":"https:\/\/baldsolutions.com\/index.php\/2022\/01\/15\/how-to-unit-test-method-invocation-that-accepts-builder-style-parameter-with-nsubstitute\/","article:published_time":"2022-01-15T12:25:02+00:00","article:modified_time":"2022-01-16T16:34:03+00:00","twitter:card":"summary","twitter:title":"Unit test for a method that accepts builder-style parameter with NSubstitute - Bald Solutions","twitter:description":"Introduction Sometimes it happens that you should write unit tests... Just kidding - you HAVE TO write unit tests (me as well). In a perfect world the method we want to write a unit-test for is well-written, concise and returns concrete value. Unfortunately, there are methods that seems to be intricate in terms of unit"},"aioseo_meta_data":{"post_id":"61","title":"#post_title #separator_sa #site_title","description":"#post_excerpt","keywords":[],"keyphrases":{"focus":[],"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":[],"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[],"defaultGraph":"Article","defaultPostTypeGraph":""},"schema_type":"default","schema_type_options":"{\"article\":{\"articleType\":\"BlogPosting\"},\"course\":{\"name\":\"\",\"description\":\"\",\"provider\":\"\"},\"faq\":{\"pages\":[]},\"product\":{\"reviews\":[]},\"recipe\":{\"ingredients\":[],\"instructions\":[],\"keywords\":[]},\"software\":{\"reviews\":[],\"operatingSystems\":[]},\"webPage\":{\"webPageType\":\"WebPage\"}}","pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2022-01-15 11:37:54","updated":"2025-06-04 04:18:05","seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/baldsolutions.com\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/baldsolutions.com\/index.php\/category\/net\/\" title=\".NET\">.NET<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tUnit test for a method that accepts builder-style parameter with NSubstitute\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/baldsolutions.com"},{"label":".NET","link":"https:\/\/baldsolutions.com\/index.php\/category\/net\/"},{"label":"Unit test for a method that accepts builder-style parameter with NSubstitute","link":"https:\/\/baldsolutions.com\/index.php\/2022\/01\/15\/how-to-unit-test-method-invocation-that-accepts-builder-style-parameter-with-nsubstitute\/"}],"_links":{"self":[{"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/posts\/61","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/comments?post=61"}],"version-history":[{"count":10,"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/posts\/61\/revisions"}],"predecessor-version":[{"id":74,"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/posts\/61\/revisions\/74"}],"wp:attachment":[{"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/media?parent=61"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/categories?post=61"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/tags?post=61"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}