Skip to content

Instantly share code, notes, and snippets.

@ozw-sei
Created September 13, 2016 13:39
Show Gist options
  • Save ozw-sei/f580081d5cbc7121022beb7995cf224d to your computer and use it in GitHub Desktop.
Save ozw-sei/f580081d5cbc7121022beb7995cf224d to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEditor;
using NUnit.Framework;
public class JsonUtilTest {
[System.Serializable]
public class user_self{
public user data;
}
[System.Serializable]
public class user{
public string id;
public string username;
public string full_name;
public string profile_picture;
public string bio;
public string website;
public count counts;
}
[System.Serializable]
public class count{
public int media;
public int follows;
public int followed_by;
}
[Test]
public void HogeTest(){
var json2 = @"{
""data"": {
""id"": ""1574083"",
""username"": ""snoopdogg"",
""full_name"": ""Snoop Dogg"",
""profile_picture"": ""http://distillery.s3.amazonaws.com/profiles/profile_1574083_75sq_1295469061.jpg"",
""bio"": ""This is my bio"",
""website"": ""http://snoopdogg.com""
}
}";
var result2 = JsonUtility.FromJson<user_self>(json2);
Assert.AreEqual(result2.data.counts.followed_by, 0);
Assert.AreEqual(result2.data.counts.follows, 0);
Assert.AreEqual(result2.data.counts.media, 0);
}
[Test]
public void EditorTest()
{
// https://api.instagram.com/v1/users/self/?access_token=ACCESS-TOKEN
var json = @"
{
""data"": {
""id"": ""1574083"",
""username"": ""snoopdogg"",
""full_name"": ""Snoop Dogg"",
""profile_picture"": ""http://distillery.s3.amazonaws.com/profiles/profile_1574083_75sq_1295469061.jpg"",
""bio"": ""This is my bio"",
""website"": ""http://snoopdogg.com"",
""counts"": {
""media"": 1320,
""follows"": 420,
""followed_by"": 3410
}
}
}";
var result = JsonUtility.FromJson<user_self>(json);
Assert.That(Is.Equals(result.data.counts.media, 1320));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment