Example #1
0
        public void Getter_ResultIsReturned()
        {
            var krw    = new KeyedReaderWriter <object, object>(k => 42, (k, v) => false, null);
            var result = krw.Get(null);

            Assert.IsTrue(42 == (int)result);
        }
        public void FromKeyedReaderWriter_UsesKnownIndexes()
        {
            var krw     = new KeyedReaderWriter <int, int>(x => x, (i, v) => true, () => new[] { 1, 2, 3, 4, 5 });
            var indexer = Indexer.FromKeyedReaderWriter(krw);

            Assert.IsTrue(indexer.SequenceEqual(new[] { 1, 2, 3, 4, 5 }));
        }
Example #3
0
        public void Setter_IsCalled()
        {
            bool executed = false;
            var  krw      = new KeyedReaderWriter <object, object>(k => null, (k, v) => { executed = true; return(false); }, null);

            krw.Set(null, null);
            Assert.IsTrue(executed);
        }
Example #4
0
        public void Setter_ValueIsUsed()
        {
            object result = null;

            var krw = new KeyedReaderWriter <object, object>(k => null, (k, v) => { result = v; return(true); }, null);

            krw.Set(null, 42);

            Assert.IsTrue(42 == (int)result);
        }
Example #5
0
        public void Setter_ResultIsReturned()
        {
            bool returnValue = false;

            var krw = new KeyedReaderWriter <object, object>(k => null, (k, v) => returnValue, null);

            Assert.IsFalse(krw.Set(null, null));

            returnValue = true;
            Assert.IsTrue(krw.Set(null, null));
        }
        public void FromKeyedReaderWriter_UsesReaderWriter()
        {
            int result = 0;
            var krw    = new KeyedReaderWriter <int, int>(x => x * 2, (i, v) => { result = i * v; return(true); }, null);

            var indexer = Indexer.FromKeyedReaderWriter(krw);

            Assert.AreEqual(2, indexer[1]);
            Assert.AreEqual(4, indexer[2]);
            Assert.AreEqual(6, indexer[3]);

            indexer[2] = 4;
            Assert.AreEqual(8, result);

            indexer[3] = 3;
            Assert.AreEqual(9, result);
        }