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