PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/desktop_clients/Visual Studio/Crear beneficiarios/Json100r3/Source/Src/Newtonsoft.Json.Tests/Issues/Issue1321.cs

https://bitbucket.org/wfpcoslv/maps-examples
C# | 202 lines | 148 code | 32 blank | 22 comment | 15 complexity | 94a16740f9baf2b9d6c4662d1b29fda1 MD5 | raw file
Possible License(s): GPL-2.0
  1. #region License
  2. // Copyright (c) 2007 James Newton-King
  3. //
  4. // Permission is hereby granted, free of charge, to any person
  5. // obtaining a copy of this software and associated documentation
  6. // files (the "Software"), to deal in the Software without
  7. // restriction, including without limitation the rights to use,
  8. // copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the
  10. // Software is furnished to do so, subject to the following
  11. // conditions:
  12. //
  13. // The above copyright notice and this permission notice shall be
  14. // included in all copies or substantial portions of the Software.
  15. //
  16. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  18. // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  20. // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  21. // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  23. // OTHER DEALINGS IN THE SOFTWARE.
  24. #endregion
  25. using System;
  26. using System.Collections.Generic;
  27. using System.IO;
  28. using System.Linq;
  29. using System.Text;
  30. #if !(NET20 || NET35 || NET40 || PORTABLE40)
  31. using System.Threading.Tasks;
  32. #endif
  33. using Newtonsoft.Json;
  34. using Newtonsoft.Json.Linq;
  35. using System.Xml;
  36. #if !NET20
  37. using System.Xml.Linq;
  38. #endif
  39. #if DNXCORE50
  40. using Xunit;
  41. using Test = Xunit.FactAttribute;
  42. using Assert = Newtonsoft.Json.Tests.XUnitAssert;
  43. #else
  44. using NUnit.Framework;
  45. #endif
  46. namespace Newtonsoft.Json.Tests.Issues
  47. {
  48. [TestFixture]
  49. public class Issue1321 : TestFixtureBase
  50. {
  51. [Test]
  52. public void Test()
  53. {
  54. ExceptionAssert.Throws<JsonWriterException>(() =>
  55. {
  56. JsonConvert.DeserializeObject(
  57. @"[""1"",",
  58. new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.None, MaxDepth = 1024 });
  59. }, "Unexpected end when reading token. Path ''.");
  60. }
  61. [Test]
  62. public void Test2()
  63. {
  64. JArray a = new JArray();
  65. var writer = a.CreateWriter();
  66. JsonTextReader reader = new JsonTextReader(new StringReader(@"[""1"","));
  67. ExceptionAssert.Throws<JsonWriterException>(() =>
  68. {
  69. writer.WriteToken(reader);
  70. }, "Unexpected end when reading token. Path ''.");
  71. }
  72. #if !(NET20 || NET35 || NET40 || PORTABLE40)
  73. [Test]
  74. public async Task Test2_Async()
  75. {
  76. JArray a = new JArray();
  77. var writer = a.CreateWriter();
  78. JsonTextReader reader = new JsonTextReader(new StringReader(@"[""1"","));
  79. await ExceptionAssert.ThrowsAsync<JsonWriterException>(async () =>
  80. {
  81. await writer.WriteTokenAsync(reader);
  82. }, "Unexpected end when reading token. Path ''.");
  83. }
  84. #endif
  85. [Test]
  86. public void Test3()
  87. {
  88. JArray a = new JArray();
  89. var writer = a.CreateWriter();
  90. JsonTextReader reader = new JsonTextReader(new StringReader(@"[""1"","));
  91. reader.Read();
  92. ExceptionAssert.Throws<JsonWriterException>(() =>
  93. {
  94. writer.WriteToken(reader);
  95. }, "Unexpected end when reading token. Path ''.");
  96. }
  97. #if !(NET20 || NET35 || NET40 || PORTABLE40)
  98. [Test]
  99. public async Task Test3_Async()
  100. {
  101. JArray a = new JArray();
  102. var writer = a.CreateWriter();
  103. JsonTextReader reader = new JsonTextReader(new StringReader(@"[""1"","));
  104. await reader.ReadAsync();
  105. await ExceptionAssert.ThrowsAsync<JsonWriterException>(async () =>
  106. {
  107. await writer.WriteTokenAsync(reader);
  108. }, "Unexpected end when reading token. Path ''.");
  109. }
  110. #endif
  111. [Test]
  112. public void Test4()
  113. {
  114. JArray a = new JArray();
  115. var writer = a.CreateWriter();
  116. JsonTextReader reader = new JsonTextReader(new StringReader(@"[[""1"","));
  117. reader.Read();
  118. reader.Read();
  119. ExceptionAssert.Throws<JsonWriterException>(() =>
  120. {
  121. writer.WriteToken(reader);
  122. }, "Unexpected end when reading token. Path ''.");
  123. }
  124. #if !(NET20 || NET35 || NET40 || PORTABLE40)
  125. [Test]
  126. public async Task Test4_Async()
  127. {
  128. JArray a = new JArray();
  129. var writer = a.CreateWriter();
  130. JsonTextReader reader = new JsonTextReader(new StringReader(@"[[""1"","));
  131. await reader.ReadAsync();
  132. await reader.ReadAsync();
  133. await ExceptionAssert.ThrowsAsync<JsonWriterException>(async () =>
  134. {
  135. await writer.WriteTokenAsync(reader);
  136. }, "Unexpected end when reading token. Path ''.");
  137. }
  138. #endif
  139. [Test]
  140. public void Test5()
  141. {
  142. StringWriter sw = new StringWriter();
  143. JsonTextWriter writer = new JsonTextWriter(sw);
  144. writer.WriteStartArray();
  145. JsonTextReader reader = new JsonTextReader(new StringReader(@"[[""1"","));
  146. reader.Read();
  147. reader.Read();
  148. ExceptionAssert.Throws<JsonWriterException>(() =>
  149. {
  150. writer.WriteToken(reader);
  151. }, "Unexpected end when reading token. Path '[0]'.");
  152. }
  153. #if !(NET20 || NET35 || NET40 || PORTABLE40)
  154. [Test]
  155. public async Task Test5_Async()
  156. {
  157. StringWriter sw = new StringWriter();
  158. JsonTextWriter writer = new JsonTextWriter(sw);
  159. writer.WriteStartArray();
  160. JsonTextReader reader = new JsonTextReader(new StringReader(@"[[""1"","));
  161. await reader.ReadAsync();
  162. await reader.ReadAsync();
  163. await ExceptionAssert.ThrowsAsync<JsonWriterException>(async () =>
  164. {
  165. await writer.WriteTokenAsync(reader);
  166. }, "Unexpected end when reading token. Path '[0]'.");
  167. }
  168. #endif
  169. }
  170. }