public void Serialize_UnIgnorePrivateField() { TestA ta = new TestA(); ta.SetIgnoredPrivateField(1); ContractConfiguration <TestA> cc = new ContractConfiguration <TestA>(); cc.Field("ignoredPrivateField").Ignore(false).HasName("unignored_private_field"); var json = JsonConvert.SerializeObject(ta, GetSettings(cc)); JsonStringValidator jsAssert = new JsonStringValidator(json); Assert.IsTrue(jsAssert.HasPropertyWithValue("unignored_private_field", 1)); }
public void Serialize_OverridePrivatePropertyName() { TestA ta = new TestA(); ta.SetPrivateProp(1); ContractConfiguration <TestA> cc = new ContractConfiguration <TestA>(); cc.Property("PrivateProp").HasName("private_prop"); var json = JsonConvert.SerializeObject(ta, GetSettings(cc)); JsonStringValidator jsAssert = new JsonStringValidator(json); Assert.IsTrue(jsAssert.HasPropertyWithValue("private_prop", 1)); }
public void Serialize_OverridePropertyName() { TestA ta = new TestA() { IdA = 1 }; ContractConfiguration <TestA> cc = new ContractConfiguration <TestA>(); cc.Property(ta => ta.IdA).HasName("id_a"); var json = JsonConvert.SerializeObject(ta, GetSettings(cc)); JsonStringValidator jsAssert = new JsonStringValidator(json); Assert.IsTrue(jsAssert.HasPropertyWithValue("id_a", 1)); }
public void Serialize_UnnamedProperty() { TestA ta = new TestA() { UnnamedProperty = 1 }; ContractConfiguration <TestA> cc = new ContractConfiguration <TestA>(); cc.Property(ta => ta.UnnamedProperty).HasName("unnamed_property"); var json = JsonConvert.SerializeObject(ta, GetSettings(cc)); JsonStringValidator jsAssert = new JsonStringValidator(json); Assert.IsTrue(jsAssert.HasPropertyWithValue("unnamed_property", 1)); }
public void Serialize_NestedObjectNaming() { TestA ta = new TestA(); ta.TestBReference = new TestB() { IdB = 1 }; ContractConfiguration <TestB> cc = new ContractConfiguration <TestB>(); cc.Property(tb => tb.IdB).HasName("id_b"); var json = JsonConvert.SerializeObject(ta, GetSettings(cc)); JsonStringValidator jsAssert = new JsonStringValidator(json, jt => jt["testB"]); Assert.IsTrue(jsAssert.HasPropertyWithValue("id_b", 1)); }
public void Serialize_NestedArrayNaming() { TestB tb = new TestB() { IdB = 1 }; var tas = new TestA[] { new TestA() { IdA = 1 }, new TestA() { IdA = 2 }, new TestA() { IdA = 3 }, new TestA() { IdA = 4 }, }; tb.TestAReferences.AddRange(tas); ContractConfiguration <TestA> cc = new ContractConfiguration <TestA>(); cc.Property(ta => ta.IdA).HasName("id_a"); var json = JsonConvert.SerializeObject(tb, GetSettings(cc)); for (int i = 0; i < tas.Length; i++) { JsonStringValidator jsAssert = new JsonStringValidator(json, jt => jt["testAs"].Cast <JObject>().ElementAt(i)); Assert.IsTrue(jsAssert.HasPropertyWithValue("id_a", i + 1)); } }