mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-01-11 19:44:55 +00:00
refactor: Rewrote JsonItemWrapper serialization for JsonConvert friendliness
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ICD.Common.Utils.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace ICD.Common.Utils.Tests.Json
|
||||
@@ -14,7 +14,7 @@ namespace ICD.Common.Utils.Tests.Json
|
||||
[TestCase(1, typeof(int))]
|
||||
public void ItemTypeTest(object item, Type expected)
|
||||
{
|
||||
Assert.AreEqual(expected, new JsonItemWrapper(item).ItemType);
|
||||
Assert.AreEqual(expected, new JsonItemWrapper(item).Type);
|
||||
}
|
||||
|
||||
[TestCase("")]
|
||||
@@ -27,19 +27,21 @@ namespace ICD.Common.Utils.Tests.Json
|
||||
[Test]
|
||||
public void WriteTest()
|
||||
{
|
||||
JsonItemWrapper wrapper = new JsonItemWrapper(new List<int> {1, 2, 3});
|
||||
string json = JsonUtils.Serialize(wrapper.Write);
|
||||
const string expected = @"{""t"":""System.Collections.Generic.List`1[[System.Int32]]"",""i"":[1,2,3]}";
|
||||
|
||||
Assert.Inconclusive();
|
||||
JsonItemWrapper wrapper = new JsonItemWrapper(new List<int> {1, 2, 3});
|
||||
string json = JsonConvert.SerializeObject(wrapper);
|
||||
|
||||
Assert.AreEqual(expected, json);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReadTest()
|
||||
{
|
||||
const string json = "{\"t\":\"System.Collections.Generic.List`1[[System.Int32, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]\",\"i\":\"[1,2,3]\"}";
|
||||
const string json = @"{""t"":""System.Collections.Generic.List`1[[System.Int32]]"",""i"":[1,2,3]}";
|
||||
|
||||
JObject jObject = JObject.Parse(json);
|
||||
List<int> wrappedObject = JsonItemWrapper.ReadToObject(jObject) as List<int>;
|
||||
JsonItemWrapper wrapper = JsonConvert.DeserializeObject<JsonItemWrapper>(json);
|
||||
List<int> wrappedObject = wrapper.Item as List<int>;
|
||||
|
||||
Assert.NotNull(wrappedObject);
|
||||
Assert.AreEqual(3, wrappedObject.Count);
|
||||
|
||||
Reference in New Issue
Block a user