public void TestFileMetadataPairsConverterCouldSerializeAndDeserialize() { FileMetadataPairs item = new FileMetadataPairs( new List <FileMetadataPairsItem> { new FileMetadataPairsItem("*.md", 1L), new FileMetadataPairsItem("*.m", true), new FileMetadataPairsItem("abc", "string"), new FileMetadataPairsItem("/[]\\*.cs", new Dictionary <string, object> { ["key"] = "2" }), new FileMetadataPairsItem("*/*.cs", new object[] { "1", "2" }), new FileMetadataPairsItem("**", new Dictionary <string, object> { ["key"] = new object[] { "1", "2" } }), }); var result = JsonUtility.Serialize(item); Assert.Equal("{\"*.md\":1,\"*.m\":true,\"abc\":\"string\",\"/[]\\\\*.cs\":{\"key\":\"2\"},\"*/*.cs\":[\"1\",\"2\"],\"**\":{\"key\":[\"1\",\"2\"]}}", result); using (var reader = new StringReader(result)) { var pairs = JsonUtility.Deserialize <FileMetadataPairs>(reader); Assert.Equal(item.Count, pairs.Count); for (int i = 0; i < pairs.Count; i++) { Assert.Equal(item[i].Glob.Raw, pairs[i].Glob.Raw); var parsedValue = pairs[i].Value; Assert.Equal(item[i].Value, parsedValue); } } }
public void TestFileMetadataPairsConverterCouldSerializeAndDeserialize() { FileMetadataPairs item = new FileMetadataPairs( new List<FileMetadataPairsItem> { new FileMetadataPairsItem("*.md", 1L), new FileMetadataPairsItem("*.m", true), new FileMetadataPairsItem("abc", "string"), new FileMetadataPairsItem("/[]\\*.cs", new Dictionary<string, object>{ ["key"] = "2" }), new FileMetadataPairsItem("*/*.cs", new object[] { "1", "2" }), new FileMetadataPairsItem("**", new Dictionary<string, object>{ ["key"] = new object[] {"1", "2" } }), }); var result = JsonUtility.Serialize(item); Assert.Equal("{\"*.md\":1,\"*.m\":true,\"abc\":\"string\",\"/[]\\\\*.cs\":{\"key\":\"2\"},\"*/*.cs\":[\"1\",\"2\"],\"**\":{\"key\":[\"1\",\"2\"]}}", result); using (var reader = new StringReader(result)) { var pairs = JsonUtility.Deserialize<FileMetadataPairs>(reader); Assert.Equal(item.Count, pairs.Count); for (int i = 0; i < pairs.Count; i++) { Assert.Equal(item[i].Glob.Raw, pairs[i].Glob.Raw); var parsedValue = ConvertJObjectToObject((JToken)pairs[i].Value); Assert.Equal(item[i].Value, parsedValue); } } }