public void UniValueCollection() { var c = new UniValueCollection(); c.Add("test", "123"); Assert.True(c.ContainsKey("test")); var k = new KeyValuePair <string, UniValue>("test2", "234"); c.Add(k); Assert.True(c.ContainsKey("test2")); Assert.True(c.Contains(k)); Assert.False(c.ContainsKey("abc")); Assert.True(c.Remove("test")); Assert.False(c.ContainsKey("test")); Assert.True(c.Remove(k)); Assert.False(c.ContainsKey("test2")); c.Add("test", "123"); c.Add("test", "234"); c.Add("test", "345"); Assert.True(c["test"].IsCollection); Assert.Equal("{ \"test\": [\"123\", \"234\", \"345\"] }", c.ToString()); Assert.Equal("[\"123\", \"234\", \"345\"]", c["test"].ToString()); Assert.False(c.Count != 1); Assert.False(c["test"].Count != 3); Assert.False(c.Keys.Count != 1); Assert.False(c.Values.Count != 1); c.Clear(); Assert.False(c.Count > 0); for (int i = 0; i <= 9; i++) { c.Add(String.Format("test-{0}", i), Guid.NewGuid().ToString()); } Assert.True(c.Count == 10); for (int i = 0; i <= 9; i++) { Assert.True(c[String.Format("test-{0}", i)] != null); } }
public void UniValueCollection_Common() { var c = new UniValueCollection(); c.Add("test", "123"); if (!c.ContainsKey("test")) { Assert.Fail(); } var k = new KeyValuePair <string, UniValue>("test2", "234"); c.Add(k); if (!c.ContainsKey("test2")) { Assert.Fail(); } if (!c.Contains(k)) { Assert.Fail(); } if (c.ContainsKey("abc")) { Assert.Fail(); } if (!c.Remove("test")) { Assert.Fail(); } if (c.ContainsKey("test")) { Assert.Fail(); } if (!c.Remove(k)) { Assert.Fail(); } if (c.ContainsKey("test2")) { Assert.Fail(); } c.Add("test", "123"); c.Add("test", "234"); c.Add("test", "345"); if (!c["test"].IsCollection) { Assert.Fail(); } Console.WriteLine(c); if (c.ToString() != "{ \"test\": [\"123\", \"234\", \"345\"] }") { Assert.Fail(); } if (c["test"] != "[\"123\", \"234\", \"345\"]") { Assert.Fail(); } Console.WriteLine(c.Count); if (c.Count != 1) { Assert.Fail(); } Console.WriteLine(c.Count); if (c["test"].Count != 3) { Assert.Fail(); } Console.WriteLine(c.Keys.Count); if (c.Keys.Count != 1) { Assert.Fail(); } Console.WriteLine(c.Values.Count); if (c.Keys.Count != 1) { Assert.Fail(); } c.Clear(); if (c.Count > 0) { Assert.Fail(); } for (int i = 0; i <= 9; i++) { c.Add(String.Format("test-{0}", i), Guid.NewGuid().ToString()); } foreach (string key in c.Keys) { Console.WriteLine("{0} = {1}", key, c[key]); } Console.WriteLine("OK"); UniValue vv = UniValue.Empty; foreach (UniValue itm in vv["data"]) { } }