예제 #1
0
        public void CanSerializeResourceWithNullContent()
        {
            var original = new TestResource
            {
                Links = new TestLinks
                {
                    new HyperMediaLink {
                        Rel = "self", Href = "http://link.com/1"
                    }
                },
                StringProperty = null
            };
            var          json         = JsonConvert.SerializeObject(original, _settings);
            const string expected     = @"{
  ""stringProperty"": null,
  ""intProperty"": 0,
  ""boolProperty"": false,
  ""dateOffsetProperty"": ""0001-01-01T00:00:00+00:00"",
  ""dateProperty"": ""0001-01-01T00:00:00"",
  ""_links"": {
    ""self"": {
      ""href"": ""http://link.com/1"",
      ""templated"": false
    }
  }
}";
            var          deserialized = JsonConvert.DeserializeObject <TestResource>(json, _settings);

            json.ShouldNotBeNullOrWhiteSpace();
            json.ShouldBe(expected, StringCompareShould.IgnoreCase);
            original.ShouldBe(deserialized);
        }