public void Can_include_nested_only() { var dto = new IncludeExclude { Id = 1234, Name = "TEST", Obj = new Exclude { Id = 1, Key = "Value" } }; using (var config = JsConfig.BeginScope()) { config.ExcludePropertyReferences = new[] { "Exclude.Id", "IncludeExclude.Id", "IncludeExclude.Name" }; Assert.That(dto.ToJson(), Is.EqualTo("{\"Obj\":{\"Key\":\"Value\"}}")); Assert.That(dto.ToJsv(), Is.EqualTo("{Obj:{Key:Value}}")); } Assert.That(JsConfig.ExcludePropertyReferences, Is.EqualTo(null)); }
public void Exclude_all_nested() { var dto = new IncludeExclude { Id = 1234, Name = "TEST", Obj = new Exclude { Id = 1, Key = "Value" } }; using (var config = JsConfig.BeginScope()) { config.ExcludePropertyReferences = new[] { "Exclude.Id", "Exclude.Key" }; Assert.AreEqual(2, config.ExcludePropertyReferences.Length); var actual = dto.ToJson(); Assert.That(actual, Is.EqualTo("{\"Id\":1234,\"Name\":\"TEST\",\"Obj\":{}}")); Assert.That(dto.ToJsv(), Is.EqualTo("{Id:1234,Name:TEST,Obj:{}}")); } }