Merge branch 'master' of github.com:JamesNK/Newtonsoft.Json
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
* text eol=crlf
|
||||||
|
|
||||||
*.doc diff=astextplain
|
*.doc diff=astextplain
|
||||||
*.DOC diff=astextplain
|
*.DOC diff=astextplain
|
||||||
*.docx diff=astextplain
|
*.docx diff=astextplain
|
||||||
|
|||||||
+16
-15
@@ -1,16 +1,17 @@
|
|||||||
[Bb]in/
|
[Bb]in/
|
||||||
[Oo]bj/
|
[Oo]bj/
|
||||||
[Ww]orking/
|
[Ww]orking/
|
||||||
Build/runbuild.txt
|
Build/runbuild.txt
|
||||||
Doc/doc.shfbproj_*
|
Doc/doc.shfbproj_*
|
||||||
TestResults/
|
TestResults/
|
||||||
AppPackages/
|
AppPackages/
|
||||||
*.suo
|
*.suo
|
||||||
*.user
|
*.user
|
||||||
_ReSharper.*
|
*.userprefs
|
||||||
*.ReSharper.user
|
_ReSharper.*
|
||||||
*.resharper.user
|
*.ReSharper.user
|
||||||
|
*.resharper.user
|
||||||
#NuGet
|
|
||||||
packages
|
#NuGet
|
||||||
|
packages
|
||||||
!packages/repositories.config
|
!packages/repositories.config
|
||||||
@@ -821,10 +821,7 @@ namespace Newtonsoft.Json.Tests.Bson
|
|||||||
|
|
||||||
Assert.IsTrue(reader.Read());
|
Assert.IsTrue(reader.Read());
|
||||||
Assert.AreEqual(JsonToken.String, reader.TokenType);
|
Assert.AreEqual(JsonToken.String, reader.TokenType);
|
||||||
Assert.AreEqual(@"for (int i = 0; i < 1000; i++)
|
Assert.AreEqual("for (int i = 0; i < 1000; i++)\r\n{\r\n alert(arg1);\r\n}", reader.Value);
|
||||||
{
|
|
||||||
alert(arg1);
|
|
||||||
}", reader.Value);
|
|
||||||
|
|
||||||
Assert.IsTrue(reader.Read());
|
Assert.IsTrue(reader.Read());
|
||||||
Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
|
Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
|
||||||
@@ -1312,12 +1309,7 @@ namespace Newtonsoft.Json.Tests.Bson
|
|||||||
|
|
||||||
Assert.IsTrue(reader.Read());
|
Assert.IsTrue(reader.Read());
|
||||||
Assert.AreEqual(JsonToken.String, reader.TokenType);
|
Assert.AreEqual(JsonToken.String, reader.TokenType);
|
||||||
Assert.AreEqual(@"<p>I'm the Director for Research and Development for <a href=""http://www.prophoenix.com"" rel=""nofollow"">ProPhoenix</a>, a public safety software company. This position allows me to investigate new and existing technologies and incorporate them into our product line, with the end goal being to help public safety agencies to do their jobs more effeciently and safely.</p>
|
Assert.AreEqual("<p>I'm the Director for Research and Development for <a href=\"http://www.prophoenix.com\" rel=\"nofollow\">ProPhoenix</a>, a public safety software company. This position allows me to investigate new and existing technologies and incorporate them into our product line, with the end goal being to help public safety agencies to do their jobs more effeciently and safely.</p>\r\n\r\n<p>I'm an advocate for PowerShell, as I believe it encourages administrative best practices and allows developers to provide additional access to their applications, without needing to explicity write code for each administrative feature. Part of my advocacy for PowerShell includes <a href=\"http://blog.usepowershell.com\" rel=\"nofollow\">my blog</a>, appearances on various podcasts, and acting as a Community Director for <a href=\"http://powershellcommunity.org\" rel=\"nofollow\">PowerShellCommunity.Org</a></p>\r\n\r\n<p>I’m also a co-host of Mind of Root (a weekly audio podcast about systems administration, tech news, and topics).</p>\r\n", reader.Value);
|
||||||
|
|
||||||
<p>I'm an advocate for PowerShell, as I believe it encourages administrative best practices and allows developers to provide additional access to their applications, without needing to explicity write code for each administrative feature. Part of my advocacy for PowerShell includes <a href=""http://blog.usepowershell.com"" rel=""nofollow"">my blog</a>, appearances on various podcasts, and acting as a Community Director for <a href=""http://powershellcommunity.org"" rel=""nofollow"">PowerShellCommunity.Org</a></p>
|
|
||||||
|
|
||||||
<p>I’m also a co-host of Mind of Root (a weekly audio podcast about systems administration, tech news, and topics).</p>
|
|
||||||
", reader.Value);
|
|
||||||
Assert.AreEqual(typeof(string), reader.ValueType);
|
Assert.AreEqual(typeof(string), reader.ValueType);
|
||||||
|
|
||||||
Assert.IsTrue(reader.Read());
|
Assert.IsTrue(reader.Read());
|
||||||
|
|||||||
@@ -342,8 +342,7 @@ namespace Newtonsoft.Json.Tests
|
|||||||
result = JavaScriptUtils.ToEscapedJavaScriptString("How now <brown> cow?", '"', true);
|
result = JavaScriptUtils.ToEscapedJavaScriptString("How now <brown> cow?", '"', true);
|
||||||
Assert.AreEqual(@"""How now <brown> cow?""", result);
|
Assert.AreEqual(@"""How now <brown> cow?""", result);
|
||||||
|
|
||||||
result = JavaScriptUtils.ToEscapedJavaScriptString(@"How
|
result = JavaScriptUtils.ToEscapedJavaScriptString("How \r\nnow brown cow?", '"', true);
|
||||||
now brown cow?", '"', true);
|
|
||||||
Assert.AreEqual(@"""How \r\nnow brown cow?""", result);
|
Assert.AreEqual(@"""How \r\nnow brown cow?""", result);
|
||||||
|
|
||||||
result = JavaScriptUtils.ToEscapedJavaScriptString("\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007", '"', true);
|
result = JavaScriptUtils.ToEscapedJavaScriptString("\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007", '"', true);
|
||||||
@@ -576,8 +575,7 @@ now brown cow?", '"', true);
|
|||||||
[Test]
|
[Test]
|
||||||
public void StringEscaping()
|
public void StringEscaping()
|
||||||
{
|
{
|
||||||
string v = @"It's a good day
|
string v = "It's a good day\r\n\"sunshine\"";
|
||||||
""sunshine""";
|
|
||||||
|
|
||||||
string json = JsonConvert.ToString(v);
|
string json = JsonConvert.ToString(v);
|
||||||
Assert.AreEqual(@"""It's a good day\r\n\""sunshine\""""", json);
|
Assert.AreEqual(@"""It's a good day\r\n\""sunshine\""""", json);
|
||||||
|
|||||||
@@ -357,62 +357,7 @@ third line", jsonTextReader.Value);
|
|||||||
Assert.IsTrue(reader.Read());
|
Assert.IsTrue(reader.Read());
|
||||||
Assert.AreEqual(JsonToken.String, reader.TokenType);
|
Assert.AreEqual(JsonToken.String, reader.TokenType);
|
||||||
|
|
||||||
Assert.AreEqual(@"#C16------------------------------
|
Assert.AreEqual("#C16------------------------------\r\n#C12Ingredients #C20\r\n#C16------------------------------\r\n\r\na piece of Leather Armor\r\n( ie #L \"Enhanced Leather Armor Boots\" \"85644\" )\r\n<img src=rdb://13264>\r\n\r\n#L \"Hacker Tool\" \"87814\"\r\n<img src=rdb://99282>\r\n\r\n#L \"Clanalizer\" \"208313\"\r\n<img src=rdb://156479>\r\n\r\n#C16------------------------------\r\n#C12Recipe #C16\r\n#C16------------------------------#C20\r\n\r\nHacker Tool\r\n#C15+#C20\r\na piece of Leather Armor\r\n#C15=#C20\r\n<img src=rdb://13264>\r\na piece of Hacked Leather Armor\r\n( ie : #L \"Hacked Leather Armor Boots\" \"245979\" )\r\n#C16Skills: | BE |#C20\r\n\r\n#C14------------------------------#C20\r\n\r\nClanalizer\r\n#C15+#C20\r\na piece of Hacked Leather Armor\r\n#C15=#C20\r\n<img src=rdb://13264>\r\na piece of Apocalypse Leather Armor\r\n( ie : #L \"Apocalypse Leather Armor Boots\" \"245966\" )\r\n#C16Skills: | ?? |#C20\r\n\r\n#C16------------------------------\r\n#C12Details#C16\r\n#C16------------------------------#C20\r\n\r\n#L \"Apocalypse Leather Armor Boots\" \"245967\"\r\n#L \"Apocalypse Leather Armor Gloves\" \"245969\"\r\n#L \"Apocalypse Leather Armor Helmet\" \"245975\"\r\n#L \"Apocalypse Leather Armor Pants\" \"245971\"\r\n#L \"Apocalypse Leather Armor Sleeves\" \"245973\"\r\n#L \"Apocalypse Leather Body Armor\" \"245965\"\r\n\r\n#C16------------------------------\r\n#C12Comments#C16\r\n#C16------------------------------#C20\r\n\r\nNice froob armor.. but ugleh!\r\n\r\n", reader.Value);
|
||||||
#C12Ingredients #C20
|
|
||||||
#C16------------------------------
|
|
||||||
|
|
||||||
a piece of Leather Armor
|
|
||||||
( ie #L ""Enhanced Leather Armor Boots"" ""85644"" )
|
|
||||||
<img src=rdb://13264>
|
|
||||||
|
|
||||||
#L ""Hacker Tool"" ""87814""
|
|
||||||
<img src=rdb://99282>
|
|
||||||
|
|
||||||
#L ""Clanalizer"" ""208313""
|
|
||||||
<img src=rdb://156479>
|
|
||||||
|
|
||||||
#C16------------------------------
|
|
||||||
#C12Recipe #C16
|
|
||||||
#C16------------------------------#C20
|
|
||||||
|
|
||||||
Hacker Tool
|
|
||||||
#C15+#C20
|
|
||||||
a piece of Leather Armor
|
|
||||||
#C15=#C20
|
|
||||||
<img src=rdb://13264>
|
|
||||||
a piece of Hacked Leather Armor
|
|
||||||
( ie : #L ""Hacked Leather Armor Boots"" ""245979"" )
|
|
||||||
#C16Skills: | BE |#C20
|
|
||||||
|
|
||||||
#C14------------------------------#C20
|
|
||||||
|
|
||||||
Clanalizer
|
|
||||||
#C15+#C20
|
|
||||||
a piece of Hacked Leather Armor
|
|
||||||
#C15=#C20
|
|
||||||
<img src=rdb://13264>
|
|
||||||
a piece of Apocalypse Leather Armor
|
|
||||||
( ie : #L ""Apocalypse Leather Armor Boots"" ""245966"" )
|
|
||||||
#C16Skills: | ?? |#C20
|
|
||||||
|
|
||||||
#C16------------------------------
|
|
||||||
#C12Details#C16
|
|
||||||
#C16------------------------------#C20
|
|
||||||
|
|
||||||
#L ""Apocalypse Leather Armor Boots"" ""245967""
|
|
||||||
#L ""Apocalypse Leather Armor Gloves"" ""245969""
|
|
||||||
#L ""Apocalypse Leather Armor Helmet"" ""245975""
|
|
||||||
#L ""Apocalypse Leather Armor Pants"" ""245971""
|
|
||||||
#L ""Apocalypse Leather Armor Sleeves"" ""245973""
|
|
||||||
#L ""Apocalypse Leather Body Armor"" ""245965""
|
|
||||||
|
|
||||||
#C16------------------------------
|
|
||||||
#C12Comments#C16
|
|
||||||
#C16------------------------------#C20
|
|
||||||
|
|
||||||
Nice froob armor.. but ugleh!
|
|
||||||
|
|
||||||
", reader.Value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -859,10 +804,12 @@ Nice froob armor.. but ugleh!
|
|||||||
[Test]
|
[Test]
|
||||||
public void NullTextReader()
|
public void NullTextReader()
|
||||||
{
|
{
|
||||||
ExceptionAssert.Throws<ArgumentNullException>(
|
ExceptionAssert.Throws<ArgumentNullException> (
|
||||||
@"Value cannot be null.
|
() => { new JsonTextReader (null); },
|
||||||
Parameter name: reader",
|
new string[] {
|
||||||
() => { new JsonTextReader(null); });
|
"Value cannot be null." + Environment.NewLine + "Parameter name: reader",
|
||||||
|
"Argument cannot be null." + Environment.NewLine + "Parameter name: reader" // Mono
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -1285,8 +1232,7 @@ Parameter name: reader",
|
|||||||
Assert.IsTrue(reader.Read());
|
Assert.IsTrue(reader.Read());
|
||||||
Assert.IsTrue(reader.Read());
|
Assert.IsTrue(reader.Read());
|
||||||
Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
|
Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
|
||||||
Assert.AreEqual(@"hi
|
Assert.AreEqual("hi\r\nbye", reader.Value);
|
||||||
bye", reader.Value);
|
|
||||||
Assert.IsTrue(reader.Read());
|
Assert.IsTrue(reader.Read());
|
||||||
Assert.AreEqual(JsonToken.Integer, reader.TokenType);
|
Assert.AreEqual(JsonToken.Integer, reader.TokenType);
|
||||||
Assert.AreEqual(1L, reader.Value);
|
Assert.AreEqual(1L, reader.Value);
|
||||||
|
|||||||
@@ -261,8 +261,7 @@ namespace Newtonsoft.Json.Tests
|
|||||||
jsonWriter.WriteStartArray();
|
jsonWriter.WriteStartArray();
|
||||||
jsonWriter.WriteValue(@"""These pretzels are making me thirsty!""");
|
jsonWriter.WriteValue(@"""These pretzels are making me thirsty!""");
|
||||||
jsonWriter.WriteValue("Jeff's house was burninated.");
|
jsonWriter.WriteValue("Jeff's house was burninated.");
|
||||||
jsonWriter.WriteValue(@"1. You don't talk about fight club.
|
jsonWriter.WriteValue("1. You don't talk about fight club.\r\n2. You don't talk about fight club.");
|
||||||
2. You don't talk about fight club.");
|
|
||||||
jsonWriter.WriteValue("35% of\t statistics\n are made\r up.");
|
jsonWriter.WriteValue("35% of\t statistics\n are made\r up.");
|
||||||
jsonWriter.WriteEndArray();
|
jsonWriter.WriteEndArray();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,11 +129,6 @@
|
|||||||
<Compile Include="Converters\ObjectIdConverterTests.cs" />
|
<Compile Include="Converters\ObjectIdConverterTests.cs" />
|
||||||
<Compile Include="Converters\StringEnumConverterTests.cs" />
|
<Compile Include="Converters\StringEnumConverterTests.cs" />
|
||||||
<Compile Include="Converters\VersionConverterTests.cs" />
|
<Compile Include="Converters\VersionConverterTests.cs" />
|
||||||
<Compile Include="FileSystemEntityModel.Designer.cs">
|
|
||||||
<AutoGen>True</AutoGen>
|
|
||||||
<DesignTime>True</DesignTime>
|
|
||||||
<DependentUpon>FileSystemEntityModel.edmx</DependentUpon>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="JsonArrayAttributeTests.cs" />
|
<Compile Include="JsonArrayAttributeTests.cs" />
|
||||||
<Compile Include="ExceptionTests.cs" />
|
<Compile Include="ExceptionTests.cs" />
|
||||||
<Compile Include="JsonValidatingReaderTests.cs" />
|
<Compile Include="JsonValidatingReaderTests.cs" />
|
||||||
@@ -344,12 +339,6 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Service Include="{3259AA49-8AA1-44D3-9025-A0B520596A8C}" />
|
<Service Include="{3259AA49-8AA1-44D3-9025-A0B520596A8C}" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
|
||||||
<EntityDeploy Include="FileSystemEntityModel.edmx">
|
|
||||||
<Generator>EntityModelCodeGenerator</Generator>
|
|
||||||
<LastGenOutput>FileSystemEntityModel.Designer.cs</LastGenOutput>
|
|
||||||
</EntityDeploy>
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="bunny_pancake.jpg">
|
<Content Include="bunny_pancake.jpg">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
@@ -382,7 +371,6 @@
|
|||||||
<ProjectReference Include="..\Newtonsoft.Json\Newtonsoft.Json.Portable.csproj">
|
<ProjectReference Include="..\Newtonsoft.Json\Newtonsoft.Json.Portable.csproj">
|
||||||
<Project>{959F7F85-C98B-4876-971A-9036224578E4}</Project>
|
<Project>{959F7F85-C98B-4876-971A-9036224578E4}</Project>
|
||||||
<Name>Newtonsoft.Json.Portable</Name>
|
<Name>Newtonsoft.Json.Portable</Name>
|
||||||
<Aliases>global</Aliases>
|
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
|
|||||||
@@ -141,8 +141,12 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
[Test]
|
[Test]
|
||||||
public void SerializeDefaultArray()
|
public void SerializeDefaultArray()
|
||||||
{
|
{
|
||||||
ExceptionAssert.Throws<NullReferenceException>("Object reference not set to an instance of an object.", () =>
|
ExceptionAssert.Throws<NullReferenceException>(
|
||||||
JsonConvert.SerializeObject(default(ImmutableArray<int>), Formatting.Indented));
|
() => JsonConvert.SerializeObject(default(ImmutableArray<int>), Formatting.Indented),
|
||||||
|
new [] {
|
||||||
|
"Object reference not set to an instance of an object.",
|
||||||
|
"Object reference not set to an instance of an object" // mono
|
||||||
|
});
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@@ -2975,8 +2975,11 @@ Path '', line 1, position 1.",
|
|||||||
string json = @"[]";
|
string json = @"[]";
|
||||||
|
|
||||||
ExceptionAssert.Throws<InvalidCastException>(
|
ExceptionAssert.Throws<InvalidCastException>(
|
||||||
@"Unable to cast object of type 'Newtonsoft.Json.Linq.JArray' to type 'Newtonsoft.Json.Linq.JObject'.",
|
() => { JsonConvert.DeserializeObject<JObject>(json); },
|
||||||
() => { JsonConvert.DeserializeObject<JObject>(json); });
|
new [] {
|
||||||
|
"Unable to cast object of type 'Newtonsoft.Json.Linq.JArray' to type 'Newtonsoft.Json.Linq.JObject'.",
|
||||||
|
"Cannot cast from source type to destination type." // mono
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -6304,18 +6307,22 @@ To fix this error either change the environment to be fully trusted, change the
|
|||||||
public void DeserializeDoubleFromNullString()
|
public void DeserializeDoubleFromNullString()
|
||||||
{
|
{
|
||||||
ExceptionAssert.Throws<ArgumentNullException>(
|
ExceptionAssert.Throws<ArgumentNullException>(
|
||||||
@"Value cannot be null.
|
() => { JsonConvert.DeserializeObject<double>(null); },
|
||||||
Parameter name: value",
|
new [] {
|
||||||
() => { JsonConvert.DeserializeObject<double>(null); });
|
"Value cannot be null." + Environment.NewLine + "Parameter name: value",
|
||||||
|
"Argument cannot be null." + Environment.NewLine + "Parameter name: value" // mono
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void DeserializeFromNullString()
|
public void DeserializeFromNullString()
|
||||||
{
|
{
|
||||||
ExceptionAssert.Throws<ArgumentNullException>(
|
ExceptionAssert.Throws<ArgumentNullException>(
|
||||||
@"Value cannot be null.
|
() => { JsonConvert.DeserializeObject(null); },
|
||||||
Parameter name: value",
|
new [] {
|
||||||
() => { JsonConvert.DeserializeObject(null); });
|
"Value cannot be null." + Environment.NewLine + "Parameter name: value",
|
||||||
|
"Argument cannot be null." + Environment.NewLine + "Parameter name: value" // mono
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|||||||
@@ -66,10 +66,14 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
}
|
}
|
||||||
]";
|
]";
|
||||||
|
|
||||||
|
var possibleMsgs = new [] {
|
||||||
|
"[1] - Error message for member 1 = An item with the same key has already been added.",
|
||||||
|
"[1] - Error message for member 1 = An element with the same key already exists in the dictionary." // mono
|
||||||
|
};
|
||||||
VersionKeyedCollection c = JsonConvert.DeserializeObject<VersionKeyedCollection>(json);
|
VersionKeyedCollection c = JsonConvert.DeserializeObject<VersionKeyedCollection>(json);
|
||||||
Assert.AreEqual(1, c.Count);
|
Assert.AreEqual(1, c.Count);
|
||||||
Assert.AreEqual(1, c.Messages.Count);
|
Assert.AreEqual(1, c.Messages.Count);
|
||||||
Assert.AreEqual("[1] - Error message for member 1 = An item with the same key has already been added.", c.Messages[0]);
|
Assert.IsTrue (possibleMsgs.Any (m => m == c.Messages[0]), "Expected One of: " + Environment.NewLine + string.Join (Environment.NewLine, possibleMsgs) + Environment.NewLine + "Was: " + Environment.NewLine + c.Messages[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -302,7 +306,13 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
|
|
||||||
Assert.AreEqual(3, errors.Count);
|
Assert.AreEqual(3, errors.Count);
|
||||||
#if !(NET20 || NET35)
|
#if !(NET20 || NET35)
|
||||||
Assert.AreEqual("[1] - 1 - The string was not recognized as a valid DateTime. There is an unknown word starting at index 0.", errors[0]);
|
var possibleErrs = new [] {
|
||||||
|
"[1] - 1 - The string was not recognized as a valid DateTime. There is an unknown word starting at index 0.",
|
||||||
|
"[1] - 1 - String was not recognized as a valid DateTime."
|
||||||
|
};
|
||||||
|
|
||||||
|
Assert.IsTrue(possibleErrs.Any (m => m == errors[0]),
|
||||||
|
"Expected One of: " + string.Join (Environment.NewLine, possibleErrs) + Environment.NewLine + "But was: " + errors[0]);
|
||||||
#else
|
#else
|
||||||
Assert.AreEqual("[1] - 1 - The string was not recognized as a valid DateTime. There is a unknown word starting at index 0.", errors[0]);
|
Assert.AreEqual("[1] - 1 - The string was not recognized as a valid DateTime. There is a unknown word starting at index 0.", errors[0]);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -193,5 +193,24 @@ namespace Newtonsoft.Json.Tests
|
|||||||
throw new Exception(string.Format("Exception of type {0} expected; got exception of type {1}.", typeof(TException).Name, ex.GetType().Name), ex);
|
throw new Exception(string.Format("Exception of type {0} expected; got exception of type {1}.", typeof(TException).Name, ex.GetType().Name), ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void Throws<TException>(Action action, params string[] possibleMessages)
|
||||||
|
where TException : Exception
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
action();
|
||||||
|
|
||||||
|
Assert.Fail("Exception of type {0} expected; got none exception", typeof(TException).Name);
|
||||||
|
}
|
||||||
|
catch (TException ex)
|
||||||
|
{
|
||||||
|
Assert.Contains (ex.Message, possibleMessages, "Unexpected exception message." + Environment.NewLine + "Expected One of: " + string.Join (Environment.NewLine, possibleMessages) + Environment.NewLine + "Got: " + ex.Message + Environment.NewLine + Environment.NewLine + ex);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new Exception(string.Format("Exception of type {0} expected; got exception of type {1}.", typeof(TException).Name, ex.GetType().Name), ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -107,12 +107,14 @@ namespace Newtonsoft.Json.Tests.Utilities
|
|||||||
[Test]
|
[Test]
|
||||||
public void DefaultConstructor_Abstract()
|
public void DefaultConstructor_Abstract()
|
||||||
{
|
{
|
||||||
ExceptionAssert.Throws<Exception>("Cannot create an abstract class.",
|
ExceptionAssert.Throws<Exception>(
|
||||||
() =>
|
() => {
|
||||||
{
|
|
||||||
Func<object> create = ExpressionReflectionDelegateFactory.Instance.CreateDefaultConstructor<object>(typeof(Type));
|
Func<object> create = ExpressionReflectionDelegateFactory.Instance.CreateDefaultConstructor<object>(typeof(Type));
|
||||||
|
|
||||||
create();
|
create();
|
||||||
|
}, new [] {
|
||||||
|
"Cannot create an abstract class.",
|
||||||
|
"Cannot create an abstract class 'System.Type'." // mono
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,24 +279,26 @@ namespace Newtonsoft.Json.Tests.Utilities
|
|||||||
[Test]
|
[Test]
|
||||||
public void CreateGetWithBadObjectTarget()
|
public void CreateGetWithBadObjectTarget()
|
||||||
{
|
{
|
||||||
ExceptionAssert.Throws<InvalidCastException>("Unable to cast object of type 'Newtonsoft.Json.Tests.TestObjects.Person' to type 'Newtonsoft.Json.Tests.TestObjects.Movie'.",
|
ExceptionAssert.Throws<InvalidCastException>(
|
||||||
() =>
|
() => {
|
||||||
{
|
|
||||||
Person p = new Person();
|
Person p = new Person();
|
||||||
p.Name = "Hi";
|
p.Name = "Hi";
|
||||||
|
|
||||||
Func<object, object> setter = ExpressionReflectionDelegateFactory.Instance.CreateGet<object>(typeof(Movie).GetProperty("Name"));
|
Func<object, object> setter = ExpressionReflectionDelegateFactory.Instance.CreateGet<object>(typeof(Movie).GetProperty("Name"));
|
||||||
|
|
||||||
setter(p);
|
setter(p);
|
||||||
|
},
|
||||||
|
new [] {
|
||||||
|
"Unable to cast object of type 'Newtonsoft.Json.Tests.TestObjects.Person' to type 'Newtonsoft.Json.Tests.TestObjects.Movie'.",
|
||||||
|
"Cannot cast from source type to destination type." // mono
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void CreateSetWithBadObjectTarget()
|
public void CreateSetWithBadObjectTarget()
|
||||||
{
|
{
|
||||||
ExceptionAssert.Throws<InvalidCastException>("Unable to cast object of type 'Newtonsoft.Json.Tests.TestObjects.Person' to type 'Newtonsoft.Json.Tests.TestObjects.Movie'.",
|
ExceptionAssert.Throws<InvalidCastException>(
|
||||||
() =>
|
() => {
|
||||||
{
|
|
||||||
Person p = new Person();
|
Person p = new Person();
|
||||||
Movie m = new Movie();
|
Movie m = new Movie();
|
||||||
|
|
||||||
@@ -307,20 +311,26 @@ namespace Newtonsoft.Json.Tests.Utilities
|
|||||||
setter(p, "Hi");
|
setter(p, "Hi");
|
||||||
|
|
||||||
Assert.AreEqual(p.Name, "Hi");
|
Assert.AreEqual(p.Name, "Hi");
|
||||||
|
},
|
||||||
|
new [] {
|
||||||
|
"Unable to cast object of type 'Newtonsoft.Json.Tests.TestObjects.Person' to type 'Newtonsoft.Json.Tests.TestObjects.Movie'.",
|
||||||
|
"Cannot cast from source type to destination type." // mono
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void CreateSetWithBadObjectValue()
|
public void CreateSetWithBadObjectValue()
|
||||||
{
|
{
|
||||||
ExceptionAssert.Throws<InvalidCastException>("Unable to cast object of type 'System.Version' to type 'System.String'.",
|
ExceptionAssert.Throws<InvalidCastException>(
|
||||||
() =>
|
() => {
|
||||||
{
|
|
||||||
Movie m = new Movie();
|
Movie m = new Movie();
|
||||||
|
|
||||||
Action<object, object> setter = ExpressionReflectionDelegateFactory.Instance.CreateSet<object>(typeof(Movie).GetProperty("Name"));
|
Action<object, object> setter = ExpressionReflectionDelegateFactory.Instance.CreateSet<object>(typeof(Movie).GetProperty("Name"));
|
||||||
|
|
||||||
setter(m, new Version("1.1.1.1"));
|
setter(m, new Version("1.1.1.1"));
|
||||||
|
}, new [] {
|
||||||
|
"Unable to cast object of type 'System.Version' to type 'System.String'.",
|
||||||
|
"Cannot cast from source type to destination type." //mono
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user