Exemplo n.º 1
0
        public void TestRegisterTNull()
        {
            var cache = new PropertyGetterCache();

            Assert.ThrowsException<ArgumentNullException>(
                () => cache.Register<PropertyGetterCacheTests>(
                    nameof(TestContext),
                    null
                )
            );
        }
Exemplo n.º 2
0
        public void TestRegisterAlreadyRegistered()
        {
            var cache = new PropertyGetterCache();

            cache.Register(
                typeof(PropertyGetterCacheTests),
                nameof(TestContext),
                (obj) => 5
            );
            cache.Register(
                typeof(PropertyGetterCacheTests),
                nameof(TestContext),
                (obj) => 7
            );

            var getter = cache.Get(
                typeof(PropertyGetterCacheTests),
                nameof(TestContext)
            );

            Assert.AreEqual(7, getter(this));
        }
Exemplo n.º 3
0
        public void TestIndexer()
        {
            var cache = new PropertyGetterCache();
            cache.Register(
                typeof(PropertyGetterCacheTests),
                nameof(TestContext),
                (obj) => 5
            );

            var typeCache = cache[typeof(PropertyGetterCacheTests)];

            Assert.IsNotNull(typeCache);
            Assert.AreEqual(typeof(PropertyGetterCacheTests), typeCache.Type);
        }
Exemplo n.º 4
0
        public void TestGetRegisteredGeneric()
        {
            var cache = new PropertyGetterCache();
            cache.Register<PropertyGetterCacheTests>(
                nameof(TestContext),
                (obj) => 5
            );

            Func<object, object> getter = cache.Get(
                typeof(PropertyGetterCacheTests),
                nameof(TestContext)
            );

            Assert.AreEqual(5, getter(this));
        }