コード例 #1
0
 public void IncludeInheritedProps()
 {
     MockContract discretional = new MockContract();
     OptionalContractResolver resolver = new OptionalContractResolver();
     resolver.Add(typeof(MockContract), "Fred");
     string json = JsonConvert.SerializeObject(discretional, new JsonSerializerSettings { ContractResolver = resolver });
     Assert.IsTrue(json.Contains("Fred"));
 }
コード例 #2
0
 public void DefaultEmpty()
 {
     MockContract discretional = new MockContract();
     OptionalContractResolver resolver = new OptionalContractResolver();
     resolver.Add(typeof(MockContract));
     string json = JsonConvert.SerializeObject(discretional, new JsonSerializerSettings { ContractResolver = resolver });
     Assert.AreEqual("{}", json);
 }
コード例 #3
0
 public void DoNotIncludePropsByDefault()
 {
     MockContract discretional = new MockContract();
     OptionalContractResolver resolver = new OptionalContractResolver();
     resolver.Add(typeof(MockContract), "Qux");
     string json = JsonConvert.SerializeObject(discretional, new JsonSerializerSettings { ContractResolver = resolver });
     Assert.IsFalse(json.Contains("Foo"));
 }
コード例 #4
0
 public void AlwaysIncludeRequestedFields()
 {
     MockContract discretional = new MockContract();
     OptionalContractResolver resolver = new OptionalContractResolver();
     resolver.Add(typeof(MockContract), "Qux");
     string json = JsonConvert.SerializeObject(discretional, new JsonSerializerSettings { ContractResolver = resolver });
     Assert.IsTrue(json.Contains("Qux"));
 }
コード例 #5
0
 public void IncludeSubTypeProps()
 {
     MockContract discretional = new MockContract
                                 { SubType = new MockContractSub() };
     OptionalContractResolver resolver = new OptionalContractResolver();
     resolver.Add(typeof(MockContract), "SubType");
     string json = JsonConvert.SerializeObject(discretional, new JsonSerializerSettings { ContractResolver = resolver });
     Assert.IsTrue(json.Contains("Corge"));
 }