-Replace tests console writes with asserts
This commit is contained in:
@@ -373,7 +373,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
public void PopulateTest()
|
||||
{
|
||||
var test = JsonConvert.DeserializeObject<PopulateWithNullJsonTest>("{\"IntValue\":null}");
|
||||
Console.WriteLine("IntValue:{0}", test.IntValue);
|
||||
Assert.AreEqual(0, test.IntValue);
|
||||
}
|
||||
|
||||
public class PopulateWithNullJsonTest
|
||||
|
||||
@@ -123,7 +123,16 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
TypeNameAssemblyFormat = FormatterAssemblyStyle.Full
|
||||
});
|
||||
|
||||
Console.WriteLine(json);
|
||||
Assert.AreEqual(@"{
|
||||
""$type"": ""System.Dynamic.ExpandoObject, System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"",
|
||||
""Text"": ""Text!"",
|
||||
""Integer"": 2147483647,
|
||||
""DynamicChildObject"": {
|
||||
""$type"": ""Newtonsoft.Json.Tests.Serialization.DynamicChildObject, Newtonsoft.Json.Tests, Version=7.0.0.0, Culture=neutral, PublicKeyToken=null"",
|
||||
""Text"": ""Child text!"",
|
||||
""Integer"": -2147483648
|
||||
}
|
||||
}", json);
|
||||
|
||||
string dynamicChildObjectTypeName = ReflectionUtils.GetTypeName(typeof(DynamicChildObject), FormatterAssemblyStyle.Full, null);
|
||||
string expandoObjectTypeName = ReflectionUtils.GetTypeName(typeof(ExpandoObject), FormatterAssemblyStyle.Full, null);
|
||||
@@ -268,8 +277,6 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
});
|
||||
|
||||
Console.WriteLine(json);
|
||||
|
||||
StringAssert.AreEqual(@"{
|
||||
""Explicit"": false,
|
||||
""Text"": ""Text!"",
|
||||
@@ -291,8 +298,6 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
NullValueHandling = NullValueHandling.Include,
|
||||
});
|
||||
|
||||
Console.WriteLine(json);
|
||||
|
||||
StringAssert.AreEqual(@"{
|
||||
""Explicit"": false,
|
||||
""Text"": ""Text!"",
|
||||
@@ -318,8 +323,6 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore,
|
||||
});
|
||||
|
||||
Console.WriteLine(json);
|
||||
|
||||
StringAssert.AreEqual(@"{
|
||||
""Text"": ""Text!"",
|
||||
""Int"": 2147483647
|
||||
|
||||
@@ -150,7 +150,13 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
|
||||
string json = JsonConvert.SerializeObject(e, Formatting.Indented);
|
||||
|
||||
Console.WriteLine(json);
|
||||
Assert.AreEqual(@"{
|
||||
""extensionData1"": [
|
||||
1,
|
||||
2,
|
||||
3
|
||||
]
|
||||
}", json);
|
||||
|
||||
Example e2 = JsonConvert.DeserializeObject<Example>(json);
|
||||
|
||||
|
||||
@@ -66,9 +66,6 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
""II"",
|
||||
""3""
|
||||
]", json);
|
||||
|
||||
Console.WriteLine("Serialized immutable list:");
|
||||
Console.WriteLine(json);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -100,17 +97,10 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
// what sorcery is this?!
|
||||
IImmutableList<string> champions = JsonConvert.DeserializeObject<IImmutableList<string>>(json);
|
||||
|
||||
Console.WriteLine(champions[0]);
|
||||
// Volibear
|
||||
|
||||
Assert.AreEqual(3, champions.Count);
|
||||
Assert.AreEqual("Volibear", champions[0]);
|
||||
Assert.AreEqual("Teemo", champions[1]);
|
||||
Assert.AreEqual("Katarina", champions[2]);
|
||||
|
||||
Console.WriteLine("Deserialized immutable list:");
|
||||
Console.WriteLine(string.Join(", ", champions));
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -1522,16 +1522,10 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
|
||||
List<Product> products = JsonConvert.DeserializeObject<List<Product>>(json);
|
||||
|
||||
Console.WriteLine(products.Count);
|
||||
// 2
|
||||
|
||||
Product p1 = products[0];
|
||||
|
||||
Console.WriteLine(p1.Name);
|
||||
// Product 1
|
||||
|
||||
Assert.AreEqual(2, products.Count);
|
||||
Assert.AreEqual("Product 1", products[0].Name);
|
||||
Assert.AreEqual("Product 1", p1.Name);
|
||||
}
|
||||
|
||||
#if !(NET40 || NET35 || NET20 || PORTABLE40)
|
||||
|
||||
@@ -229,8 +229,6 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
|
||||
string json = JsonConvert.SerializeObject(c, Formatting.Indented);
|
||||
|
||||
Console.WriteLine(json);
|
||||
|
||||
StringAssert.AreEqual(@"{
|
||||
""FaqId"": 1,
|
||||
""Name"": null,
|
||||
@@ -256,8 +254,6 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
|
||||
string json = JsonConvert.SerializeObject(c, Formatting.Indented);
|
||||
|
||||
Console.WriteLine(json);
|
||||
|
||||
StringAssert.AreEqual(@"{
|
||||
""IsProxy"": true,
|
||||
""FaqId"": 1,
|
||||
@@ -1117,8 +1113,6 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
var stopWatch = Stopwatch.StartNew();
|
||||
var deserialize = jsonSerializer.Deserialize(new StreamReader(ms), typeof(Dictionary<DictionaryKeyCast, int>));
|
||||
stopWatch.Stop();
|
||||
|
||||
Console.WriteLine("Time elapsed: " + stopWatch.ElapsedMilliseconds);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1308,8 +1302,6 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
|
||||
string json = JsonConvert.SerializeObject(baseWith, Formatting.Indented);
|
||||
|
||||
Console.WriteLine(json);
|
||||
|
||||
StringAssert.AreEqual(@"{
|
||||
""VirtualWithDataMemberBase"": ""VirtualWithDataMember2!"",
|
||||
""VirtualSub"": ""Virtual2!"",
|
||||
@@ -1388,9 +1380,9 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
JObject jsonNetJson = JObject.Parse(JsonConvert.SerializeObject(o));
|
||||
jsonNetJson = new JObject(jsonNetJson.Properties().OrderBy(p => p.Name));
|
||||
|
||||
Console.WriteLine("Results for " + o.GetType().Name);
|
||||
Console.WriteLine("DataContractJsonSerializer: " + dataContractJson);
|
||||
Console.WriteLine("JsonDotNetSerializer : " + jsonNetJson);
|
||||
//Console.WriteLine("Results for " + o.GetType().Name);
|
||||
//Console.WriteLine("DataContractJsonSerializer: " + dataContractJson);
|
||||
//Console.WriteLine("JsonDotNetSerializer : " + jsonNetJson);
|
||||
|
||||
Assert.AreEqual(dataContractJson.Count, jsonNetJson.Count);
|
||||
foreach (KeyValuePair<string, JToken> property in dataContractJson)
|
||||
@@ -2235,11 +2227,10 @@ keyword such as type of business.""
|
||||
|
||||
string json = JsonConvert.SerializeObject(c, Formatting.Indented);
|
||||
|
||||
Console.WriteLine(json);
|
||||
//{
|
||||
// "DefaultConverter": "\/Date(0)\/",
|
||||
// "MemberConverter": "1970-01-01T00:00:00Z"
|
||||
//}
|
||||
Assert.AreEqual(@"{
|
||||
""DefaultConverter"": ""1970-01-01T00:00:00Z"",
|
||||
""MemberConverter"": ""1970-01-01T00:00:00Z""
|
||||
}", json);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -2454,7 +2445,6 @@ keyword such as type of business.""
|
||||
};
|
||||
|
||||
string json = JsonConvert.SerializeObject(requiredMembersClass);
|
||||
Console.WriteLine(json);
|
||||
}, "Cannot write a null value for property 'FirstName'. Property requires a value. Path ''.");
|
||||
}
|
||||
|
||||
@@ -2591,9 +2581,9 @@ keyword such as type of business.""
|
||||
string javascriptJson = JsonConvert.SerializeObject(entry, new JavaScriptDateTimeConverter());
|
||||
// {"Details":"Application started.","LogDate":new Date(1234656000000)}
|
||||
|
||||
Console.WriteLine(defaultJson);
|
||||
Console.WriteLine(isoJson);
|
||||
Console.WriteLine(javascriptJson);
|
||||
Assert.AreEqual(@"{""Details"":""Application started."",""LogDate"":""2009-02-15T00:00:00Z""}", defaultJson);
|
||||
Assert.AreEqual(@"{""Details"":""Application started."",""LogDate"":""2009-02-15T00:00:00Z""}", isoJson);
|
||||
Assert.AreEqual(@"{""Details"":""Application started."",""LogDate"":new Date(1234656000000)}", javascriptJson);
|
||||
}
|
||||
|
||||
public void GenericListAndDictionaryInterfaceProperties()
|
||||
@@ -3157,12 +3147,6 @@ keyword such as type of business.""
|
||||
|
||||
Dictionary<string, string> values = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
|
||||
|
||||
Console.WriteLine(values.Count);
|
||||
// 2
|
||||
|
||||
Console.WriteLine(values["key1"]);
|
||||
// value1
|
||||
|
||||
Assert.AreEqual(2, values.Count);
|
||||
Assert.AreEqual("value1", values["key1"]);
|
||||
Assert.AreEqual("value2", values["key2"]);
|
||||
@@ -3455,7 +3439,7 @@ Path '', line 1, position 1.");
|
||||
};
|
||||
|
||||
string json = JsonConvert.SerializeObject(structTest, Formatting.Indented);
|
||||
Console.WriteLine(json);
|
||||
|
||||
StringAssert.AreEqual(@"{
|
||||
""StringField"": ""StringField"",
|
||||
""IntField"": 10,
|
||||
@@ -4857,7 +4841,7 @@ Path '', line 1, position 1.");
|
||||
|
||||
string json = JsonConvert.SerializeObject(child);
|
||||
|
||||
Console.WriteLine(json);
|
||||
Assert.AreEqual(@"{""_id"":2,""Name"":""Isabell"",""Father"":{""$ref"":null,""$id"":null,""blah"":""blah!""}}", json);
|
||||
|
||||
Dictionary<string, object> result = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
|
||||
|
||||
@@ -5700,7 +5684,10 @@ Path '', line 1, position 1.");
|
||||
// ""nonVirtualMember"": ""NonVirtualMember!""
|
||||
//}", result);
|
||||
|
||||
Console.WriteLine(result);
|
||||
Assert.AreEqual(@"{
|
||||
""virtualMember"": ""VirtualMember!"",
|
||||
""nonVirtualMember"": ""NonVirtualMember!""
|
||||
}", result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -5719,7 +5706,7 @@ Path '', line 1, position 1.");
|
||||
|
||||
string xml = Encoding.UTF8.GetString(ms.ToArray(), 0, Convert.ToInt32(ms.Length));
|
||||
|
||||
Console.WriteLine(xml);
|
||||
Assert.AreEqual(@"<JsonSerializerTest.ChildDataContract xmlns=""http://schemas.datacontract.org/2004/07/Newtonsoft.Json.Tests.Serialization"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><nonVirtualMember>NonVirtualMember!</nonVirtualMember><virtualMember>VirtualMember!</virtualMember><NewMember i:nil=""true""/></JsonSerializerTest.ChildDataContract>", xml);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -5768,7 +5755,6 @@ Path '', line 1, position 1.");
|
||||
};
|
||||
|
||||
string result = JsonConvert.SerializeObject(cc);
|
||||
Console.WriteLine(result);
|
||||
Assert.AreEqual(@"{""differentVirtualMember"":""VirtualMember!"",""nonVirtualMember"":""NonVirtualMember!""}", result);
|
||||
}
|
||||
|
||||
@@ -6908,8 +6894,11 @@ Path '', line 1, position 1.");
|
||||
|
||||
JArray a = (JArray)JArray.ReadFrom(reader);
|
||||
JValue v = (JValue)a[0];
|
||||
Console.WriteLine(v.Value.GetType());
|
||||
Console.WriteLine(a.ToString());
|
||||
|
||||
Assert.AreEqual(typeof(string), v.Value.GetType());
|
||||
Assert.AreEqual(@"[
|
||||
""2000-01-02T03:04:05+06:00""
|
||||
]", a.ToString());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -7907,15 +7896,11 @@ Path '', line 1, position 1.");
|
||||
|
||||
string expected = JsonConvert.SerializeObject(dates, Formatting.Indented);
|
||||
|
||||
Console.WriteLine(expected);
|
||||
|
||||
string actual = JsonConvert.SerializeObject(dates, Formatting.Indented, new JsonSerializerSettings
|
||||
{
|
||||
DateFormatString = JsonSerializerSettings.DefaultDateFormatString
|
||||
});
|
||||
|
||||
Console.WriteLine(expected);
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
#endif
|
||||
@@ -8202,7 +8187,8 @@ Path '', line 1, position 1.");
|
||||
ParticipantEntity product = new ParticipantEntity();
|
||||
product.Properties = new Dictionary<string, string> { { "s", "d" } };
|
||||
string json = JsonConvert.SerializeObject(product);
|
||||
Console.WriteLine(json);
|
||||
|
||||
Assert.AreEqual(@"{""pa_info"":{""s"":""d""}}", json);
|
||||
ParticipantEntity deserializedProduct = JsonConvert.DeserializeObject<ParticipantEntity>(json);
|
||||
}
|
||||
|
||||
@@ -8601,8 +8587,6 @@ Path '', line 1, position 1.");
|
||||
var serializerSettings = new JsonSerializerSettings();
|
||||
var jsonCopy = JsonConvert.SerializeObject(original, serializerSettings);
|
||||
|
||||
Console.WriteLine(original);
|
||||
|
||||
var clonedObject = JsonConvert.DeserializeObject<DerivedConstructorType>(jsonCopy, serializerSettings);
|
||||
|
||||
Assert.AreEqual("Base", clonedObject.BaseProperty);
|
||||
|
||||
@@ -70,8 +70,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
|
||||
User u = (User)o;
|
||||
|
||||
Console.WriteLine(u.Name);
|
||||
// James
|
||||
Assert.AreEqual(u.Name, "James");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -119,7 +118,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
public void SerializeDeserialize_DictionaryContextContainsGuid_DeserializesItemAsGuid()
|
||||
{
|
||||
const string contextKey = "k1";
|
||||
var someValue = Guid.NewGuid();
|
||||
var someValue = new Guid("5dd2dba0-20c0-49f8-a054-1fa3b0a8d774");
|
||||
|
||||
Dictionary<string, Guid> inputContext = new Dictionary<string, Guid>();
|
||||
inputContext.Add(contextKey, someValue);
|
||||
@@ -132,7 +131,10 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
};
|
||||
string serializedString = JsonConvert.SerializeObject(inputContext, jsonSerializerSettings);
|
||||
|
||||
Console.WriteLine(serializedString);
|
||||
Assert.AreEqual(@"{
|
||||
""$type"": ""System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[System.Guid, mscorlib]], mscorlib"",
|
||||
""k1"": ""5dd2dba0-20c0-49f8-a054-1fa3b0a8d774""
|
||||
}", serializedString);
|
||||
|
||||
var deserializedObject = (Dictionary<string, Guid>)JsonConvert.DeserializeObject(serializedString, jsonSerializerSettings);
|
||||
|
||||
@@ -257,7 +259,15 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
|
||||
string json = JsonConvert.SerializeObject(child, Formatting.Indented);
|
||||
|
||||
Console.WriteLine(json);
|
||||
Assert.AreEqual(@"{
|
||||
""_id"": 2,
|
||||
""Name"": ""Isabell"",
|
||||
""Father"": {
|
||||
""blah"": ""blah!"",
|
||||
""$ref"": null,
|
||||
""$id"": null
|
||||
}
|
||||
}", json);
|
||||
|
||||
Dictionary<string, object> result = JsonConvert.DeserializeObject<Dictionary<string, object>>(json, new JsonSerializerSettings
|
||||
{
|
||||
|
||||
@@ -823,19 +823,16 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
List<Person> deserializedPeople = JsonConvert.DeserializeObject<List<Person>>(json,
|
||||
new JsonSerializerSettings { PreserveReferencesHandling = PreserveReferencesHandling.Objects });
|
||||
|
||||
Console.WriteLine(deserializedPeople.Count);
|
||||
// 2
|
||||
Assert.AreEqual(2, deserializedPeople.Count);
|
||||
|
||||
Person p1 = deserializedPeople[0];
|
||||
Person p2 = deserializedPeople[1];
|
||||
|
||||
Console.WriteLine(p1.Name);
|
||||
// James
|
||||
Console.WriteLine(p2.Name);
|
||||
// James
|
||||
Assert.AreEqual("James", p1.Name);
|
||||
Assert.AreEqual("James", p2.Name);
|
||||
|
||||
bool equal = Object.ReferenceEquals(p1, p2);
|
||||
// true
|
||||
Assert.AreEqual(true, equal);
|
||||
}
|
||||
|
||||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
|
||||
|
||||
@@ -370,13 +370,6 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
|
||||
string json = JsonConvert.SerializeObject(person, Formatting.Indented);
|
||||
|
||||
Console.WriteLine(json);
|
||||
//{
|
||||
// "Name": "George Michael Bluth",
|
||||
// "Age": 16,
|
||||
// "Title": "Mister Manager"
|
||||
//}
|
||||
|
||||
StringAssert.AreEqual(@"{
|
||||
""Name"": ""George Michael Bluth"",
|
||||
""Age"": 16,
|
||||
|
||||
@@ -219,45 +219,32 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
{
|
||||
SerializationEventTestObject obj = new SerializationEventTestObject();
|
||||
|
||||
Console.WriteLine(obj.Member1);
|
||||
// 11
|
||||
Console.WriteLine(obj.Member2);
|
||||
// Hello World!
|
||||
Console.WriteLine(obj.Member3);
|
||||
// This is a nonserialized value
|
||||
Console.WriteLine(obj.Member4);
|
||||
// null
|
||||
Console.WriteLine(obj.Member5);
|
||||
// null
|
||||
Assert.AreEqual(11, obj.Member1);
|
||||
Assert.AreEqual("Hello World!", obj.Member2);
|
||||
Assert.AreEqual("This is a nonserialized value", obj.Member3);
|
||||
Assert.AreEqual(null, obj.Member4);
|
||||
Assert.AreEqual(null, obj.Member5);
|
||||
|
||||
string json = JsonConvert.SerializeObject(obj, Formatting.Indented);
|
||||
// {
|
||||
// "Member1": 11,
|
||||
// "Member2": "This value went into the data file during serialization.",
|
||||
// "Member4": null
|
||||
// }
|
||||
Assert.AreEqual(@"{
|
||||
""Member1"": 11,
|
||||
""Member2"": ""This value went into the data file during serialization."",
|
||||
""Member4"": null
|
||||
}", json);
|
||||
|
||||
Console.WriteLine(obj.Member1);
|
||||
// 11
|
||||
Console.WriteLine(obj.Member2);
|
||||
// This value was reset after serialization.
|
||||
Console.WriteLine(obj.Member3);
|
||||
// This is a nonserialized value
|
||||
Console.WriteLine(obj.Member4);
|
||||
// null
|
||||
Console.WriteLine(obj.Member5);
|
||||
// Error message for member Member6 = Exception has been thrown by the target of an invocation.
|
||||
Assert.AreEqual(11, obj.Member1);
|
||||
Assert.AreEqual("This value was reset after serialization.", obj.Member2);
|
||||
Assert.AreEqual("This is a nonserialized value", obj.Member3);
|
||||
Assert.AreEqual(null, obj.Member4);
|
||||
Assert.AreEqual("Error message for member Member6 = Error getting value from 'Member6' on 'Newtonsoft.Json.Tests.TestObjects.SerializationEventTestObject'.", obj.Member5);
|
||||
|
||||
obj = JsonConvert.DeserializeObject<SerializationEventTestObject>(json);
|
||||
|
||||
Console.WriteLine(obj.Member1);
|
||||
// 11
|
||||
Console.WriteLine(obj.Member2);
|
||||
// This value went into the data file during serialization.
|
||||
Console.WriteLine(obj.Member3);
|
||||
// This value was set during deserialization
|
||||
Console.WriteLine(obj.Member4);
|
||||
// This value was set after deserialization.
|
||||
Assert.AreEqual(11, obj.Member1);
|
||||
Assert.AreEqual("This value went into the data file during serialization.", obj.Member2);
|
||||
Assert.AreEqual("This value was set during deserialization", obj.Member3);
|
||||
Assert.AreEqual("This value was set after deserialization.", obj.Member4);
|
||||
Assert.AreEqual(null, obj.Member5);
|
||||
}
|
||||
|
||||
public class SerializationEventBaseTestObject
|
||||
@@ -356,9 +343,6 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
// persisted "Id" value into the renamed "Identifier"
|
||||
// property, etc.
|
||||
error.Handled = true;
|
||||
|
||||
// We never get here :(
|
||||
Console.WriteLine("Error has been fixed");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -135,8 +135,6 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
jsonSerializer.Serialize(jsonWriter, f, typeof(Foo1));
|
||||
}
|
||||
|
||||
Console.WriteLine("Trace output:\n{0}", traceWriter.ToString());
|
||||
|
||||
return sw.ToString();
|
||||
}
|
||||
|
||||
@@ -190,7 +188,17 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
// }
|
||||
// ]
|
||||
|
||||
Console.WriteLine(json);
|
||||
Assert.AreEqual(@"[
|
||||
{
|
||||
""Name"": ""Joe Employee"",
|
||||
""Manager"": {
|
||||
""Name"": ""Mike Manager""
|
||||
}
|
||||
},
|
||||
{
|
||||
""Name"": ""Mike Manager""
|
||||
}
|
||||
]", json);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -322,17 +330,26 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
// "Name": "Martha Family Details"
|
||||
// }
|
||||
//]
|
||||
Console.WriteLine(json);
|
||||
|
||||
Assert.AreEqual(@"[
|
||||
{
|
||||
""Name"": ""Joe Family Details"",
|
||||
""NumberOfChildren"": 4
|
||||
},
|
||||
{
|
||||
""Name"": ""Martha Family Details""
|
||||
}
|
||||
]", json);
|
||||
|
||||
string mikeString = "{\"Name\": \"Mike Person\"}";
|
||||
FamilyDetails mike = JsonConvert.DeserializeObject<FamilyDetails>(mikeString);
|
||||
|
||||
Console.WriteLine("mikeString specifies number of children: {0}", mike.NumberOfChildrenSpecified);
|
||||
Assert.AreEqual(false, mike.NumberOfChildrenSpecified);
|
||||
|
||||
string mikeFullDisclosureString = "{\"Name\": \"Mike Person\", \"NumberOfChildren\": \"0\"}";
|
||||
mike = JsonConvert.DeserializeObject<FamilyDetails>(mikeFullDisclosureString);
|
||||
|
||||
Console.WriteLine("mikeString specifies number of children: {0}", mike.NumberOfChildrenSpecified);
|
||||
Assert.AreEqual(true, mike.NumberOfChildrenSpecified);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -90,7 +90,6 @@ Newtonsoft.Json Error: 0 : Error!
|
||||
staff,
|
||||
new JsonSerializerSettings { TraceWriter = traceWriter, Converters = { new JavaScriptDateTimeConverter() } });
|
||||
|
||||
Console.WriteLine(traceWriter);
|
||||
// 2012-11-11T12:08:42.761 Info Started serializing Newtonsoft.Json.Tests.Serialization.Staff. Path ''.
|
||||
// 2012-11-11T12:08:42.785 Info Started serializing System.DateTime with converter Newtonsoft.Json.Converters.JavaScriptDateTimeConverter. Path 'StartDate'.
|
||||
// 2012-11-11T12:08:42.791 Info Finished serializing System.DateTime with converter Newtonsoft.Json.Converters.JavaScriptDateTimeConverter. Path 'StartDate'.
|
||||
@@ -150,7 +149,6 @@ Newtonsoft.Json Error: 0 : Error!
|
||||
MetadataPropertyHandling = MetadataPropertyHandling.Default
|
||||
});
|
||||
|
||||
Console.WriteLine(traceWriter);
|
||||
// 2012-11-11T12:08:42.761 Info Started serializing Newtonsoft.Json.Tests.Serialization.Staff. Path ''.
|
||||
// 2012-11-11T12:08:42.785 Info Started serializing System.DateTime with converter Newtonsoft.Json.Converters.JavaScriptDateTimeConverter. Path 'StartDate'.
|
||||
// 2012-11-11T12:08:42.791 Info Finished serializing System.DateTime with converter Newtonsoft.Json.Converters.JavaScriptDateTimeConverter. Path 'StartDate'.
|
||||
@@ -878,8 +876,6 @@ Newtonsoft.Json Error: 0 : Error!
|
||||
traceWriter.Flush();
|
||||
traceWriter.Close();
|
||||
|
||||
Console.WriteLine(traceWriter.GetJson());
|
||||
|
||||
StringAssert.AreEqual(@"{
|
||||
""Array"": [
|
||||
""String!"",
|
||||
@@ -1039,8 +1035,6 @@ Newtonsoft.Json Error: 0 : Error!
|
||||
|
||||
traceReader.Close();
|
||||
|
||||
Console.WriteLine(traceReader.GetJson());
|
||||
|
||||
StringAssert.AreEqual(json, traceReader.GetJson());
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -101,8 +101,6 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
TypeNameHandling = TypeNameHandling.Auto
|
||||
});
|
||||
|
||||
Console.WriteLine(json);
|
||||
|
||||
StringAssert.AreEqual(@"{
|
||||
""Collection"": [
|
||||
""Collection value!""
|
||||
@@ -1132,7 +1130,6 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
|
||||
private void TestJsonSerializationRoundTrip(SerializableWrapper e, TypeNameHandling flag)
|
||||
{
|
||||
Console.WriteLine("Type Name Handling: " + flag.ToString());
|
||||
StringWriter writer = new StringWriter();
|
||||
|
||||
//Create our serializer and set Type Name Handling appropriately
|
||||
@@ -1141,8 +1138,6 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
|
||||
//Do the actual serialization and dump to Console for inspection
|
||||
serializer.Serialize(new JsonTextWriter(writer), e);
|
||||
Console.WriteLine(writer.ToString());
|
||||
Console.WriteLine();
|
||||
|
||||
//Now try to deserialize
|
||||
//Json.Net will cause an error here as it will try and instantiate
|
||||
@@ -1653,7 +1648,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
public void SerializeDeserialize_DictionaryContextContainsGuid_DeserializesItemAsGuid()
|
||||
{
|
||||
const string contextKey = "k1";
|
||||
var someValue = Guid.NewGuid();
|
||||
var someValue = new Guid("a6e986df-fc2c-4906-a1ef-9492388f7833");
|
||||
|
||||
Dictionary<string, Guid> inputContext = new Dictionary<string, Guid>();
|
||||
inputContext.Add(contextKey, someValue);
|
||||
@@ -1665,7 +1660,10 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
};
|
||||
string serializedString = JsonConvert.SerializeObject(inputContext, jsonSerializerSettings);
|
||||
|
||||
Console.WriteLine(serializedString);
|
||||
Assert.AreEqual(@"{
|
||||
""$type"": ""System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[System.Guid, mscorlib]], mscorlib"",
|
||||
""k1"": ""a6e986df-fc2c-4906-a1ef-9492388f7833""
|
||||
}", serializedString);
|
||||
|
||||
var deserializedObject = (Dictionary<string, Guid>)JsonConvert.DeserializeObject(serializedString, jsonSerializerSettings);
|
||||
|
||||
@@ -1799,19 +1797,15 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All, TypeNameAssemblyFormat = FormatterAssemblyStyle.Full } // TypeNameHandling.Auto will work
|
||||
);
|
||||
|
||||
Console.WriteLine(serialized);
|
||||
|
||||
var output = JsonConvert.DeserializeObject<List<Stack<string>>>(serialized,
|
||||
new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }
|
||||
);
|
||||
|
||||
foreach (var stack in output)
|
||||
{
|
||||
foreach (var value in stack)
|
||||
{
|
||||
Console.WriteLine(value);
|
||||
}
|
||||
}
|
||||
List<string> strings = output.SelectMany(s => s).ToList();
|
||||
|
||||
Assert.AreEqual(9, strings.Count);
|
||||
Assert.AreEqual("One", strings[0]);
|
||||
Assert.AreEqual("Nine", strings[8]);
|
||||
}
|
||||
|
||||
#if !NET20
|
||||
|
||||
Reference in New Issue
Block a user