title: C# Unit testing a Newtonsoft JSON model
body: <p>I am starting with unit testing and am doing so with XUnit.</p>
  
  <p>I have a model :</p>
  
  <pre><code>using Newtonsoft.Json;
  namespace HomeAddressSearch
  {
      public class Properties
      {
          [Required]
          [JsonProperty(PropertyName = "civic_number")]
          public string CivicNumber { get; set; }
  
          [JsonProperty(PropertyName = "address")]
          public string Address { get; set; }
  
          [JsonProperty(PropertyName = "postal_code")]
          public string PostalCode { get; set; }
  
          [JsonProperty(PropertyName = "city_name")]
          public string CityName { get; set; }
      }
  }
  </code></pre>
  
  <p>and I have a JSON from which I am getting values like :</p>
  
  <pre><code>[
    {
      "properties": {
        "civic_number": "100",
        "address": "100, king street",
        "postal_code": "H0H0H0",
        "city_name": "Windsor"
      },
      "owner": {
        "name": "John Doe",
        "age": "40"
      },
    }
  ]
  </code></pre>
  
  <p>So I want to test that model and for so I though of:</p>
  
  <ul>
  <li>As CivicNumber is Required I want to make sure there is no Null value or empty string in the JSON, so a test with a null value crashing the test</li>
  <li>If ever someone would change the JSON and remove one of the field in the properties object, like city_name, then the test would fail so I know I either need to adapt my model or get back to the original JSON format</li>
  <li>Check that format of JSON values, in this case all of them are string, are ok to be injected in my model</li>
  <li>Run an injection from a shorter version of a JSON file with like only 3 entries into the model to make sure everything is ok</li>
  </ul>
  
  <p>Am I on the right path and how to do this, that would greatly help and kickstart me for a lot of other things.</p>
  
  <p>THanks!</p>