-Formatting

-Build
This commit is contained in:
James Newton-King
2015-12-04 23:54:38 +13:00
parent c96779dc10
commit eb0cbd6a75
334 changed files with 3952 additions and 514 deletions
+5 -4
View File
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8"?>
<configuration> <configuration>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup> </startup>
</configuration> </configuration>
@@ -3,6 +3,6 @@
"net45": {} "net45": {}
}, },
"runtimes": { "runtimes": {
"win-anycpu": {} "win": {}
} }
} }
@@ -30,6 +30,7 @@ using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information // set of attributes. Change these attribute values to modify the information
// associated with an assembly. // associated with an assembly.
[assembly: AssemblyTitle("Json.NET Test Console")] [assembly: AssemblyTitle("Json.NET Test Console")]
[assembly: AssemblyDescription("")] [assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
@@ -42,9 +43,11 @@ using System.Runtime.InteropServices;
// Setting ComVisible to false makes the types in this assembly not visible // Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from // to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type. // COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)] [assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM // The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("bf0cc842-d368-4800-9614-b5abcc736110")] [assembly: Guid("bf0cc842-d368-4800-9614-b5abcc736110")]
// Version information for an assembly consists of the following four values: // Version information for an assembly consists of the following four values:
@@ -56,5 +59,6 @@ using System.Runtime.InteropServices;
// //
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
[assembly: AssemblyVersion("7.0.0.0")] [assembly: AssemblyVersion("7.0.0.0")]
[assembly: AssemblyFileVersion("7.0.2.18802")] [assembly: AssemblyFileVersion("7.0.2.18802")]
@@ -920,7 +920,9 @@ namespace Newtonsoft.Json.Tests.Bson
for (int i = 0; i < 100; i++) for (int i = 0; i < 100; i++)
{ {
if (i > 0) if (i > 0)
{
largeStringBuilder.Append("-"); largeStringBuilder.Append("-");
}
largeStringBuilder.Append(i.ToString(CultureInfo.InvariantCulture)); largeStringBuilder.Append(i.ToString(CultureInfo.InvariantCulture));
} }
@@ -1606,6 +1608,7 @@ namespace Newtonsoft.Json.Tests.Bson
#if !(NET20 || NET35) #if !(NET20 || NET35)
public bool BindToNameCalled { get; set; } public bool BindToNameCalled { get; set; }
public override void BindToName(Type serializedType, out string assemblyName, out string typeName) public override void BindToName(Type serializedType, out string assemblyName, out string typeName)
{ {
BindToNameCalled = true; BindToNameCalled = true;
@@ -301,7 +301,9 @@ namespace Newtonsoft.Json.Tests.Bson
for (int i = 0; i < 100; i++) for (int i = 0; i < 100; i++)
{ {
if (i > 0) if (i > 0)
{
largeStringBuilder.Append("-"); largeStringBuilder.Append("-");
}
largeStringBuilder.Append(i.ToString(CultureInfo.InvariantCulture)); largeStringBuilder.Append(i.ToString(CultureInfo.InvariantCulture));
} }
@@ -483,7 +485,6 @@ namespace Newtonsoft.Json.Tests.Bson
// 6D-61-6C-6C-00-02-31-00-07-00-00-00-4D-65-64-69-75-6D- // 6D-61-6C-6C-00-02-31-00-07-00-00-00-4D-65-64-69-75-6D-
// 00-02-32-00-06-00-00-00-4C-61-72-67-65-00-00-00 // 00-02-32-00-06-00-00-00-4C-61-72-67-65-00-00-00
ms.Seek(0, SeekOrigin.Begin); ms.Seek(0, SeekOrigin.Begin);
// deserialize product from BSON // deserialize product from BSON
@@ -493,7 +494,6 @@ namespace Newtonsoft.Json.Tests.Bson
Console.WriteLine(deserializedProduct.Name); Console.WriteLine(deserializedProduct.Name);
// Carlos' Spicy Wieners // Carlos' Spicy Wieners
Assert.AreEqual("Carlos' Spicy Wieners", deserializedProduct.Name); Assert.AreEqual("Carlos' Spicy Wieners", deserializedProduct.Name);
Assert.AreEqual(9.95m, deserializedProduct.Price); Assert.AreEqual(9.95m, deserializedProduct.Price);
Assert.AreEqual(3, deserializedProduct.Sizes.Length); Assert.AreEqual(3, deserializedProduct.Sizes.Length);
@@ -745,10 +745,7 @@ namespace Newtonsoft.Json.Tests.Bson
BsonWriter writer = new BsonWriter(ms); BsonWriter writer = new BsonWriter(ms);
ExceptionAssert.Throws<JsonWriterException>(() => ExceptionAssert.Throws<JsonWriterException>(() => { serializer.Serialize(writer, b); }, "Error writing Binary value. BSON must start with an Object or Array. Path ''.");
{
serializer.Serialize(writer, b);
}, "Error writing Binary value. BSON must start with an Object or Array. Path ''.");
} }
public class GuidTestClass public class GuidTestClass
@@ -43,6 +43,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Converters namespace Newtonsoft.Json.Tests.Converters
@@ -36,6 +36,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Converters namespace Newtonsoft.Json.Tests.Converters
@@ -590,4 +590,5 @@ namespace Newtonsoft.Json.Tests.Converters
} }
} }
} }
#endif #endif
@@ -524,20 +524,29 @@ namespace Newtonsoft.Json.Tests.Converters
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{ {
if (reader.Value == null || reader.Value == DBNull.Value) if (reader.Value == null || reader.Value == DBNull.Value)
{
return System.Data.SqlTypes.SqlDateTime.Null; return System.Data.SqlTypes.SqlDateTime.Null;
}
else else
{
return new System.Data.SqlTypes.SqlDateTime((DateTime)serializer.Deserialize(reader)); return new System.Data.SqlTypes.SqlDateTime((DateTime)serializer.Deserialize(reader));
}
} }
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{ {
if (((System.Data.SqlTypes.SqlDateTime)value).IsNull) if (((System.Data.SqlTypes.SqlDateTime)value).IsNull)
{
writer.WriteNull(); writer.WriteNull();
}
else else
{
writer.WriteValue(((System.Data.SqlTypes.SqlDateTime)value).Value); writer.WriteValue(((System.Data.SqlTypes.SqlDateTime)value).Value);
}
} }
} }
#endif #endif
} }
} }
#endif #endif
@@ -300,4 +300,5 @@ namespace Newtonsoft.Json.Tests.Converters
} }
} }
} }
#endif #endif
@@ -40,6 +40,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Converters namespace Newtonsoft.Json.Tests.Converters
@@ -256,9 +256,13 @@ namespace Newtonsoft.Json.Tests.Converters
// if the current timezone is utc then local already equals utc // if the current timezone is utc then local already equals utc
if (offset == TimeSpan.Zero) if (offset == TimeSpan.Zero)
{
Assert.AreEqual(json, json2); Assert.AreEqual(json, json2);
}
else else
{
Assert.AreNotEqual(json, json2); Assert.AreNotEqual(json, json2);
}
} }
#endif #endif
@@ -227,9 +227,13 @@ namespace Newtonsoft.Json.Tests.Converters
{ {
DateTime? d = (DateTime?)value; DateTime? d = (DateTime?)value;
if (d == null) if (d == null)
{
writer.WriteNull(); writer.WriteNull();
}
else else
{
writer.WriteValue(d.Value.Ticks); writer.WriteValue(d.Value.Ticks);
}
} }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
@@ -13,6 +13,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Converters namespace Newtonsoft.Json.Tests.Converters
@@ -24,7 +25,7 @@ namespace Newtonsoft.Json.Tests.Converters
public void SerializeUsingInternalConverter() public void SerializeUsingInternalConverter()
{ {
DefaultContractResolver contractResolver = new DefaultContractResolver(); DefaultContractResolver contractResolver = new DefaultContractResolver();
JsonObjectContract contract = (JsonObjectContract) contractResolver.ResolveContract(typeof (KeyValuePair<string, int>)); JsonObjectContract contract = (JsonObjectContract)contractResolver.ResolveContract(typeof(KeyValuePair<string, int>));
Assert.AreEqual(typeof(KeyValuePairConverter), contract.InternalConverter.GetType()); Assert.AreEqual(typeof(KeyValuePairConverter), contract.InternalConverter.GetType());
@@ -36,6 +36,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Converters namespace Newtonsoft.Json.Tests.Converters
@@ -500,7 +500,6 @@ namespace Newtonsoft.Json.Tests.Converters
Assert.AreEqual(DuplicateNameEnum.foo_bar, o.Value); Assert.AreEqual(DuplicateNameEnum.foo_bar, o.Value);
Assert.AreEqual(DuplicateNameEnum2.FooBar, o.Value2); Assert.AreEqual(DuplicateNameEnum2.FooBar, o.Value2);
}, "Type 'Newtonsoft.Json.Tests.Converters.DuplicateNameEnum' contains two members 'foo_bar' 'and 'FooBar' with the same name 'foo_bar'. Multiple members with the same name in one type are not supported. Consider changing one of the member names using EnumMemberAttribute attribute."); }, "Type 'Newtonsoft.Json.Tests.Converters.DuplicateNameEnum' contains two members 'foo_bar' 'and 'FooBar' with the same name 'foo_bar'. Multiple members with the same name in one type are not supported. Consider changing one of the member names using EnumMemberAttribute attribute.");
} }
#endif #endif
@@ -512,6 +511,7 @@ namespace Newtonsoft.Json.Tests.Converters
{ {
[DataMember] [DataMember]
public DuplicateNameEnum Value { get; set; } public DuplicateNameEnum Value { get; set; }
[DataMember] [DataMember]
public DuplicateNameEnum2 Value2 { get; set; } public DuplicateNameEnum2 Value2 { get; set; }
} }
@@ -521,10 +521,13 @@ namespace Newtonsoft.Json.Tests.Converters
{ {
[EnumMember] [EnumMember]
first = 0, first = 0,
[EnumMember] [EnumMember]
foo_bar = 1, foo_bar = 1,
[EnumMember(Value = "foo_bar")] [EnumMember(Value = "foo_bar")]
FooBar = 2, FooBar = 2,
[EnumMember] [EnumMember]
foo_bar_NOT_USED = 3 foo_bar_NOT_USED = 3
} }
@@ -534,10 +537,13 @@ namespace Newtonsoft.Json.Tests.Converters
{ {
[EnumMember] [EnumMember]
first = 0, first = 0,
[EnumMember(Value = "foo_bar")] [EnumMember(Value = "foo_bar")]
FooBar = 1, FooBar = 1,
[EnumMember] [EnumMember]
foo_bar = 2, foo_bar = 2,
[EnumMember(Value = "TEST")] [EnumMember(Value = "TEST")]
foo_bar_NOT_USED = 3 foo_bar_NOT_USED = 3
} }
@@ -35,6 +35,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Converters namespace Newtonsoft.Json.Tests.Converters
@@ -53,6 +53,7 @@ using Newtonsoft.Json.Utilities;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
#if !NET20 #if !NET20
using System.Xml.Linq; using System.Xml.Linq;
#endif #endif
namespace Newtonsoft.Json.Tests.Converters namespace Newtonsoft.Json.Tests.Converters
@@ -103,7 +104,9 @@ namespace Newtonsoft.Json.Tests.Converters
reader.Read(); reader.Read();
XmlNodeConverter converter = new XmlNodeConverter(); XmlNodeConverter converter = new XmlNodeConverter();
if (deserializeRootElementName != null) if (deserializeRootElementName != null)
{
converter.DeserializeRootElementName = deserializeRootElementName; converter.DeserializeRootElementName = deserializeRootElementName;
}
XmlNode node = (XmlNode)converter.ReadJson(reader, typeof(XmlDocument), null, new JsonSerializer()); XmlNode node = (XmlNode)converter.ReadJson(reader, typeof(XmlDocument), null, new JsonSerializer());
@@ -116,7 +119,9 @@ namespace Newtonsoft.Json.Tests.Converters
string linqXmlText = d.ToString(SaveOptions.DisableFormatting); string linqXmlText = d.ToString(SaveOptions.DisableFormatting);
if (d.Declaration != null) if (d.Declaration != null)
{
linqXmlText = d.Declaration + linqXmlText; linqXmlText = d.Declaration + linqXmlText;
}
Assert.AreEqual(xmlText, linqXmlText); Assert.AreEqual(xmlText, linqXmlText);
#endif #endif
@@ -238,7 +243,7 @@ namespace Newtonsoft.Json.Tests.Converters
var result = xmlDocument.FirstChild.ChildNodes.Cast<XmlNode>().ToArray(); var result = xmlDocument.FirstChild.ChildNodes.Cast<XmlNode>().ToArray();
var json = JsonConvert.SerializeObject(result, Formatting.Indented); // <--- fails here with the cast message var json = JsonConvert.SerializeObject(result, Formatting.Indented); // <--- fails here with the cast message
StringAssert.AreEqual(@"[ StringAssert.AreEqual(@"[
{ {
@@ -275,7 +280,7 @@ namespace Newtonsoft.Json.Tests.Converters
var result = xmlDocument.Root.Nodes().ToArray(); var result = xmlDocument.Root.Nodes().ToArray();
var json = JsonConvert.SerializeObject(result, Formatting.Indented); // <--- fails here with the cast message var json = JsonConvert.SerializeObject(result, Formatting.Indented); // <--- fails here with the cast message
StringAssert.AreEqual(@"[ StringAssert.AreEqual(@"[
{ {
@@ -446,10 +451,7 @@ namespace Newtonsoft.Json.Tests.Converters
} }
}"; }";
ExceptionAssert.Throws<JsonSerializationException>( ExceptionAssert.Throws<JsonSerializationException>(
() => () => { JsonConvert.DeserializeXmlNode(json); },
{
JsonConvert.DeserializeXmlNode(json);
},
"JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document. Consider specifing a DeserializeRootElementName. Path 'Email', line 3, position 13."); "JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document. Consider specifing a DeserializeRootElementName. Path 'Email', line 3, position 13.");
} }
@@ -553,7 +555,6 @@ namespace Newtonsoft.Json.Tests.Converters
Assert.AreEqual(@"{""?xml-stylesheet"":""href=\""classic.xsl\"" type=\""text/xml\""""}", jsonText); Assert.AreEqual(@"{""?xml-stylesheet"":""href=\""classic.xsl\"" type=\""text/xml\""""}", jsonText);
// XmlProcessingInstruction // XmlProcessingInstruction
XmlCDataSection cDataSection = doc.CreateCDataSection("<Kiwi>true</Kiwi>"); XmlCDataSection cDataSection = doc.CreateCDataSection("<Kiwi>true</Kiwi>");
@@ -561,7 +562,6 @@ namespace Newtonsoft.Json.Tests.Converters
Assert.AreEqual(@"{""#cdata-section"":""<Kiwi>true</Kiwi>""}", jsonText); Assert.AreEqual(@"{""#cdata-section"":""<Kiwi>true</Kiwi>""}", jsonText);
// XmlElement // XmlElement
XmlElement element = doc.CreateElement("xs", "Choice", "http://www.w3.org/2001/XMLSchema"); XmlElement element = doc.CreateElement("xs", "Choice", "http://www.w3.org/2001/XMLSchema");
element.SetAttributeNode(doc.CreateAttribute("msdata", "IsDataSet", "urn:schemas-microsoft-com:xml-msdata")); element.SetAttributeNode(doc.CreateAttribute("msdata", "IsDataSet", "urn:schemas-microsoft-com:xml-msdata"));
@@ -711,7 +711,10 @@ namespace Newtonsoft.Json.Tests.Converters
public class Utf8StringWriter : StringWriter public class Utf8StringWriter : StringWriter
{ {
public override Encoding Encoding { get { return Encoding.UTF8; } } public override Encoding Encoding
{
get { return Encoding.UTF8; }
}
public Utf8StringWriter(StringBuilder sb) : base(sb) public Utf8StringWriter(StringBuilder sb) : base(sb)
{ {
@@ -1303,7 +1306,7 @@ namespace Newtonsoft.Json.Tests.Converters
StringAssert.AreEqual(expected, jsonText); StringAssert.AreEqual(expected, jsonText);
XmlDocument newDoc = (XmlDocument)DeserializeXmlNode(jsonText); XmlDocument newDoc = (XmlDocument)DeserializeXmlNode(jsonText);
Assert.AreEqual(@"<span class=""vevent""><a class=""url"" href=""http://www.web2con.com/""><!-- Hi --><span>Text</span></a><!-- Hi! --></span>", newDoc.InnerXml); Assert.AreEqual(@"<span class=""vevent""><a class=""url"" href=""http://www.web2con.com/""><!-- Hi --><span>Text</span></a><!-- Hi! --></span>", newDoc.InnerXml);
} }
[Test] [Test]
@@ -1948,7 +1951,9 @@ namespace Newtonsoft.Json.Tests.Converters
{ {
XmlDocument doc = (XmlDocument)serializer.Deserialize(reader, typeof(XmlDocument)); XmlDocument doc = (XmlDocument)serializer.Deserialize(reader, typeof(XmlDocument));
if (reader.Read() && reader.TokenType != JsonToken.Comment) if (reader.Read() && reader.TokenType != JsonToken.Comment)
{
throw new JsonSerializationException("Additional text found in JSON string after finishing deserializing object."); throw new JsonSerializationException("Additional text found in JSON string after finishing deserializing object.");
}
using (XmlWriter writer = XmlWriter.Create(xml)) using (XmlWriter writer = XmlWriter.Create(xml))
{ {
doc.Save(writer); doc.Save(writer);
@@ -2583,4 +2588,5 @@ namespace Newtonsoft.Json.Tests.Converters
#endif #endif
} }
} }
#endif #endif
+12 -2
View File
@@ -40,6 +40,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests namespace Newtonsoft.Json.Tests
@@ -113,8 +114,8 @@ namespace Newtonsoft.Json.Tests
// create hex string from value // create hex string from value
HtmlColor color = (HtmlColor)value; HtmlColor color = (HtmlColor)value;
string hexString = color.Red.ToString("X2") string hexString = color.Red.ToString("X2")
+ color.Green.ToString("X2") + color.Green.ToString("X2")
+ color.Blue.ToString("X2"); + color.Blue.ToString("X2");
// write value to json // write value to json
writer.WriteValue("#" + hexString); writer.WriteValue("#" + hexString);
@@ -450,10 +451,13 @@ namespace Newtonsoft.Json.Tests
public class House1 public class House1
{ {
public string StreetAddress { get; set; } public string StreetAddress { get; set; }
[JsonIgnore] [JsonIgnore]
public int Bedrooms { get; set; } public int Bedrooms { get; set; }
[JsonIgnore] [JsonIgnore]
public decimal FloorArea { get; set; } public decimal FloorArea { get; set; }
[JsonIgnore] [JsonIgnore]
public DateTime BuildDate { get; set; } public DateTime BuildDate { get; set; }
} }
@@ -463,6 +467,7 @@ namespace Newtonsoft.Json.Tests
{ {
[JsonProperty] [JsonProperty]
public string StreetAddress { get; set; } public string StreetAddress { get; set; }
public int Bedrooms { get; set; } public int Bedrooms { get; set; }
public decimal FloorArea { get; set; } public decimal FloorArea { get; set; }
public DateTime BuildDate { get; set; } public DateTime BuildDate { get; set; }
@@ -473,6 +478,7 @@ namespace Newtonsoft.Json.Tests
{ {
[JsonProperty("address")] [JsonProperty("address")]
public string StreetAddress { get; set; } public string StreetAddress { get; set; }
public int Bedrooms { get; set; } public int Bedrooms { get; set; }
public decimal FloorArea { get; set; } public decimal FloorArea { get; set; }
public DateTime BuildDate { get; set; } public DateTime BuildDate { get; set; }
@@ -483,8 +489,10 @@ namespace Newtonsoft.Json.Tests
{ {
[JsonProperty("address", Order = 2)] [JsonProperty("address", Order = 2)]
public string StreetAddress { get; set; } public string StreetAddress { get; set; }
public int Bedrooms { get; set; } public int Bedrooms { get; set; }
public decimal FloorArea { get; set; } public decimal FloorArea { get; set; }
[JsonProperty("buildDate", Order = 1)] [JsonProperty("buildDate", Order = 1)]
public DateTime BuildDate { get; set; } public DateTime BuildDate { get; set; }
} }
@@ -494,8 +502,10 @@ namespace Newtonsoft.Json.Tests
{ {
[JsonProperty("address", Order = 2)] [JsonProperty("address", Order = 2)]
public string StreetAddress { get; set; } public string StreetAddress { get; set; }
public int Bedrooms { get; set; } public int Bedrooms { get; set; }
public decimal FloorArea { get; set; } public decimal FloorArea { get; set; }
[JsonProperty("buildDate", Order = 1)] [JsonProperty("buildDate", Order = 1)]
[JsonConverter(typeof(JavaScriptDateTimeConverter))] [JsonConverter(typeof(JavaScriptDateTimeConverter))]
public DateTime BuildDate { get; set; } public DateTime BuildDate { get; set; }
@@ -183,4 +183,5 @@ namespace Newtonsoft.Json.Tests.Documentation
} }
} }
} }
#endif #endif
@@ -186,5 +186,6 @@ namespace Newtonsoft.Json.Tests.Documentation
} }
} }
} }
#pragma warning restore 618 #pragma warning restore 618
#endif #endif
@@ -92,7 +92,9 @@ namespace Newtonsoft.Json.Tests.Documentation
// this will only be called once and then cached // this will only be called once and then cached
if (objectType == typeof(DateTime) || objectType == typeof(DateTimeOffset)) if (objectType == typeof(DateTime) || objectType == typeof(DateTimeOffset))
{
contract.Converter = new JavaScriptDateTimeConverter(); contract.Converter = new JavaScriptDateTimeConverter();
}
return contract; return contract;
} }
@@ -113,9 +113,13 @@ namespace Newtonsoft.Json.Tests.Documentation
while (reader.Read()) while (reader.Read())
{ {
if (reader.Value != null) if (reader.Value != null)
{
Console.WriteLine("Token: {0}, Value: {1}", reader.TokenType, reader.Value); Console.WriteLine("Token: {0}, Value: {1}", reader.TokenType, reader.Value);
}
else else
{
Console.WriteLine("Token: {0}", reader.TokenType); Console.WriteLine("Token: {0}", reader.TokenType);
}
} }
// Token: StartObject // Token: StartObject
@@ -34,6 +34,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Bson namespace Newtonsoft.Json.Tests.Documentation.Samples.Bson
@@ -34,6 +34,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Bson namespace Newtonsoft.Json.Tests.Documentation.Samples.Bson
@@ -35,6 +35,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Bson namespace Newtonsoft.Json.Tests.Documentation.Samples.Bson
@@ -36,13 +36,15 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
#if !(DNXCORE50 || NET20) #if !(DNXCORE50 || NET20)
namespace Newtonsoft.Json.Tests.Documentation.Samples.Json namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
{ {
#region Types
#region Types
public class XmlJsonReader : JsonReader public class XmlJsonReader : JsonReader
{ {
private readonly Stack<JTokenType> _stateStack; private readonly Stack<JTokenType> _stateStack;
@@ -65,7 +67,9 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
public override bool Read() public override bool Read()
{ {
if (HandleValueType()) if (HandleValueType())
{
return true; return true;
}
while (_reader.Read()) while (_reader.Read())
{ {
@@ -74,7 +78,9 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
case XmlNodeType.Element: case XmlNodeType.Element:
string typeName = _reader.GetAttribute("type"); string typeName = _reader.GetAttribute("type");
if (typeName == null) if (typeName == null)
{
throw new Exception("No type specified."); throw new Exception("No type specified.");
}
_valueType = (JTokenType)Enum.Parse(typeof(JTokenType), typeName, true); _valueType = (JTokenType)Enum.Parse(typeof(JTokenType), typeName, true);
@@ -100,25 +106,33 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
SetToken(JsonToken.EndObject); SetToken(JsonToken.EndObject);
_stateStack.Pop(); _stateStack.Pop();
if (PeekState() == JTokenType.Property) if (PeekState() == JTokenType.Property)
{
_stateStack.Pop(); _stateStack.Pop();
}
return true; return true;
case JTokenType.Array: case JTokenType.Array:
SetToken(JsonToken.EndArray); SetToken(JsonToken.EndArray);
_stateStack.Pop(); _stateStack.Pop();
if (PeekState() == JTokenType.Property) if (PeekState() == JTokenType.Property)
{
_stateStack.Pop(); _stateStack.Pop();
}
return true; return true;
case JTokenType.Constructor: case JTokenType.Constructor:
SetToken(JsonToken.EndConstructor); SetToken(JsonToken.EndConstructor);
_stateStack.Pop(); _stateStack.Pop();
if (PeekState() == JTokenType.Property) if (PeekState() == JTokenType.Property)
{
_stateStack.Pop(); _stateStack.Pop();
}
return true; return true;
} }
_stateStack.Pop(); _stateStack.Pop();
if (PeekState() == JTokenType.Property) if (PeekState() == JTokenType.Property)
{
_stateStack.Pop(); _stateStack.Pop();
}
break; break;
case XmlNodeType.Text: case XmlNodeType.Text:
@@ -168,7 +182,9 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
_valueType = null; _valueType = null;
if (PeekState() == JTokenType.Property) if (PeekState() == JTokenType.Property)
{
_stateStack.Pop(); _stateStack.Pop();
}
return true; return true;
case JTokenType.Object: case JTokenType.Object:
SetToken(JsonToken.StartObject); SetToken(JsonToken.StartObject);
@@ -183,7 +199,9 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
case JTokenType.Constructor: case JTokenType.Constructor:
string constructorName = _reader.GetAttribute("name"); string constructorName = _reader.GetAttribute("name");
if (constructorName == null) if (constructorName == null)
{
throw new Exception("No constructor name specified."); throw new Exception("No constructor name specified.");
}
SetToken(JsonToken.StartConstructor, constructorName); SetToken(JsonToken.StartConstructor, constructorName);
_stateStack.Push(JTokenType.Constructor); _stateStack.Push(JTokenType.Constructor);
@@ -196,7 +214,9 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
public override int? ReadAsInt32() public override int? ReadAsInt32()
{ {
if (!Read()) if (!Read())
{
return null; return null;
}
return (Value != null) ? (int?)Convert.ToInt32(Value) : null; return (Value != null) ? (int?)Convert.ToInt32(Value) : null;
} }
@@ -204,7 +224,9 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
public override string ReadAsString() public override string ReadAsString()
{ {
if (!Read()) if (!Read())
{
return null; return null;
}
return (string)Value; return (string)Value;
} }
@@ -212,7 +234,9 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
public override byte[] ReadAsBytes() public override byte[] ReadAsBytes()
{ {
if (!Read()) if (!Read())
{
return null; return null;
}
return (byte[])Value; return (byte[])Value;
} }
@@ -220,7 +244,9 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
public override decimal? ReadAsDecimal() public override decimal? ReadAsDecimal()
{ {
if (!Read()) if (!Read())
{
return null; return null;
}
return (Value != null) ? (decimal?)Convert.ToDecimal(Value) : null; return (Value != null) ? (decimal?)Convert.ToDecimal(Value) : null;
} }
@@ -228,7 +254,9 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
public override DateTime? ReadAsDateTime() public override DateTime? ReadAsDateTime()
{ {
if (!Read()) if (!Read())
{
return null; return null;
}
return (Value != null) ? (DateTime?)Convert.ToDateTime(Value) : null; return (Value != null) ? (DateTime?)Convert.ToDateTime(Value) : null;
} }
@@ -236,12 +264,14 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
public override DateTimeOffset? ReadAsDateTimeOffset() public override DateTimeOffset? ReadAsDateTimeOffset()
{ {
if (!Read()) if (!Read())
{
return null; return null;
}
return (Value != null) ? (DateTimeOffset?)Convert.ToDateTime(Value) : null; return (Value != null) ? (DateTimeOffset?)Convert.ToDateTime(Value) : null;
} }
} }
#endregion #endregion
[TestFixture] [TestFixture]
public class CustomJsonReader : TestFixtureBase public class CustomJsonReader : TestFixtureBase
@@ -249,7 +279,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
[Test] [Test]
public void Example() public void Example()
{ {
#region Usage #region Usage
string xml = @"<Root type=""Object""> string xml = @"<Root type=""Object"">
<Null type=""Null"" /> <Null type=""Null"" />
<String type=""String"">This is a string!</String> <String type=""String"">This is a string!</String>
@@ -308,7 +338,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
// "Constructor": new Date(2000, 12, 30) // "Constructor": new Date(2000, 12, 30)
//} //}
} }
#endregion #endregion
using (XmlReader xmlReader = XmlReader.Create(new StringReader(xml), new XmlReaderSettings { IgnoreWhitespace = true })) using (XmlReader xmlReader = XmlReader.Create(new StringReader(xml), new XmlReaderSettings { IgnoreWhitespace = true }))
using (XmlJsonReader reader = new XmlJsonReader(xmlReader)) using (XmlJsonReader reader = new XmlJsonReader(xmlReader))
@@ -36,13 +36,15 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
#if !(DNXCORE50 || NET20) #if !(DNXCORE50 || NET20)
namespace Newtonsoft.Json.Tests.Documentation.Samples.Json namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
{ {
#region Types
#region Types
public class XmlJsonWriter : JsonWriter public class XmlJsonWriter : JsonWriter
{ {
private readonly XmlWriter _writer; private readonly XmlWriter _writer;
@@ -234,9 +236,13 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
base.WriteStartArray(); base.WriteStartArray();
if (isStart) if (isStart)
{
WriteValueElement("Root", JTokenType.Array); WriteValueElement("Root", JTokenType.Array);
}
else else
{
WriteValueElement(JTokenType.Array); WriteValueElement(JTokenType.Array);
}
} }
public override void WriteStartObject() public override void WriteStartObject()
@@ -246,9 +252,13 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
base.WriteStartObject(); base.WriteStartObject();
if (isStart) if (isStart)
{
WriteValueElement("Root", JTokenType.Object); WriteValueElement("Root", JTokenType.Object);
}
else else
{
WriteValueElement(JTokenType.Object); WriteValueElement(JTokenType.Object);
}
} }
public override void WriteStartConstructor(string name) public override void WriteStartConstructor(string name)
@@ -258,9 +268,13 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
base.WriteStartConstructor(name); base.WriteStartConstructor(name);
if (isStart) if (isStart)
{
WriteValueElement("Root", JTokenType.Constructor); WriteValueElement("Root", JTokenType.Constructor);
}
else else
{
WriteValueElement(JTokenType.Constructor); WriteValueElement(JTokenType.Constructor);
}
_writer.WriteAttributeString("name", name); _writer.WriteAttributeString("name", name);
} }
@@ -306,7 +320,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
} }
} }
} }
#endregion #endregion
[TestFixture] [TestFixture]
public class CustomJsonWriter : TestFixtureBase public class CustomJsonWriter : TestFixtureBase
@@ -314,17 +328,17 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
[Test] [Test]
public void Example() public void Example()
{ {
#region Usage #region Usage
var user = new var user = new
{ {
Name = "James", Name = "James",
Age = 30, Age = 30,
Enabled = true, Enabled = true,
Roles = new[] Roles = new[]
{ {
"Publisher", "Publisher",
"Administrator" "Administrator"
} }
}; };
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
@@ -348,7 +362,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
// <Item type="String">Administrator</Item> // <Item type="String">Administrator</Item>
// </Roles> // </Roles>
//</Root> //</Root>
#endregion #endregion
sw = new StringWriter(); sw = new StringWriter();
@@ -33,6 +33,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Json namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
@@ -59,9 +60,13 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
while (reader.Read()) while (reader.Read())
{ {
if (reader.Value != null) if (reader.Value != null)
{
Console.WriteLine("Token: {0}, Value: {1}", reader.TokenType, reader.Value); Console.WriteLine("Token: {0}, Value: {1}", reader.TokenType, reader.Value);
}
else else
{
Console.WriteLine("Token: {0}", reader.TokenType); Console.WriteLine("Token: {0}", reader.TokenType);
}
} }
// Token: StartObject // Token: StartObject
@@ -33,6 +33,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Json namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
@@ -61,7 +62,9 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
while (true) while (true)
{ {
if (!reader.Read()) if (!reader.Read())
{
break; break;
}
JsonSerializer serializer = new JsonSerializer(); JsonSerializer serializer = new JsonSerializer();
Role role = serializer.Deserialize<Role>(reader); Role role = serializer.Deserialize<Role>(reader);
@@ -33,6 +33,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Json namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
@@ -33,6 +33,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
@@ -38,6 +38,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
@@ -33,6 +33,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
@@ -38,6 +38,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
@@ -35,6 +35,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
@@ -33,6 +33,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
@@ -33,6 +33,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
@@ -33,6 +33,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
@@ -62,7 +63,9 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
{ {
Console.Write(reader.TokenType); Console.Write(reader.TokenType);
if (reader.Value != null) if (reader.Value != null)
{
Console.Write(" - " + reader.Value); Console.Write(" - " + reader.Value);
}
Console.WriteLine(); Console.WriteLine();
} }
@@ -33,6 +33,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
@@ -33,6 +33,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
@@ -41,6 +41,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
@@ -33,6 +33,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
@@ -33,6 +33,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
@@ -59,7 +59,6 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
o["age"] = 59; o["age"] = 59;
o["employer"] = "Bill & Melinda Gates Foundation"; o["employer"] = "Bill & Melinda Gates Foundation";
HashSet<string> changedProperties = o.Annotation<HashSet<string>>(); HashSet<string> changedProperties = o.Annotation<HashSet<string>>();
// age // age
// employer // employer
@@ -33,6 +33,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
@@ -33,6 +33,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
@@ -30,6 +30,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
@@ -33,6 +33,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
@@ -33,6 +33,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
@@ -33,6 +33,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
@@ -33,6 +33,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
@@ -38,6 +38,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
@@ -40,6 +40,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
@@ -38,6 +38,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
@@ -38,6 +38,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
@@ -38,6 +38,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
@@ -35,6 +35,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
@@ -34,6 +34,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
@@ -41,6 +41,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
@@ -33,6 +33,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
@@ -33,6 +33,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
@@ -33,6 +33,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
@@ -34,6 +34,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
@@ -34,6 +34,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
@@ -35,6 +35,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
@@ -34,6 +34,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
@@ -82,4 +82,5 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Schema
} }
} }
} }
#pragma warning restore 618 #pragma warning restore 618
@@ -62,4 +62,5 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Schema
} }
} }
} }
#pragma warning restore 618 #pragma warning restore 618
@@ -72,4 +72,5 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Schema
} }
} }
} }
#pragma warning restore 618 #pragma warning restore 618
@@ -71,4 +71,5 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Schema
} }
} }
} }
#pragma warning restore 618 #pragma warning restore 618
@@ -64,4 +64,5 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Schema
} }
} }
} }
#pragma warning restore 618 #pragma warning restore 618
@@ -84,4 +84,5 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Schema
} }
} }
} }
#pragma warning restore 618 #pragma warning restore 618
@@ -50,4 +50,5 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Schema
} }
} }
} }
#pragma warning restore 618 #pragma warning restore 618
@@ -80,4 +80,5 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Schema
} }
} }
} }
#pragma warning restore 618 #pragma warning restore 618
@@ -55,4 +55,5 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Schema
} }
} }
} }
#pragma warning restore 618 #pragma warning restore 618
@@ -38,6 +38,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
@@ -38,6 +38,7 @@ using NUnit.Framework;
using Newtonsoft.Json.Utilities.LinqBridge; using Newtonsoft.Json.Utilities.LinqBridge;
#else #else
using System.Linq; using System.Linq;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
@@ -34,6 +34,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
#if !(DNXCORE50 || NET20 || NET35) #if !(DNXCORE50 || NET20 || NET35)
@@ -43,7 +44,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
[TestFixture] [TestFixture]
public class CustomTraceWriter : TestFixtureBase public class CustomTraceWriter : TestFixtureBase
{ {
#region Types #region Types
public class NLogTraceWriter : ITraceWriter public class NLogTraceWriter : ITraceWriter
{ {
private static readonly Logger Logger = LogManager.GetLogger("NLogTraceWriter"); private static readonly Logger Logger = LogManager.GetLogger("NLogTraceWriter");
@@ -84,12 +85,12 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
} }
} }
} }
#endregion #endregion
[Test] [Test]
public void Example() public void Example()
{ {
#region Usage #region Usage
IList<string> countries = new List<string> IList<string> countries = new List<string>
{ {
"New Zealand", "New Zealand",
@@ -110,7 +111,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
// "Denmark", // "Denmark",
// "China" // "China"
// ] // ]
#endregion #endregion
Assert.AreEqual(@"[ Assert.AreEqual(@"[
""New Zealand"", ""New Zealand"",
@@ -35,6 +35,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
@@ -33,6 +33,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
@@ -32,6 +32,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
@@ -32,6 +32,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
@@ -37,6 +37,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
@@ -33,6 +33,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
@@ -52,7 +53,9 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
public Website(Website website) public Website(Website website)
{ {
if (website == null) if (website == null)
{
throw new ArgumentNullException("website"); throw new ArgumentNullException("website");
}
Url = website.Url; Url = website.Url;
} }
@@ -33,6 +33,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
@@ -35,6 +35,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
@@ -34,6 +34,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
@@ -32,6 +32,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
@@ -32,6 +32,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
@@ -32,6 +32,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
@@ -32,6 +32,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
@@ -63,7 +63,9 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
// use Autofac to create types that have been registered with it // use Autofac to create types that have been registered with it
if (_container.IsRegistered(objectType)) if (_container.IsRegistered(objectType))
{
contract.DefaultCreator = () => _container.Resolve(objectType); contract.DefaultCreator = () => _container.Resolve(objectType);
}
return contract; return contract;
} }
@@ -34,6 +34,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
@@ -54,7 +55,9 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
get get
{ {
if (_roles == null) if (_roles == null)
{
throw new Exception("Roles not loaded!"); throw new Exception("Roles not loaded!");
}
return _roles; return _roles;
} }
@@ -34,6 +34,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
@@ -33,6 +33,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
@@ -33,6 +33,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
@@ -32,6 +32,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
@@ -33,6 +33,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
@@ -32,6 +32,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert; using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else #else
using NUnit.Framework; using NUnit.Framework;
#endif #endif
namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer

Some files were not shown because too many files have changed in this diff Show More