{"id":3099,"date":"2015-04-09T23:19:37","date_gmt":"2015-04-09T23:19:37","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=3099"},"modified":"2015-04-09T23:19:49","modified_gmt":"2015-04-09T23:19:49","slug":"unit-testing-and-the-current-synchronizationcontext-may-not-be-used-as-a-taskscheduler-error","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/unit-testing-and-the-current-synchronizationcontext-may-not-be-used-as-a-taskscheduler-error\/","title":{"rendered":"Unit testing and &#8220;The current SynchronizationContext may not be used as a TaskScheduler&#8221; error"},"content":{"rendered":"<p>When running unit tests (for example with xUnit) and code that requires a synchronization context, one might get the test failing with the message<\/p>\n<p><em>The current SynchronizationContext may not be used as a TaskScheduler.<\/em><\/p>\n<p>The easiest way to resolve this is to supply your own SynchronizationContext to a unit test class, for example adding a static constructor (for xUnit) or in the SetUp method (in NUnit).<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nstatic MyTests()\r\n{\r\n   SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());\t\t\r\n}\r\n<\/pre>\n<p><em>Note: xUnit supplies a Synchronization context when using async tests, but when running Reactive Extensions or TPL code it seems we need to supply our own.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When running unit tests (for example with xUnit) and code that requires a synchronization context, one might get the test failing with the message The current SynchronizationContext may not be used as a TaskScheduler. The easiest way to resolve this is to supply your own SynchronizationContext to a unit test class, for example adding a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[28,48],"tags":[],"class_list":["post-3099","post","type-post","status-publish","format-standard","hentry","category-testing","category-xunit"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/3099","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=3099"}],"version-history":[{"count":1,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/3099\/revisions"}],"predecessor-version":[{"id":3100,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/3099\/revisions\/3100"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=3099"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=3099"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=3099"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}