public void Add_Key_Value_Assigns_Value() { _Dictionary.Add("a", 123); Assert.AreEqual(123, _Dictionary["a"]); Assert.AreEqual(1, _Dictionary.AssignedCount); Assert.AreEqual("a", _Dictionary.AssignedKey); Assert.AreEqual(123, _Dictionary.AssignedValue); }
public void SerializeTest() { // [] { var dictionary = new SampleDictionary(); dictionary["key"] = new Hoge(1, "user1"); Assert.AreEqual("{\"keys\":[\"key\"],\"values\":[{\"Id\":1,\"Name\":\"user1\"}]}", JsonUtility.ToJson(dictionary)); } // Add { var dictionary = new SampleDictionary(); dictionary.Add("key", new Hoge(1, "user1")); Assert.AreEqual("{\"keys\":[\"key\"],\"values\":[{\"Id\":1,\"Name\":\"user1\"}]}", JsonUtility.ToJson(dictionary)); } // Add { var dictionary = new SampleDictionary(); dictionary.Add(new KeyValuePair <string, Hoge>("key", new Hoge(1, "user1"))); Assert.AreEqual("{\"keys\":[\"key\"],\"values\":[{\"Id\":1,\"Name\":\"user1\"}]}", JsonUtility.ToJson(dictionary)); } // Clear { var dictionary = new SampleDictionary(); dictionary.Add("key", new Hoge(1, "user1")); Assert.AreEqual("{\"keys\":[\"key\"],\"values\":[{\"Id\":1,\"Name\":\"user1\"}]}", JsonUtility.ToJson(dictionary)); } // Remove { var dictionary = new SampleDictionary(); var entity = new Hoge(1, "user1"); dictionary.Add("key", entity); dictionary.Remove(new KeyValuePair <string, Hoge>("key", entity)); Assert.AreEqual("{\"keys\":[],\"values\":[]}", JsonUtility.ToJson(dictionary)); } // new { var dictionary = new SampleDictionary( new Dictionary <string, Hoge> { { "key1", new Hoge(1, "user1") }, { "key2", new Hoge(2, "user2") } }); Assert.AreEqual( "{" + "\"keys\":[\"key1\",\"key2\"]," + "\"values\":[{\"Id\":1,\"Name\":\"user1\"},{\"Id\":2,\"Name\":\"user2\"}]" + "}", JsonUtility.ToJson(dictionary) ); } }