public void Remove_Copes_When_Key_Not_Present() { var actual = _Dictionary.Remove("a"); Assert.AreEqual(false, actual); Assert.AreEqual(0, _Dictionary.RemovedCount); }
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) ); } }
public void Remove_Removes_KeyValuePair() { _Dictionary = new SampleDictionary(new Dictionary <string, int?>() { ["a"] = 48, }); var actual = _Dictionary.Remove(new KeyValuePair <string, int?>("a", 48)); Assert.AreEqual(true, actual); Assert.IsFalse(_Dictionary.ContainsKey("a")); Assert.AreEqual(1, _Dictionary.RemovedCount); Assert.AreEqual("a", _Dictionary.RemovedKey); }