public void TryRemoveOverloadTwo()
        {
            var dictionary = new Dictionary<string, string>
            {
                { "three", "bar" }
            };

            string removed;
            dictionary.TryRemove("four", out removed).Should().BeFalse();
            removed.Should().BeNull();
            dictionary.TryRemove("three", out removed).Should().BeTrue();
            removed.Should().Be("bar");
            dictionary.Count.Should().Be(0);

            Action action = () => dictionary.TryRemove(key: null, value: out removed);
            action.ShouldThrow<ArgumentNullException>()
                .And.ParamName.Should().Be("key");

            dictionary = null;
            action.ShouldThrow<ArgumentNullException>()
                .And.ParamName.Should().Be("source");
        }
        public void TryRemoveOverloadOne()
        {
            var dictionary = new Dictionary<string, string>
            {
                { "one", "foo" },
                { "two", "foo" },
                { "three", "bar" }
            };

            dictionary.TryRemove(keys: new string[] { "zing" }).Should().BeFalse();
            dictionary.TryRemove(new string[] { "one", "three" }).Should().BeTrue();
            dictionary.Count.Should().Be(1);

            Action action = () => dictionary.TryRemove(keys: null);
            action.ShouldThrow<ArgumentNullException>()
                .And.ParamName.Should().Be("keys");

            dictionary = null;
            action.ShouldThrow<ArgumentNullException>()
                .And.ParamName.Should().Be("source");
        }
Example #3
0
        public void TryRemove_NotFound()
        {
            var dict = new Dictionary<string, string> { { "foo", "bar" } };

            string value;
            Assert.IsFalse (dict.TryRemove ("foo2", out value));
        }
        public void TryRemove()
        {
            var dictionary = new Dictionary<string, string>
            {
                { "three", "bar" }
            };

            dictionary.TryRemove("four").Should().BeFalse();
            dictionary.TryRemove("three").Should().BeTrue();
            dictionary.Count.Should().Be(0);

            Action action = () => dictionary.TryRemove(key: null);
            action.ShouldThrow<ArgumentNullException>()
                .And.ParamName.Should().Be("key");

            dictionary = null;
            action.ShouldThrow<ArgumentNullException>()
                .And.ParamName.Should().Be("source");
        }
Example #5
0
        public void TryRemove_Found()
        {
            var dict = new Dictionary<string, string> { { "foo", "bar" } };

            string value;
            Assert.IsTrue (dict.TryRemove ("foo", out value));
            Assert.AreEqual ("bar", value);
        }