{"id":1692,"date":"2020-08-14T15:27:31","date_gmt":"2020-08-14T05:27:31","guid":{"rendered":"https:\/\/ntsblog.homedev.com.au\/?p=1692"},"modified":"2023-10-26T21:09:12","modified_gmt":"2023-10-26T10:09:12","slug":"mock-ioptions-in-unit-test","status":"publish","type":"post","link":"https:\/\/ntsblog.homedev.com.au\/index.php\/2020\/08\/14\/mock-ioptions-in-unit-test\/","title":{"rendered":"Mock IOptions<model> in unit test"},"content":{"rendered":"<div id=\"ntsbl-767427533\" class=\"ntsbl-before-content ntsbl-entity-placement\"><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-6288941070289539\" crossorigin=\"anonymous\"><\/script><ins class=\"adsbygoogle\" style=\"display:inline-block;width:728px;height:90px;\" \ndata-ad-client=\"ca-pub-6288941070289539\" \ndata-ad-slot=\"9356781486\"><\/ins> \n<script> \n(adsbygoogle = window.adsbygoogle || []).push({}); \n<\/script>\n<\/div><h2>The Issue<\/h2>\n\n\n<p>You wish to unit test using the microsoft options Interface, but how do you inject your configuration class into your test framework?<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The solution<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>var options = Options.Create(new MyConfiguration() { Property = value});<\/code><\/pre>\n\n\n\n<p>That code will create an IOptions&lt;MyConfiguration&gt; class that you constructed, and now you can pass into the custructor of your _sut (System Under Test)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Issue You wish to unit test using the microsoft options Interface, but how do you inject your configuration class into your test framework? The [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[37,5],"tags":[],"class_list":["post-1692","post","type-post","status-publish","format-standard","hentry","category-net-core","category-c"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/posts\/1692","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/comments?post=1692"}],"version-history":[{"count":0,"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/posts\/1692\/revisions"}],"wp:attachment":[{"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/media?parent=1692"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/categories?post=1692"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/tags?post=1692"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}