Exemple #1
0
        public void ContainsKey_OnlyReturnsTrue_IfValueCanBeLoaded()
        {
            var dictionary = new LazySelectionDictionary <int, string>(x => x.ToMaybe().Where(y => y != 1).Select(y => y.ToString()));

            Assert.IsFalse(dictionary.ContainsKey(1));
            Assert.IsTrue(dictionary.ContainsKey(42));
        }
Exemple #2
0
        public void TryGetValue_InvokesSelectionFunc()
        {
            var    dictionary = new LazySelectionDictionary <int, string>(x => x.ToMaybe().Where(y => y % 2 == 0).Select(y => x.ToString()));
            string value      = null;

            Assert.IsFalse(dictionary.TryGetValue(1, out value));
            Assert.IsTrue(dictionary.TryGetValue(2, out value));
            Assert.AreEqual("2", value);
        }
Exemple #3
0
        public void GetValue_EvaluatesOnce()
        {
            int executed   = 0;
            var dictionary = new LazySelectionDictionary <int, string>(x => { executed++; return(x.ToString().ToMaybe()); });

            string value = dictionary[1];

            value = dictionary[1];

            Assert.AreEqual("1", value);
            Assert.AreEqual(1, executed);
        }