Exemplo n.º 1
0
        public void SystemCache_TestExpirationDate()
        {
            var key = "absCacheKey";

            var cache = new SystemCache();

            var dummy = new DummyObject()
            {
                Id = 2
            };

            cache.Add(key, dummy, DateTime.Now.AddSeconds(5));

            Thread.Sleep(2000);


            var o = cache.GetData <DummyObject>(key);

            Assert.True(o != null);
            Assert.IsType(typeof(DummyObject), o);
            Thread.Sleep(3001);


            o = cache.GetData <DummyObject>(key);

            Assert.True(o == null);
        }
Exemplo n.º 2
0
        public void SystemCache_TestSliding()
        {
            var key = "slidingCacheKey";

            var cache = new SystemCache();

            var dummy = new DummyObject()
            {
                Id = 1
            };

            cache.Add(key, dummy, TimeSpan.FromSeconds(2));

            Thread.Sleep(500);

            for (int i = 0; i < 3; i++)
            {
                var o = cache.GetData <DummyObject>(key);

                Assert.True(o != null, string.Format("failed on {0} iteration", i));
                Thread.Sleep(500);
            }

            Thread.Sleep(2001);

            var ob = cache.GetData(key);

            Assert.True(ob == null);
        }
Exemplo n.º 3
0
        public void SystemCache_TestSelfReferenceObject()
        {
            var key = "selfrefCacheKey";

            var cache = new SystemCache();

            var datString = new DATString()
            {
                DATStringId = 1,
                Name        = "test",
                Source      = "DAT",
                Type        = "SA"
            };

            datString.Equipments = new List <Equipment>();

            datString.Equipments.Add(new Equipment()
            {
                DATStrings = new HashSet <DATString>()
                {
                    datString
                }
            });

            cache.Add(key, datString);

            var ob = cache.GetData <DATString>(key);

            Assert.NotNull(ob);
        }
Exemplo n.º 4
0
        public void SystemCache_StringValueTest()
        {
            var key = "test-string";

            var cache = new SystemCache();

            //            var dummy = new DummyObject() { Id = 1 };

            cache.Add(key, "La la la");

            Thread.Sleep(500);


            var o = cache.GetData(key);

            Assert.True(o != null, "failed on {0} iteration");
            Assert.Equal(o, "La la la");

            string str = cache.GetData <string>(key);

            Assert.True(str != null, "failed on {0} iteration");
            Assert.Equal(str, "La la la");
        }