mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-08 17:24:49 +00:00
83 lines
1.6 KiB
C#
83 lines
1.6 KiB
C#
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using ICD.Common.Utils.Extensions;
|
|
using Newtonsoft.Json;
|
|
using NUnit.Framework;
|
|
|
|
namespace ICD.Common.Utils.Tests.Extensions
|
|
{
|
|
[TestFixture]
|
|
public sealed class JsonExtensionsTest
|
|
{
|
|
[Test]
|
|
public void WriteObjectTest()
|
|
{
|
|
Assert.Inconclusive();
|
|
}
|
|
|
|
[Test]
|
|
public void GetValueAsIntTest()
|
|
{
|
|
Assert.Inconclusive();
|
|
}
|
|
|
|
[Test]
|
|
public void GetValueAsStringTest()
|
|
{
|
|
Assert.Inconclusive();
|
|
}
|
|
|
|
[Test]
|
|
public void GetValueAsBoolTest()
|
|
{
|
|
Assert.Inconclusive();
|
|
}
|
|
|
|
[Test]
|
|
public void GetValueAsEnumTest()
|
|
{
|
|
Assert.Inconclusive();
|
|
}
|
|
|
|
[Test]
|
|
public void SerializeArrayTest()
|
|
{
|
|
JsonSerializer serializer = new JsonSerializer();
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
using (StringWriter stringWriter = new StringWriter(stringBuilder))
|
|
{
|
|
using (JsonWriter writer = new JsonTextWriter(stringWriter))
|
|
{
|
|
serializer.SerializeArray(writer, new[] {1, 2, 3, 4});
|
|
}
|
|
}
|
|
|
|
string json = stringBuilder.ToString();
|
|
Assert.AreEqual("[1,2,3,4]", json);
|
|
}
|
|
|
|
[Test]
|
|
public void DeserializeArrayTest()
|
|
{
|
|
const string json = "[1,2,3,4]";
|
|
|
|
JsonSerializer serializer = new JsonSerializer();
|
|
int[] deserialized;
|
|
|
|
using (StringReader stringReader = new StringReader(json))
|
|
{
|
|
using (JsonReader reader = new JsonTextReader(stringReader))
|
|
{
|
|
reader.Read();
|
|
deserialized = serializer.DeserializeArray<int>(reader).ToArray();
|
|
}
|
|
}
|
|
|
|
Assert.IsTrue(deserialized.SequenceEqual(new[] {1, 2, 3, 4}));
|
|
}
|
|
}
|
|
}
|