{"id":28659,"date":"2019-05-15T00:00:00","date_gmt":"2019-05-14T22:00:00","guid":{"rendered":"https:\/\/blexin.com\/tdd-tutto-il-codice-e-colpevole-fino-a-prova-contraria\/"},"modified":"2021-05-20T19:17:25","modified_gmt":"2021-05-20T17:17:25","slug":"tdd-the-whole-code-is-guilty-until-proven-innocent","status":"publish","type":"post","link":"https:\/\/blexin.com\/en\/blog-en\/tdd-the-whole-code-is-guilty-until-proven-innocent\/","title":{"rendered":"TDD: the whole code is guilty, until proven innocent!"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"608\" data-attachment-id=\"28630\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/tdd-the-whole-code-is-guilty-until-proven-innocent\/attachment\/a16452f3-251a-4e86-90e2-9587547457a6-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/a16452f3-251a-4e86-90e2-9587547457a6.png?fit=1024%2C608&amp;ssl=1\" data-orig-size=\"1024,608\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"a16452f3-251a-4e86-90e2-9587547457a6\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/a16452f3-251a-4e86-90e2-9587547457a6.png?fit=1024%2C608&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/a16452f3-251a-4e86-90e2-9587547457a6.png?resize=1024%2C608&#038;ssl=1\" alt=\"\" class=\"wp-image-28630\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/a16452f3-251a-4e86-90e2-9587547457a6.png 1024w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/a16452f3-251a-4e86-90e2-9587547457a6-980x582.png 980w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/a16452f3-251a-4e86-90e2-9587547457a6-480x285.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1024px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">While I was working on a client\u2019s project with one of our partners, I had the opportunity to face the development of some tasks, using a method I\u2019ve heard about many times, but that I have never used before: the&nbsp;<strong>Test Driven Development (TDD)<\/strong>. _This method consists in writing tests of the code we are developing, before we write the code itself!<br>Since it is difficult today to find projects, for whom it is easy to have some tests\u2019 arrays, this experience really strikes me, mostly due to the added value that this method can give to software development.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The principles of this protocol have been defined in detail by&nbsp;<strong><a href=\"https:\/\/en.wikipedia.org\/wiki\/Robert_C._Martin\" target=\"_blank\" rel=\"noreferrer noopener\">Uncle Bob<\/a><\/strong>&nbsp;and you can find them below:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><em>You are not allowed to write any production code unless it is to make a failing unit test pass.<\/em><\/li><li><em>You are not allowed to write any more of a unit test than is sufficient to fail; and compilation failures are failures.<\/em><\/li><li><em>You are not allowed to write any more production code than is sufficient to pass the one failing unit test.<\/em><\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">In brief, what you have to keep on mind as you are using this method is:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>&#8220;Only ever write code to fix a failing test&#8221;<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"le-tre-fasi-di-tdd-red-green-refactor\"><strong>TDD three stages: Red, Green Refactor<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The Test Driven Development founds itself on three stages: Red, Green, Refactor.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"996\" height=\"662\" data-attachment-id=\"28633\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/tdd-the-whole-code-is-guilty-until-proven-innocent\/attachment\/print-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/tdd.jpg?fit=996%2C662&amp;ssl=1\" data-orig-size=\"996,662\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;Print&quot;,&quot;orientation&quot;:&quot;1&quot;}\" data-image-title=\"Print\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/tdd.jpg?fit=996%2C662&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/tdd.jpg?resize=996%2C662&#038;ssl=1\" alt=\"\" class=\"wp-image-28633\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/tdd.jpg 996w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/tdd-980x651.jpg 980w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/tdd-480x319.jpg 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 996px, 100vw\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"fase-rossa\"><strong>Red stage<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In this stage, you have to write a behavior you would like to test, but you don\u2019t need to think about how the code should be implemented: you just need to identify how it must acts with specific inputs.<br>If you are thinking about how to implement it,&nbsp;<strong>you\u2019re wrong!<\/strong><br>In this stage, you only need to decide \u201chow\u201d your code will be used.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"fase-verde\"><strong>Green Stage<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This is the stage we programmers mostly like: writing code.<br>The most common mistake one can do in this stage is to think to implement the test\u2019s expected behavior in the best possible way, even getting it complicated for future developments.<br>In this case too,&nbsp;<strong>you\u2019re wrong!<\/strong><br>You just need to write enough code to let the test passing from red to green, but you are not required to think if you are following the&nbsp;<em>Best Practices<\/em>, and so on.<br>The Test Driving Development offers&nbsp;<strong><em>to-do list&nbsp;<\/em><\/strong>where you can take note of all the passage you need to complete the functionality you are implementing. The same list contains also doubts or problems you discover during the code\u2019s writing. At the end of the process, this list must be empty.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"fase-di-refactoring\"><strong>Refactoring stage<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The last stage of the process has a precise purpose: improve the code, without changing its behavior.<br>We have our \u201cgreen test\u201d, which grant us that the implemented functionality will do what it should: we just need to improve the code.<br>It\u2019s time to delete the unnecessary code, look at what we wrote critically and apply best practices.<br>As soon as we complete this stage, we are ready to start again with the red stage.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"la-parte-divertente\"><strong>The funny part<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now that the operational principles are clear, I would like to apply this method to an easy example. Create a Web API application in .NET Core, which only function is to accept a GET request with a custom header and return a&nbsp;<strong>202 (Accepted)<\/strong>&nbsp;If the customer header is correct, or a&nbsp;<strong>401 (Unauthorized)<\/strong>&nbsp;if it is incorrect or absent.<br>I use VisualStudio templates to be fast as possible with the creation of a new solution.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"712\" data-attachment-id=\"28636\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/tdd-the-whole-code-is-guilty-until-proven-innocent\/attachment\/step1-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/step1.png?fit=1178%2C819&amp;ssl=1\" data-orig-size=\"1178,819\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"step1\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/step1.png?fit=1024%2C712&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/step1.png?resize=1024%2C712&#038;ssl=1\" alt=\"\" class=\"wp-image-28636\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/step1-1024x712.png 1024w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/step1-980x681.png 980w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/step1-480x334.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1024px, 100vw\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"983\" height=\"693\" data-attachment-id=\"28638\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/tdd-the-whole-code-is-guilty-until-proven-innocent\/attachment\/step2-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/step2.png?fit=983%2C693&amp;ssl=1\" data-orig-size=\"983,693\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"step2\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/step2.png?fit=983%2C693&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/step2.png?resize=983%2C693&#038;ssl=1\" alt=\"\" class=\"wp-image-28638\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/step2.png 983w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/step2-980x691.png 980w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/step2-480x338.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 983px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">I add one more project to the solution to manage the test.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"709\" data-attachment-id=\"28640\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/tdd-the-whole-code-is-guilty-until-proven-innocent\/attachment\/step3-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/step3.png?fit=1181%2C818&amp;ssl=1\" data-orig-size=\"1181,818\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"step3\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/step3.png?fit=1024%2C709&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/step3.png?resize=1024%2C709&#038;ssl=1\" alt=\"\" class=\"wp-image-28640\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/step3-1024x709.png 1024w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/step3-980x679.png 980w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/step3-480x332.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1024px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In this way, I have my Solution with two projects inside it: one is for tests and the other one is for the API we would create.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"707\" height=\"659\" data-attachment-id=\"28643\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/tdd-the-whole-code-is-guilty-until-proven-innocent\/attachment\/step4-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/step4.png?fit=707%2C659&amp;ssl=1\" data-orig-size=\"707,659\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"step4\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/step4.png?fit=707%2C659&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/step4.png?resize=707%2C659&#038;ssl=1\" alt=\"\" class=\"wp-image-28643\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/step4.png 707w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/step4-480x447.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 707px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">We need to tidy up of classes created in the template: let\u2019s delete&nbsp;<em>ValueController.cs<\/em>&nbsp;and&nbsp;<em>UnitTest1.cs<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We create the classes DemoControllerTest in the test project, and DemoController in the API project.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nusing Microsoft.VisualStudio.TestTools.UnitTesting;\n\u00a0\nnamespace TddStepToStep.Tests\n{\n\u00a0\u00a0\u00a0\u00a0&#x5B;TestClass]\n\u00a0\u00a0\u00a0\u00a0public class DemoControllerTest\n\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0}\n}\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nusing Microsoft.AspNetCore.Mvc;\n\u00a0\nnamespace TddStepToStep.Controllers\n{\n\u00a0\u00a0\u00a0\u00a0&#x5B;Route(&quot;api\/&#x5B;controller]&quot;)]\n\u00a0\u00a0\u00a0\u00a0&#x5B;ApiController]\n\u00a0\u00a0\u00a0\u00a0public class DemoController : ControllerBase\n\u00a0\u00a0\u00a0\u00a0{\u00a0\u00a0 \n\u00a0\u00a0\u00a0\u00a0}\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Specify the test target, that\u2019s to say the class DemoController<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nprivate DemoController _target;\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Add a method to initialize the test class, where we create the DemoController request, by giving it a configuration class. In the configuration class there is the ApiKey property and it will be used to establish if the value passed to the request is correct.<br>The compiler will surely advise us that there\u2019s no&nbsp;<em>DemoControllerConfig<\/em>&nbsp;class, that&nbsp;<em>DemoController<\/em>&nbsp;has no constructor, which can accept that kind of parameter and that it absolutely doesn\u2019t know what is&nbsp;<em>CORRECT_API_KEY<\/em>.<br><br>We can start from the easiest thing to do: create the constant&nbsp;<em>CORRECT_API_KEY<\/em><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\npublic const string CORRECT_API_KEY = &quot;1234&quot;;\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">We create then the class&nbsp;<em>DemoControllerConfig<\/em>&nbsp;in the API project,It is empty at the beginning, but VS will help us (through the shortcut&nbsp;<strong>CTRL + &#8216;.&#8217;<\/strong>&nbsp;) and will suggest us to add a property&nbsp;<em>ApiKey<\/em>&nbsp;to the class. We can do the same to create a constructor and its relative private property for&nbsp;<em>DemoController<\/em>:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nusing TddStepToStep.Controllers;\n\u00a0\nnamespace TddStepToStep.Tests\n{\n\u00a0\u00a0\u00a0\u00a0&#x5B;TestClass]\n\u00a0\u00a0\u00a0\u00a0public class DemoControllerTest\n\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0public const string CORRECT_API_KEY = &quot;1234&quot;;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0private DemoController _target;\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#x5B;TestInitialize]\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0public void Init()\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0_target = new DemoController(new DemoControllerConfig() { ApiKey = CORRECT_API_KEY });\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0}\n}\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nusing Microsoft.AspNetCore.Mvc;\n\u00a0\nnamespace TddStepToStep.Controllers\n{\n\u00a0\u00a0\u00a0\u00a0&#x5B;Route(&quot;api\/&#x5B;controller]&quot;)]\n\u00a0\u00a0\u00a0\u00a0&#x5B;ApiController]\n\u00a0\u00a0\u00a0\u00a0public class DemoController : ControllerBase\n\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0private DemoControllerConfig demoControllerConfig;\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0public DemoController(DemoControllerConfig demoControllerConfig)\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0this.demoControllerConfig = demoControllerConfig;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0}\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">It\u2019s normal to pass a class that contains the ApiKey to Controller, instead to recover the value from a configuration file, when you use the \u201ctest first\u201d method: we are dividing our logic from external factors.<br>The next step is to create the real test.<br>I want to test that the Status Code of the answer is&nbsp;<strong><em>202 accepted<\/em><\/strong>&nbsp;, when an HTTP request with an header with the same value of the provide one, arrives.<br>The test\u2019s name must denote exactly what we want to test. A good method to write the test\u2019s name is to follow this rule:&nbsp;<em>Should_ExpectedBehavior_When_StateUnderTest<\/em>.<br>The test name would be then:&nbsp;<strong><em>ShouldReturnAcceptedResultWhenCorrectApiKeyIsPassed<\/em><\/strong>.<br>To pass a Header to a Controller, we need to write some code.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n_target.ControllerContext = new ControllerContext();\n_target.ControllerContext.HttpContext = new DefaultHttpContext();\n_target.ControllerContext.HttpContext.Request.Headers.Add(&quot;X-API-KEY&quot;, CORRECT_API_KEY);\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">To add a Header, we create a new ControllerContext for the Controller we are going to test, to which we set up a new HttpContext that allows us to access to the Request. In the Request, we find the Headers. We add then the Header&nbsp;<strong><em>X-API-KEY<\/em><\/strong>&nbsp;with the correct value. Now we can simulate the API call, simply invoking the method that answers to the call.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nvar resp = _target.GetValues();\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">we transmit the obtained answer to the&nbsp;<strong>Assert<\/strong>.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nAssert.IsInstanceOfType(resp, typeof(AcceptedResult));\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">The compilator will complains about the non-existance of&nbsp;<em>GetValues()<\/em>, but we can use the command&nbsp;<strong>CTRL + &#8216;.&#8217;&nbsp;<\/strong>to create the lacking method we are going to implement.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n&#x5B;HttpGet]\npublic ActionResult GetValues()\n{\n\u00a0\u00a0\u00a0\u00a0throw new NotImplementedException();\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">We finally have our test\u2019s method, which we can execute and that we expect to fail (red&nbsp;<strong><em>stage<\/em><\/strong>):<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n&#x5B;TestMethod]\npublic void ShouldReturnAcceptedResultWhenCorrectApiKeyIsPassed()\n{\n\u00a0\u00a0\u00a0\u00a0_target.ControllerContext = new ControllerContext();\n\u00a0\u00a0\u00a0\u00a0_target.ControllerContext.HttpContext = new DefaultHttpContext();\n\u00a0\u00a0\u00a0\u00a0_target.ControllerContext.HttpContext.Request.Headers.Add(&quot;X-API-KEY&quot;, CORRECT_API_KEY);\n\u00a0\u00a0\u00a0\u00a0var resp = _target.GetValues();\n\u00a0\u00a0\u00a0\u00a0Assert.IsInstanceOfType(resp, typeof(AcceptedResult));\n}\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"952\" height=\"800\" data-attachment-id=\"28648\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/tdd-the-whole-code-is-guilty-until-proven-innocent\/attachment\/failed_test-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/failed_test.png?fit=952%2C800&amp;ssl=1\" data-orig-size=\"952,800\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"failed_test\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/failed_test.png?fit=952%2C800&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/failed_test.png?resize=952%2C800&#038;ssl=1\" alt=\"\" class=\"wp-image-28648\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/failed_test.png 952w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/failed_test-480x403.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 952px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The test fails because we still don\u2019t implement the&nbsp;<em>GetValues<\/em>&nbsp;method in the controller.<br>We will then implement the method, in order to let it changes to&nbsp;<strong><em>green stage<\/em><\/strong>.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n&#x5B;HttpGet]\npublic ActionResult GetValues()\n{\n\u00a0\u00a0\u00a0\u00a0if (Request.Headers.ContainsKey(&quot;X-API-KEY&quot;) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&amp;&amp; Request.Headers&#x5B;&quot;X-API-KEY&quot;].Equals(demoControllerConfig.ApiKey))\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return Accepted();\n\u00a0\n\u00a0\u00a0\u00a0\u00a0return Ok();\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Run the test again:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"953\" height=\"803\" data-attachment-id=\"28650\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/tdd-the-whole-code-is-guilty-until-proven-innocent\/attachment\/passed_test-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/passed_test.png?fit=953%2C803&amp;ssl=1\" data-orig-size=\"953,803\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"passed_test\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/passed_test.png?fit=953%2C803&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/passed_test.png?resize=953%2C803&#038;ssl=1\" alt=\"\" class=\"wp-image-28650\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/passed_test.png 953w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/passed_test-480x404.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 953px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">We respect the first requirement, now we need to obtain a 401 in the event that the key was incorrect.<br>I add the test and I run it, but I await that it will fails again.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\npublic const string WRONG_API_KEY = &quot;1235&quot;;\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n&#x5B;TestMethod]\npublic void ShouldReturnUnauthorizedResultWhenWrongApiKeyIsPassed()\n{\n\u00a0\u00a0\u00a0\u00a0_target.ControllerContext = new ControllerContext();\n\u00a0\u00a0\u00a0\u00a0_target.ControllerContext.HttpContext = new DefaultHttpContext();\n\u00a0\u00a0\u00a0\u00a0_target.ControllerContext.HttpContext.Request.Headers.Add(&quot;X-API-KEY&quot;, WRONG_API_KEY);\n\u00a0\u00a0\u00a0\u00a0var resp = _target.GetValues();\n\u00a0\u00a0\u00a0\u00a0Assert.IsInstanceOfType(resp, typeof(UnauthorizedResult));\n}\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"952\" height=\"803\" data-attachment-id=\"28656\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/tdd-the-whole-code-is-guilty-until-proven-innocent\/attachment\/second_test_failed-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/second_test_failed.png?fit=952%2C803&amp;ssl=1\" data-orig-size=\"952,803\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"second_test_failed\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/second_test_failed.png?fit=952%2C803&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/second_test_failed.png?resize=952%2C803&#038;ssl=1\" alt=\"\" class=\"wp-image-28656\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/second_test_failed.png 952w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/second_test_failed-480x405.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 952px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">We receive and error message because the test expects a &#8220;<em>Unauthorized<\/em>\u201d, but it receives an&nbsp;<em>OK<\/em>.<br>We change the behavior with the method&nbsp;<em>GetValues<\/em>:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n&#x5B;HttpGet]\npublic ActionResult GetValues()\n{\n\u00a0\u00a0\u00a0\u00a0if (!Request.Headers.ContainsKey(&quot;X-API-KEY&quot;) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0|| !Request.Headers&#x5B;&quot;X-API-KEY&quot;].Equals(demoControllerConfig.ApiKey))\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return Unauthorized();\n\u00a0\n\u00a0\u00a0\u00a0\u00a0return Accepted();\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Run the test again:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"953\" height=\"802\" data-attachment-id=\"28653\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/tdd-the-whole-code-is-guilty-until-proven-innocent\/attachment\/all_tests_passed-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/all_tests_passed.png?fit=953%2C802&amp;ssl=1\" data-orig-size=\"953,802\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"all_tests_passed\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/all_tests_passed.png?fit=953%2C802&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/all_tests_passed.png?resize=953%2C802&#038;ssl=1\" alt=\"\" class=\"wp-image-28653\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/all_tests_passed.png 953w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/all_tests_passed-480x404.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 953px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">great! We reach the goal<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It still lacks the \u201crefactoring stage\u201d: you can do it on your own as exercise! You can, for example, us a part of the code in an Action Filter&#8230;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I wish I was able to intrigue you<br>See you next<\/p>\n\n\n\n\n","protected":false},"excerpt":{"rendered":"<p>Let\u2019s learn how to use the TDD method to improve the approach to our applications\u2019 development<\/p>\n","protected":false},"author":196716250,"featured_media":28630,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"off","_et_pb_old_content":"","_et_gb_content_width":"","_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","inline_featured_image":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_wpas_customize_per_network":false,"jetpack_post_was_ever_published":false},"categories":[688637524],"tags":[688637416,688637411],"class_list":["post-28659","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog-en","tag-asp-net-core-en","tag-testing-en"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>TDD: the whole code is guilty, until proven innocent! - Blexin<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blexin.com\/en\/blog-en\/tdd-the-whole-code-is-guilty-until-proven-innocent\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"TDD: the whole code is guilty, until proven innocent! - Blexin\" \/>\n<meta property=\"og:description\" content=\"Let\u2019s learn how to use the TDD method to improve the approach to our applications\u2019 development\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blexin.com\/en\/blog-en\/tdd-the-whole-code-is-guilty-until-proven-innocent\/\" \/>\n<meta property=\"og:site_name\" content=\"Blexin\" \/>\n<meta property=\"article:published_time\" content=\"2019-05-14T22:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-05-20T17:17:25+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i2.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/a16452f3-251a-4e86-90e2-9587547457a6.png?fit=1024%2C608&ssl=1\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"608\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Adolfo Arnold\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Adolfo Arnold\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/tdd-the-whole-code-is-guilty-until-proven-innocent\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/tdd-the-whole-code-is-guilty-until-proven-innocent\\\/\"},\"author\":{\"name\":\"Adolfo Arnold\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#\\\/schema\\\/person\\\/0de430b61c8a48b0e9d81308817c1517\"},\"headline\":\"TDD: the whole code is guilty, until proven innocent!\",\"datePublished\":\"2019-05-14T22:00:00+00:00\",\"dateModified\":\"2021-05-20T17:17:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/tdd-the-whole-code-is-guilty-until-proven-innocent\\\/\"},\"wordCount\":1253,\"image\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/tdd-the-whole-code-is-guilty-until-proven-innocent\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/blexin.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/a16452f3-251a-4e86-90e2-9587547457a6.png?fit=1024%2C608&ssl=1\",\"keywords\":[\"Asp.net core\",\"Testing\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/tdd-the-whole-code-is-guilty-until-proven-innocent\\\/\",\"url\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/tdd-the-whole-code-is-guilty-until-proven-innocent\\\/\",\"name\":\"TDD: the whole code is guilty, until proven innocent! - Blexin\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/tdd-the-whole-code-is-guilty-until-proven-innocent\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/tdd-the-whole-code-is-guilty-until-proven-innocent\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/blexin.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/a16452f3-251a-4e86-90e2-9587547457a6.png?fit=1024%2C608&ssl=1\",\"datePublished\":\"2019-05-14T22:00:00+00:00\",\"dateModified\":\"2021-05-20T17:17:25+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#\\\/schema\\\/person\\\/0de430b61c8a48b0e9d81308817c1517\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/tdd-the-whole-code-is-guilty-until-proven-innocent\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/tdd-the-whole-code-is-guilty-until-proven-innocent\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/tdd-the-whole-code-is-guilty-until-proven-innocent\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/blexin.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/a16452f3-251a-4e86-90e2-9587547457a6.png?fit=1024%2C608&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/blexin.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/a16452f3-251a-4e86-90e2-9587547457a6.png?fit=1024%2C608&ssl=1\",\"width\":1024,\"height\":608},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/tdd-the-whole-code-is-guilty-until-proven-innocent\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/blexin.com\\\/en\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"TDD: the whole code is guilty, until proven innocent!\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#website\",\"url\":\"https:\\\/\\\/blexin.com\\\/en\\\/\",\"name\":\"Blexin\",\"description\":\"Con noi \u00e8 semplice\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/blexin.com\\\/en\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#\\\/schema\\\/person\\\/0de430b61c8a48b0e9d81308817c1517\",\"name\":\"Adolfo Arnold\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/ff2a87b54d0f130d7452164533199af05ef16dbd08b9241729946cea0eec7cca?s=96&d=identicon&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/ff2a87b54d0f130d7452164533199af05ef16dbd08b9241729946cea0eec7cca?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/ff2a87b54d0f130d7452164533199af05ef16dbd08b9241729946cea0eec7cca?s=96&d=identicon&r=g\",\"caption\":\"Adolfo Arnold\"},\"url\":\"https:\\\/\\\/blexin.com\\\/en\\\/author\\\/adolfo-arnoldblexin-com\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"TDD: the whole code is guilty, until proven innocent! - Blexin","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:\/\/blexin.com\/en\/blog-en\/tdd-the-whole-code-is-guilty-until-proven-innocent\/","og_locale":"en_US","og_type":"article","og_title":"TDD: the whole code is guilty, until proven innocent! - Blexin","og_description":"Let\u2019s learn how to use the TDD method to improve the approach to our applications\u2019 development","og_url":"https:\/\/blexin.com\/en\/blog-en\/tdd-the-whole-code-is-guilty-until-proven-innocent\/","og_site_name":"Blexin","article_published_time":"2019-05-14T22:00:00+00:00","article_modified_time":"2021-05-20T17:17:25+00:00","og_image":[{"width":1024,"height":608,"url":"https:\/\/i2.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/a16452f3-251a-4e86-90e2-9587547457a6.png?fit=1024%2C608&ssl=1","type":"image\/png"}],"author":"Adolfo Arnold","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Adolfo Arnold","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blexin.com\/en\/blog-en\/tdd-the-whole-code-is-guilty-until-proven-innocent\/#article","isPartOf":{"@id":"https:\/\/blexin.com\/en\/blog-en\/tdd-the-whole-code-is-guilty-until-proven-innocent\/"},"author":{"name":"Adolfo Arnold","@id":"https:\/\/blexin.com\/en\/#\/schema\/person\/0de430b61c8a48b0e9d81308817c1517"},"headline":"TDD: the whole code is guilty, until proven innocent!","datePublished":"2019-05-14T22:00:00+00:00","dateModified":"2021-05-20T17:17:25+00:00","mainEntityOfPage":{"@id":"https:\/\/blexin.com\/en\/blog-en\/tdd-the-whole-code-is-guilty-until-proven-innocent\/"},"wordCount":1253,"image":{"@id":"https:\/\/blexin.com\/en\/blog-en\/tdd-the-whole-code-is-guilty-until-proven-innocent\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/a16452f3-251a-4e86-90e2-9587547457a6.png?fit=1024%2C608&ssl=1","keywords":["Asp.net core","Testing"],"articleSection":["Blog"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/blexin.com\/en\/blog-en\/tdd-the-whole-code-is-guilty-until-proven-innocent\/","url":"https:\/\/blexin.com\/en\/blog-en\/tdd-the-whole-code-is-guilty-until-proven-innocent\/","name":"TDD: the whole code is guilty, until proven innocent! - Blexin","isPartOf":{"@id":"https:\/\/blexin.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/blexin.com\/en\/blog-en\/tdd-the-whole-code-is-guilty-until-proven-innocent\/#primaryimage"},"image":{"@id":"https:\/\/blexin.com\/en\/blog-en\/tdd-the-whole-code-is-guilty-until-proven-innocent\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/a16452f3-251a-4e86-90e2-9587547457a6.png?fit=1024%2C608&ssl=1","datePublished":"2019-05-14T22:00:00+00:00","dateModified":"2021-05-20T17:17:25+00:00","author":{"@id":"https:\/\/blexin.com\/en\/#\/schema\/person\/0de430b61c8a48b0e9d81308817c1517"},"breadcrumb":{"@id":"https:\/\/blexin.com\/en\/blog-en\/tdd-the-whole-code-is-guilty-until-proven-innocent\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blexin.com\/en\/blog-en\/tdd-the-whole-code-is-guilty-until-proven-innocent\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blexin.com\/en\/blog-en\/tdd-the-whole-code-is-guilty-until-proven-innocent\/#primaryimage","url":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/a16452f3-251a-4e86-90e2-9587547457a6.png?fit=1024%2C608&ssl=1","contentUrl":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/a16452f3-251a-4e86-90e2-9587547457a6.png?fit=1024%2C608&ssl=1","width":1024,"height":608},{"@type":"BreadcrumbList","@id":"https:\/\/blexin.com\/en\/blog-en\/tdd-the-whole-code-is-guilty-until-proven-innocent\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blexin.com\/en\/"},{"@type":"ListItem","position":2,"name":"TDD: the whole code is guilty, until proven innocent!"}]},{"@type":"WebSite","@id":"https:\/\/blexin.com\/en\/#website","url":"https:\/\/blexin.com\/en\/","name":"Blexin","description":"Con noi \u00e8 semplice","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blexin.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blexin.com\/en\/#\/schema\/person\/0de430b61c8a48b0e9d81308817c1517","name":"Adolfo Arnold","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/ff2a87b54d0f130d7452164533199af05ef16dbd08b9241729946cea0eec7cca?s=96&d=identicon&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/ff2a87b54d0f130d7452164533199af05ef16dbd08b9241729946cea0eec7cca?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ff2a87b54d0f130d7452164533199af05ef16dbd08b9241729946cea0eec7cca?s=96&d=identicon&r=g","caption":"Adolfo Arnold"},"url":"https:\/\/blexin.com\/en\/author\/adolfo-arnoldblexin-com\/"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/a16452f3-251a-4e86-90e2-9587547457a6.png?fit=1024%2C608&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pcyUBx-7sf","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts\/28659","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/users\/196716250"}],"replies":[{"embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/comments?post=28659"}],"version-history":[{"count":7,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts\/28659\/revisions"}],"predecessor-version":[{"id":31990,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts\/28659\/revisions\/31990"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/media\/28630"}],"wp:attachment":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/media?parent=28659"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/categories?post=28659"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/tags?post=28659"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}