PageRenderTime 50ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/wfpcoslv/maps-examples
C# | 141 lines | 106 code | 13 blank | 22 comment | 1 complexity | b76e72e9f180c169865ca6511cf5c099 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. #if !(DNXCORE50 || PORTABLE40)
  26. using System;
  27. using System.Collections.Generic;
  28. using System.Linq;
  29. using System.Text;
  30. using Newtonsoft.Json;
  31. using Newtonsoft.Json.Linq;
  32. using System.Xml;
  33. #if !NET20
  34. using System.Xml.Linq;
  35. #endif
  36. #if DNXCORE50
  37. using Xunit;
  38. using Test = Xunit.FactAttribute;
  39. using Assert = Newtonsoft.Json.Tests.XUnitAssert;
  40. #else
  41. using NUnit.Framework;
  42. #endif
  43. namespace Newtonsoft.Json.Tests.Issues
  44. {
  45. [TestFixture]
  46. public class Issue1327 : TestFixtureBase
  47. {
  48. #if !PORTABLE
  49. public class PersonWithXmlNode
  50. {
  51. public XmlNode TestXml { get; set; }
  52. public string Name { get; set; }
  53. public int IdNumber { get; set; }
  54. }
  55. #endif
  56. #if !NET20
  57. public class PersonWithXObject
  58. {
  59. public XObject TestXml1 { get; set; }
  60. public XNode TestXml2 { get; set; }
  61. public XContainer TestXml3 { get; set; }
  62. public string Name { get; set; }
  63. public int IdNumber { get; set; }
  64. }
  65. #endif
  66. #if !PORTABLE
  67. [Test]
  68. public void Test_XmlNode()
  69. {
  70. string json = @"{
  71. ""TestXml"": {
  72. ""orders"": {
  73. ""order"": {
  74. ""id"": ""550268"",
  75. ""name"": ""vinoth""
  76. }
  77. }
  78. },
  79. ""Name"": ""Kumar"",
  80. ""IdNumber"": 990268
  81. }";
  82. var p = JsonConvert.DeserializeObject<PersonWithXmlNode>(json);
  83. Assert.AreEqual("Kumar", p.Name);
  84. Assert.AreEqual("vinoth", p.TestXml.SelectSingleNode("//name").InnerText);
  85. }
  86. #endif
  87. #if !NET20
  88. [Test]
  89. public void Test_XObject()
  90. {
  91. string json = @"{
  92. ""TestXml1"": {
  93. ""orders"": {
  94. ""order"": {
  95. ""id"": ""550268"",
  96. ""name"": ""vinoth""
  97. }
  98. }
  99. },
  100. ""TestXml2"": {
  101. ""orders"": {
  102. ""order"": {
  103. ""id"": ""550268"",
  104. ""name"": ""vinoth""
  105. }
  106. }
  107. },
  108. ""TestXml3"": {
  109. ""orders"": {
  110. ""order"": {
  111. ""id"": ""550268"",
  112. ""name"": ""vinoth""
  113. }
  114. }
  115. },
  116. ""Name"": ""Kumar"",
  117. ""IdNumber"": 990268
  118. }";
  119. var p = JsonConvert.DeserializeObject<PersonWithXObject>(json);
  120. Assert.AreEqual("Kumar", p.Name);
  121. Assert.AreEqual("vinoth", (string)((XDocument)p.TestXml1).Root.Element("order").Element("name"));
  122. Assert.AreEqual("vinoth", (string)((XDocument)p.TestXml2).Root.Element("order").Element("name"));
  123. Assert.AreEqual("vinoth", (string)((XDocument)p.TestXml3).Root.Element("order").Element("name"));
  124. }
  125. #endif
  126. }
  127. }
  128. #endif