using NUnit.Framework; using System.Collections.Generic; using UnityEngine; namespace Funique.Test { public sealed partial class ManagerTest { /// /// Testing the serialization functionality
/// ------------------------------------------------
/// 測試序列化元件功能 ///
public sealed class SerializationTest { List test_list = new List(); Dictionary test_dict = new Dictionary(); string buffer = string.Empty; [OneTimeSetUp] public void Setup() { AccountData d = new AccountData() { Account = "Account", Password = "Password" }; test_list.Add(d); test_dict.Add(0, d); } [OneTimeTearDown] public void TearDown() { test_list.Clear(); test_dict.Clear(); } [Order(0)] [Test] public void ListSerialization() { var s = new Serialization(test_list); buffer = JsonUtility.ToJson(s); Assert.IsFalse(string.IsNullOrEmpty(buffer), "Something is wrong, the result is null"); } [Order(1)] [Test] public void ListDeSerialization() { var s = JsonUtility.FromJson>(buffer).ToList(); Assert.AreEqual(s.Count, test_list.Count); Assert.AreEqual(s[0].Account, test_list[0].Account); Assert.AreEqual(s[0].Password, test_list[0].Password); } [Order(2)] [Test] public void DictionarySerialization() { var s = new Serialization(test_dict); buffer = JsonUtility.ToJson(s); Assert.IsFalse(string.IsNullOrEmpty(buffer), "Something is wrong, the result is null"); } [Order(3)] [Test] public void DictionaryDeSerialization() { var s = JsonUtility.FromJson>(buffer).ToDictionary(); Assert.AreEqual(s.Count, test_dict.Count); Assert.AreEqual(s[0].Account, test_dict[0].Account); Assert.AreEqual(s[0].Password, test_dict[0].Password); } } } }