public void VerifyResourceSerializationRespectNullHandlingIgnore() { var snake = new SnakeResource { Links = new HalLinks(new SelfLink("/snake")) }; var settings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; settings.ConfigureForHalite(); var json = JsonConvert.SerializeObject(snake, settings); var expectedJson = "{\"_links\":{\"self\":{\"href\":\"/snake\"}}}"; json.ShouldBe(expectedJson); }
public void VerifyResourceSerializationRespectNullHandlingInclude() { var snake = new SnakeResource { Links = new HalLinks(new SelfLink("/snake")) }; var settings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Include }; settings.ConfigureForHalite(); var json = JsonConvert.SerializeObject(snake, settings); var expectedJson = "{\"_links\":{\"self\":{\"href\":\"/snake\"}},\"LongTail\":null}"; // Name has null-setting as property json.ShouldBe(expectedJson); }
public void VerifyResourceSerializationRespectNamingStrategy() { var snake = new SnakeResource { Links = new HalLinks(new SelfLink("/snake")), LongTail = "yes", Name = "Kozmo" }; var settings = new JsonSerializerSettings { ContractResolver = new HalContractResolver { NamingStrategy = new SnakeCaseNamingStrategy() } }; var json = JsonConvert.SerializeObject(snake, settings); var expectedJson = "{\"_links\":{\"self\":{\"href\":\"/snake\"}},\"long_tail\":\"yes\",\"name\":\"Kozmo\"}"; json.ShouldBe(expectedJson); }