Exemplo n.º 1
0
        public void GetValueOrDefault_of_int_dictionary_is_correct()
        {
            var dict = new Dictionary <int, int>
            {
                { 1, 10 },
                { 2, 20 },
                { 3, 30 }
            };

            dict.GetValueOrDefault(1).ShouldBe(10);
            dict.GetValueOrDefault(4).ShouldBe(0);
            IDictionaryExtension.GetValueOrDefault(dict, 5, -1).ShouldBe(-1);
        }
Exemplo n.º 2
0
        public void GetValueOrDefault_of_string_dictionary_is_correct()
        {
            var dict = new Dictionary <int, string>
            {
                { 1, "first" },
                { 2, "second" },
                { 3, "third" }
            };

            dict.GetValueOrDefault(1).ShouldBe("first");
            dict.GetValueOrDefault(4).ShouldBeNull();
            IDictionaryExtension.GetValueOrDefault(dict, 5, "five").ShouldBe("five");
        }