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 } ] }"))); }
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 } ] }"))); }
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); }
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 } ] }"))); }
public void MakeSingleQuotes_ifQuoted() { var result = JsonProgram.MakeSingleQuotes(new string[] { "test", "test4" }, "\"test\": \"test2\", \"test4\": \"test5\""); Assert.AreEqual("'test': 'test2', 'test4': 'test5'", result); }
public void MakeSingleQuotes_notTouch() { var result = JsonProgram.MakeSingleQuotes(new string[] { "test" }, "\"test\": 1, \"test4\": 2"); Assert.AreEqual("'test': 1, \"test4\": 2", result); }
public void MakeSingleQuotes_ifNotQuoted() { var result = JsonProgram.MakeSingleQuotes(new string[] { "test", "test4" }, "\"test\": 1, \"test4\": 2"); Assert.AreEqual("'test': 1, 'test4': 2", result); }