示例#1
0
        public void WorkCorrectly_WithJson1Task()
        {
            var res = JsonProgram.ConvertJson(@"{""version"":""2"",""products"":{""642572671"":{""name"":""\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t"",""price"":26755360,""count"":2147483647},""462028247"":{""name"":""\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t"",""price"":1812829817,""count"":1583821338},""1064089862"":{""name"":""jtXpDL4AA"",""price"":1,""count"":1765575149},""441937189"":{""name"":""LPAI"",""price"":2119059550,""count"":260983550},""1493811026"":{""name"":""M"",""price"":1208992471,""count"":1},""1"":{""name"":"""",""price"":1,""count"":1},""1031623038"":{""name"":""XuNL"",""price"":188661436,""count"":0},""0"":{""name"":""Vz"",""price"":2147483647,""count"":1}}}");

            Assert.That(res, Is.EqualTo(CleanFormatting(@"
{
  ""version"": ""3"",
  ""products"": [
    {
      ""id"": 642572671,
      ""name"": ""\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t"",
      ""price"": 26755360.0,
      ""count"": 2147483647
    },
    {
      ""id"": 462028247,
      ""name"": ""\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t"",
      ""price"": 1812829817.0,
      ""count"": 1583821338
    },
    {
      ""id"": 1064089862,
      ""name"": ""jtXpDL4AA"",
      ""price"": 1.0,
      ""count"": 1765575149
    },
    {
      ""id"": 441937189,
      ""name"": ""LPAI"",
      ""price"": 2119059550.0,
      ""count"": 260983550
    },
    {
      ""id"": 1493811026,
      ""name"": ""M"",
      ""price"": 1208992471.0,
      ""count"": 1
    },
    {
      ""id"": 1,
      ""name"": """",
      ""price"": 1.0,
      ""count"": 1
    },
    {
      ""id"": 1031623038,
      ""name"": ""XuNL"",
      ""price"": 188661436.0,
      ""count"": 0
    },
    {
      ""id"": 0,
      ""name"": ""Vz"",
      ""price"": 2147483647.0,
      ""count"": 1
    }
  ]
}")));
        }
示例#2
0
        public void Simple()
        {
            var res = JsonProgram.ConvertJson(@"
{
	""version"": ""2"",
	""products"": {
		""1"": {
			""name"": ""Pen"",
			""price"": 12,
			""count"": 100
		},
		""2"": {
			""name"": ""Pencil"",
			""price"": 8,
			""count"": 1000
		},
		""3"": {
			""name"": ""Box"",
			""price"": 12.1,
			""count"": 50
		}
	}
}
");

            Assert.That(res, Is.EqualTo(CleanFormatting(@"
{
	""version"": ""3"",
	""products"": [
		{
			""id"": 1,
			""name"": ""Pen"",
			""price"": 12.0,
			""count"": 100
		},
		{
			""id"": 2,
			""name"": ""Pencil"",
			""price"": 8.0,
			""count"": 1000
		},
		{
			""id"": 3,
			""name"": ""Box"",
			""price"": 12.1,
			""count"": 50
		}
	]
}")));
        }
示例#3
0
        public void JsonTestV1(string v2, string v3)
        {
            var jsonV2 = "";

            using (StreamReader sr = new StreamReader(v2))
            {
                jsonV2 = sr.ReadToEnd();
            }
            JObject jsonV3 = new JObject();

            using (StreamReader sr = new StreamReader(v3))
            {
                jsonV3 = JObject.Parse(sr.ReadToEnd());
            }

            JObject resultJson = JsonProgram.ConverJson(jsonV2);

            Assert.AreEqual(jsonV3, resultJson);
        }
示例#4
0
        public void WorkCorrectly_WithJson2Task()
        {
            var res = JsonProgram.ConvertJson(@"{""version"":""2"",""constants"":{""pi"":3.14},""products"":{""1"":{""name"":""product-name"",""price"":""12.3 * pi + pi + 4"",""count"":100}}}"
                                              );

            //onsole.WriteLine(JObject.Parse(@"{ ""version"":""2"",""constants"":{ ""pi"":3.14},""products"":{ ""1"":{ ""name"":""product - name"",""price"":""12.3 * pi + pi + 4"",""count"":100} } }"));
            Assert.That(CleanFormatting(res), Is.EqualTo(CleanFormatting(@"
{
    ""version"": ""3"",
    ""products"": [
      {
      ""id"": 1,
      ""name"": ""product-name"",
      ""price"": 45.762,
      ""count"": 100
    }
  ]
}")));
        }
示例#5
0
        public void MakeSingleQuotes_ifQuoted()
        {
            var result = JsonProgram.MakeSingleQuotes(new string[] { "test", "test4" }, "\"test\": \"test2\", \"test4\": \"test5\"");

            Assert.AreEqual("'test': 'test2', 'test4': 'test5'", result);
        }
示例#6
0
        public void MakeSingleQuotes_notTouch()
        {
            var result = JsonProgram.MakeSingleQuotes(new string[] { "test" }, "\"test\": 1, \"test4\": 2");

            Assert.AreEqual("'test': 1, \"test4\": 2", result);
        }
示例#7
0
        public void MakeSingleQuotes_ifNotQuoted()
        {
            var result = JsonProgram.MakeSingleQuotes(new string[] { "test", "test4" }, "\"test\": 1, \"test4\": 2");

            Assert.AreEqual("'test': 1, 'test4': 2", result);
        }