Ejemplo n.º 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));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }