public void RemoveItem_ItemNotExists_ReturnsFalse()
        {
            var dctIntStr = new DictionaryImplementedWithList <int, string>();

            dctIntStr.Add(1, "a");
            dctIntStr.Remove(new KeyValuePair <int, string>(2, "a")).Should().BeFalse();
        }
        public void RemoveByKey_KeyNotExists_ReturnsFalse()
        {
            var dctIntStr = new DictionaryImplementedWithList <int, string>();

            dctIntStr.Add(1, "a");
            dctIntStr.Remove(2).Should().BeFalse();
        }
        public void ContainsKey_NonSpecialKey_KeyNotExists_ReturnsFalse()
        {
            var dctIntStr = new DictionaryImplementedWithList <int, string>();

            dctIntStr.Add(1, "a");
            dctIntStr.ContainsKey(2).Should().BeFalse();
        }
        public void ContainsKey_StringKey_UsesCaseInsensitiveCompare_KeyExists_ReturnsTrue()
        {
            var dctStrStr = new DictionaryImplementedWithList <string, string>();

            dctStrStr.Add("mykey", "myvalue");
            dctStrStr.ContainsKey("MYKEY").Should().BeTrue();
        }
        public void DictionaryGet_KeyNotExists_ThrowsKeyNotFound()
        {
            var    dctIntStr = new DictionaryImplementedWithList <int, string>();
            string val;
            Action act = () => val = dctIntStr[3];

            act.ShouldThrow <KeyNotFoundException>();
        }
        public void Add_KeyNotExist_IncreasesCount()
        {
            var dctIntStr = new DictionaryImplementedWithList <int, string>();

            dctIntStr.Count.Should().Be(0);
            dctIntStr.Add(new KeyValuePair <int, string>(1, "A"));
            dctIntStr.Count.Should().Be(1);
        }
        public void DictionarySet_KeyExists_SetsValue()
        {
            var dctIntStr = new DictionaryImplementedWithList <int, string>();

            dctIntStr.Add(1, "a");
            dctIntStr[1] = "b";

            dctIntStr[1].Should().Be("b");
        }
        public void DictionaryGet_KeyExists_ReturnsValue()
        {
            var dctIntStr = new DictionaryImplementedWithList <int, string>();

            dctIntStr.Add(1, "A");
            var val = dctIntStr[1];

            val.Should().Be("A");
        }
        public void Add_KeyExists_ThrowsError()
        {
            var dctIntStr = new DictionaryImplementedWithList <int, string>();

            dctIntStr.Add(new KeyValuePair <int, string>(1, "A"));
            Action act = () => dctIntStr.Add(new KeyValuePair <int, string>(1, "A"));

            act.ShouldThrow <ArgumentException>();
        }
        public void TryGetValue_KeyNotExists_ReturnFalse()
        {
            var    dctIntStr = new DictionaryImplementedWithList <int, string>();
            string myValue;

            dctIntStr.Add(1, "a");

            dctIntStr.TryGetValue(2, out myValue).Should().BeFalse();
        }
        public void DictionarySet_KeyNotExists_ThrowsKeyNotFound()
        {
            var dctIntStr = new DictionaryImplementedWithList <int, string>();

            dctIntStr.Add(1, "a");

            Action act = () => dctIntStr[2] = "A";

            act.ShouldThrow <KeyNotFoundException>();
        }
        public void Clear_ReducesCountToZero()
        {
            var dctIntStr = new DictionaryImplementedWithList <int, string>();

            dctIntStr.Add(1, "A");
            dctIntStr.Count.Should().Be(1);

            dctIntStr.Clear();
            dctIntStr.Count.Should().Be(0);
        }
        public void ContainsKey_ObjectKey_UseCustomComparer_KeyNotExists_ReturnsFalse()
        {
            var dctObjStr = new DictionaryImplementedWithList <Animal, string>(
                new AnimalComparer());
            var tony = new Animal {
                Name = "Tony", Says = "Roar"
            };
            var simba = new Animal {
                Name = "Tigger", Says = "Meow"
            };

            dctObjStr.Add(tony, "they're great!");
            dctObjStr.ContainsKey(simba).Should().BeFalse();
        }
        public void GetEnumerator_CanEnumerate()
        {
            var dctIntStr = new DictionaryImplementedWithList <int, string>();

            dctIntStr.Add(1, "a");
            dctIntStr.Add(2, "b");
            dctIntStr.Add(3, "c");

            var enumerator = dctIntStr.GetEnumerator();
            var counter    = 1;

            while (enumerator.MoveNext())
            {
                var pair = enumerator.Current;
                pair.Key.Should().Be(counter);
                counter++;
            }
        }
        public void CopyTo_CopiesDictionaryToArray()
        {
            var myArray   = new KeyValuePair <int, string> [5];
            var dctIntStr = new DictionaryImplementedWithList <int, string>();

            dctIntStr.Add(1, "a");
            dctIntStr.Add(2, "b");
            dctIntStr.Add(3, "c");

            dctIntStr.CopyTo(myArray, 2);

            myArray[2].Key.Should().Be(1);
            myArray[2].Value.Should().Be("a");
            myArray[3].Key.Should().Be(2);
            myArray[3].Value.Should().Be("b");
            myArray[4].Key.Should().Be(3);
            myArray[4].Value.Should().Be("c");
        }