コード例 #1
0
        public void CanUpdateCache()
        {
            var expiration  = new ExpirationStrategyMock();
            var planId      = new Guid(1, (short)0, (short)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0);
            int calledTimes = 0;

            var plan           = LoadPlan(planId);
            var referenceRoute = LoadPlan(planId);

            Func <Guid, PlanNodeDO> cacheMiss = x =>
            {
                calledTimes++;
                Assert.AreEqual(planId, x);
                return(plan);
            };

            var cache = new PlanCache(expiration);

            var plan1   = cache.Get(planId, cacheMiss);
            var updated = LoadPlan(planId, "updated");

            var o = new PlanSnapshot(plan1, false);
            var c = new PlanSnapshot(updated, false);

            cache.Update(updated.Id, c.Compare(o));
            var plan2 = cache.Get(planId, cacheMiss);

            Assert.AreEqual(1, calledTimes);
            Assert.IsTrue(AreEquals(plan1, referenceRoute));
            Assert.IsTrue(AreEquals(plan2, updated));
        }
コード例 #2
0
        public void CanLoadFromCacheUsingChildActivitiesId()
        {
            var expiration  = new ExpirationStrategyMock();
            var planId      = new Guid(1, (short)0, (short)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0);
            int calledTimes = 0;

            var plan = LoadPlan(planId);

            Func <Guid, PlanNodeDO> cacheMiss = x =>
            {
                calledTimes++;
                return(plan);
            };

            var cache = new PlanCache(expiration);

            var plan1 = cache.Get(new Guid(2, (short)0, (short)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0), cacheMiss);

            Assert.IsTrue(AreEquals(plan1, plan));

            foreach (var id in PlanTreeHelper.Linearize(plan).Select(x => x.Id))
            {
                Assert.IsTrue(AreEquals(plan, cache.Get(id, cacheMiss)));
            }

            Assert.AreEqual(1, calledTimes);
        }
コード例 #3
0
        public void CanExpireItems()
        {
            var expiration  = new ExpirationStrategyMock();
            var planId      = new Guid(1, (short)0, (short)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0);
            int calledTimes = 0;

            Func <Guid, PlanNodeDO> cacheMiss = x =>
            {
                calledTimes++;
                Assert.AreEqual(planId, x);
                return(LoadPlan(x));
            };

            var cache = new PlanCache(expiration);


            cache.Get(planId, cacheMiss);
            expiration.InvokeExpirationCallback();
            cache.Get(planId, cacheMiss);

            Assert.AreEqual(2, calledTimes);
        }