public void Remove_Key()
        {
            var map = new MapField <string, string>();

            map.Add("foo", "bar");
            Assert.AreEqual(1, map.Count);
            Assert.IsFalse(map.Remove("missing"));
            Assert.AreEqual(1, map.Count);
            Assert.IsTrue(map.Remove("foo"));
            Assert.AreEqual(0, map.Count);
            Assert.Throws <ArgumentNullException>(() => map.Remove(null));
        }
        public void EqualityHandlesNullValues()
        {
            var map1 = new MapField <string, ForeignMessage>();

            map1.Add("a", new ForeignMessage {
                C = 10
            });
            map1.Add("b", null);

            var map2 = new MapField <string, ForeignMessage>();

            map2.Add("a", new ForeignMessage {
                C = 10
            });
            map2.Add("b", null);

            EqualityTester.AssertEquality(map1, map2);
            // Check the null value isn't ignored entirely...
            Assert.IsTrue(map1.Remove("b"));
            EqualityTester.AssertInequality(map1, map2);
            map1.Add("b", new ForeignMessage());
            EqualityTester.AssertInequality(map1, map2);
            map1["b"] = null;
            EqualityTester.AssertEquality(map1, map2);
        }
        public void AddPreservesInsertionOrder()
        {
            var map = new MapField <string, string>();

            map.Add("a", "v1");
            map.Add("b", "v2");
            map.Add("c", "v3");
            map.Remove("b");
            map.Add("d", "v4");
            CollectionAssert.AreEqual(new[] { "a", "c", "d" }, map.Keys);
            CollectionAssert.AreEqual(new[] { "v1", "v3", "v4" }, map.Values);
        }