Ejemplo n.º 1
0
        public void TestCaching()
        {
            ICache cache = new NonExpiringCache();

            context.ObjectFactory.RegisterSingleton("inventors", cache);

            ProxyFactory pf = new ProxyFactory(new InventorStore());

            pf.AddAdvisors(cacheAspect);

            IInventorStore store = (IInventorStore)pf.GetProxy();

            Assert.AreEqual(0, cache.Count);

            IList inventors = store.GetAll();

            Assert.AreEqual(2, cache.Count);

            store.Delete((Inventor)inventors[0]);
            Assert.AreEqual(1, cache.Count);

            Inventor tesla = store.Load("Nikola Tesla");

            Assert.AreEqual(2, cache.Count);

            store.Save(tesla);
            Assert.AreEqual(2, cache.Count);
            Assert.AreEqual("Serbian", ((Inventor)cache.Get("Nikola Tesla")).Nationality);

            store.DeleteAll();
            Assert.AreEqual(0, cache.Count);
        }
Ejemplo n.º 2
0
        public void CacheDoesNotImplementICache()
        {
            context.ObjectFactory.RegisterSingleton("inventors", new Object());

            ProxyFactory pf = new ProxyFactory(new InventorStore());

            pf.AddAdvisors(cacheAspect);

            IInventorStore store = (IInventorStore)pf.GetProxy();
            IList          items = store.GetAll();
        }
Ejemplo n.º 3
0
        public void CacheDoesNotExist()
        {
            //ICache cache = new NonExpiringCache();
            //context.ObjectFactory.RegisterSingleton("losers", cache);

            ProxyFactory pf = new ProxyFactory(new InventorStore());

            pf.AddAdvisors(cacheAspect);

            IInventorStore store = (IInventorStore)pf.GetProxy();
            IList          items = store.GetAll();
        }
Ejemplo n.º 4
0
        public void CacheDoesNotImplementICache()
        {
            context.ObjectFactory.RegisterSingleton("inventors", new Object());

            ProxyFactory pf = new ProxyFactory(new InventorStore());

            pf.AddAdvisors(cacheAspect);

            IInventorStore store = (IInventorStore)pf.GetProxy();

            Assert.Throws <ArgumentException>(() => store.GetAll());
        }
Ejemplo n.º 5
0
        public void CacheDoesNotExist()
        {
            //ICache cache = new NonExpiringCache();
            //context.ObjectFactory.RegisterSingleton("losers", cache);

            ProxyFactory pf = new ProxyFactory(new InventorStore());

            pf.AddAdvisors(cacheAspect);

            IInventorStore store = (IInventorStore)pf.GetProxy();

            Assert.Throws <NoSuchObjectDefinitionException>(() => store.GetAll());
        }
Ejemplo n.º 6
0
        public void NoCacheKeySpecified()
        {
            ICache cache = new NonExpiringCache();

            context.ObjectFactory.RegisterSingleton("inventors", cache);

            ProxyFactory pf = new ProxyFactory(new InventorStore());

            pf.AddAdvisors(cacheAspect);

            IInventorStore store = (IInventorStore)pf.GetProxy();

            Assert.Throws <ArgumentNullException>(() => store.GetAllNoCacheKey());
        }
Ejemplo n.º 7
0
        public void NoCacheKeySpecified()
        {
            ICache cache = new NonExpiringCache();

            context.ObjectFactory.RegisterSingleton("inventors", cache);

            ProxyFactory pf = new ProxyFactory(new InventorStore());

            pf.AddAdvisors(cacheAspect);

            IInventorStore store = (IInventorStore)pf.GetProxy();
            IList          items = store.GetAllNoCacheKey();

            Assert.IsNotNull(items);
        }
Ejemplo n.º 8
0
        public void TestCacheResultDoesNotReturnInvalidType()
        {
            ICache cache = new NonExpiringCache();

            context.ObjectFactory.RegisterSingleton("inventors", cache);

            ProxyFactory pf = new ProxyFactory(new InventorStore());

            pf.AddAdvisors(cacheAspect);

            IInventorStore store = (IInventorStore)pf.GetProxy();

            cache.Insert("Nikola Tesla", "WrongTypeForMethodSignature");

            Inventor value = store.Load("Nikola Tesla");

            Assert.That(value, Is.AssignableTo(typeof(Inventor)), "CacheAspect returned a cached type that is incompatible with the method signature return type");
        }