Ejemplo n.º 1
0
 public TCacheGetTests()
 {
     using (TCacheService cache = new TCacheService())
     {
         bool cleaned = cache.RemoveKey(TestQueueName).Result&& cache.RemoveKey(TestQueueNameSecond).Result;
     }
 }
Ejemplo n.º 2
0
        public async Task SearchKeyValues()
        {
            using (TCacheService cache = new TCacheService(TestConfiguration.EnvRedisUri))
            {
                await cache.SetObjectAsKeyValue("user:test2:5", "test1");

                await cache.SetObjectAsKeyValue("user:test2:6", "test2");

                await cache.SetObjectAsKeyValue("user:test2:7", "test3");

                await cache.SetObjectAsKeyValue("user:test2:8", "test4");

                var results = await cache.SearchKeyValues("user:test2*");

                bool resultCheck = results.ContainsValue("test1") && results.ContainsValue("test2") && results.ContainsValue("test3") && results.ContainsValue("test4");

                Assert.Equal(4, results.Count);
                Assert.True(resultCheck);

                foreach (var item in results.Keys)
                {
                    await cache.RemoveKey(item);
                }
            }
        }
Ejemplo n.º 3
0
        public async Task SearchKeyValuesTyped()
        {
            using (TCacheService cache = new TCacheService(TestConfiguration.EnvRedisUri))
            {
                await cache.SetObjectAsKeyValue("user:test3:9", new Cat { Name = "Ted" });

                await cache.SetObjectAsKeyValue("user:test3:10", new Cat { Name = "Fred" });

                await cache.SetObjectAsKeyValue("user:test3:11", new Cat { Name = "Ned" });

                await cache.SetObjectAsKeyValue("user:test3:12", new Cat { Name = "Bed" });

                var results = await cache.SearchKeyValues <Cat>("user:test3*");

                List <string> resultValues = results.Values.Select(x => x.Name).ToList();

                bool resultCheck = resultValues.Contains("Ted") && resultValues.Contains("Fred") && resultValues.Contains("Ned") && resultValues.Contains("Bed");

                Assert.Equal(4, results.Count);
                Assert.True(resultCheck);

                foreach (var item in results.Keys)
                {
                    await cache.RemoveKey(item);
                }
            }
        }
Ejemplo n.º 4
0
 public TCacheCreatePushTests()
 {
     using (TCacheService cache = new TCacheService())
     {
         bool cleaned = cache.RemoveKey(TestQueueName).Result;
     }
 }
Ejemplo n.º 5
0
        public async Task RemoveKeyNoKey()
        {
            using (TCacheService cache = new TCacheService(TestConfiguration.EnvRedisUri))
            {
                bool result = await cache.RemoveKey("blah blah blah");

                Assert.True(result);
            }
        }
Ejemplo n.º 6
0
        public async Task GetEmptyNoTypeQueue()
        {
            using (TCacheService cache = new TCacheService(TestConfiguration.EnvRedisUri))
            {
                string noCat = await cache.PopFromQueue(TestQueueNameEmpty);

                Assert.Null(noCat);
            }
        }
Ejemplo n.º 7
0
        public async Task GetEmptyTypesValue()
        {
            using (TCacheService cache = new TCacheService(TestConfiguration.EnvRedisUri))
            {
                Cat value = await cache.GetValueFromKey <Cat>("test4");

                Assert.Null(value);
            }
        }
Ejemplo n.º 8
0
        public async Task RemoveQueue()
        {
            using (TCacheService cache = new TCacheService(TestConfiguration.EnvRedisUri))
            {
                await cache.RemoveKey(TestQueueName);

                bool exists = await cache.QueueExists(TestQueueName);

                Assert.False(exists);
            }
        }
Ejemplo n.º 9
0
        public async Task PopTedFromQueue()
        {
            TCacheService cache = new TCacheService(TestConfiguration.EnvRedisUri);
            Cat           cat1  = await cache.PopFromQueue <Cat>(TestQueueName, TCachePopMode.Delete);

            Cat cat2 = await cache.PopFromQueue <Cat>(TestQueueName, TCachePopMode.Delete);

            bool done = cat1.Name == "Ted" && cat2 == null;

            Assert.True(done);
        }
Ejemplo n.º 10
0
        public async Task CreateQueue()
        {
            TCacheService cache = new TCacheService(TestConfiguration.EnvRedisUri);

            await cache.PushToQueue(TestQueueName, new List <Cat> {
                new Cat {
                    Name = "Ted", Age = 3
                }
            });

            Assert.True(await cache.QueueExists(TestQueueName));
        }
Ejemplo n.º 11
0
        public async Task KeyExistsTest()
        {
            using (TCacheService cache = new TCacheService(TestConfiguration.EnvRedisUri))
            {
                await cache.SetObjectAsKeyValue("test6", "test");

                bool result = await cache.KeyExists("test6");

                await cache.RemoveKey("test6");

                Assert.True(result);
            }
        }
Ejemplo n.º 12
0
        public async Task SetKey()
        {
            using (TCacheService cache = new TCacheService(TestConfiguration.EnvRedisUri))
            {
                await cache.SetObjectAsKeyValue("test2", "hi!");

                string value = await cache.GetValueFromKey("test2");

                await cache.RemoveKey("test2");

                Assert.Equal("hi!", value);
            }
        }
Ejemplo n.º 13
0
        public async Task TypedValueFetch()
        {
            using (TCacheService cache = new TCacheService(TestConfiguration.EnvRedisUri))
            {
                await cache.SetObjectAsKeyValue("test5", new Cat { Name = "Billy", Age = 90 });

                var result = await cache.GetValueFromKey <Cat>("test5");

                await cache.RemoveKey("test5");

                Assert.True(result is Cat && result.Name == "Billy" && result.Age == 90);
            }
        }
Ejemplo n.º 14
0
        public async Task SetKeyExpiring()
        {
            using (TCacheService cache = new TCacheService(TestConfiguration.EnvRedisUri))
            {
                await cache.SetObjectAsKeyValue("test3", new Cat { }, TimeSpan.FromSeconds(5));

                bool initialCheck = await cache.KeyExists("test3");

                await Task.Delay(TimeSpan.FromSeconds(6));

                bool finalCheck = await cache.KeyExists("test3");

                Assert.True(initialCheck && !finalCheck);
            }
        }
Ejemplo n.º 15
0
        public async Task RemoveKeyWithKey()
        {
            using (TCacheService cache = new TCacheService(TestConfiguration.EnvRedisUri))
            {
                // set
                await cache.SetObjectAsKeyValue("test1", "blah blah blah");

                // remove
                await cache.RemoveKey("test1");

                // check
                string result = await cache.GetValueFromKey("test1");

                // asert
                Assert.Null(result);
            }
        }
Ejemplo n.º 16
0
        public async Task TestRemoveExistingQueue()
        {
            using (TCacheService cache = new TCacheService(TestConfiguration.EnvRedisUri))
            {
                await cache.PushToQueue(TestRemoveQueue, new List <Cat> {
                    new Cat {
                        Name = "Kel", Age = 12
                    }
                });

                await cache.RemoveQueue(TestRemoveQueue);

                bool result = await cache.QueueExists(TestRemoveQueue);

                Assert.False(result);
            }
        }
Ejemplo n.º 17
0
        public async Task BasicGetQueue()
        {
            // NOTE: This test is both to test the basic string fetch functionality and it tests to see if an empty LIST key properly unsets
            using (TCacheService cache = new TCacheService())
            {
                await cache.PushToQueue(TestQueueNameSecond, new List <Cat> {
                    new Cat {
                        Name = "Amolee"
                    }
                });

                string result = await cache.PopFromQueue(TestQueueNameSecond);

                bool resultCheck = result.Contains("Amolee");
                bool queueExists = await cache.QueueExists(TestQueueNameSecond);

                Assert.True(resultCheck && !queueExists);
            }
        }
Ejemplo n.º 18
0
        public async Task SearchKeys()
        {
            using (TCacheService cache = new TCacheService(TestConfiguration.EnvRedisUri))
            {
                await cache.SetObjectAsKeyValue("user:test1:1", "test");

                await cache.SetObjectAsKeyValue("user:test1:2", "test");

                await cache.SetObjectAsKeyValue("user:test1:3", "test");

                await cache.SetObjectAsKeyValue("user:test1:4", "test");

                List <string> results = await cache.SearchKeys("user:test1*");

                Assert.Equal(4, results.Count);

                foreach (var item in results)
                {
                    await cache.RemoveKey(item);
                }
            }
        }
Ejemplo n.º 19
0
        public async Task GetQueue()
        {
            TCacheService cache = new TCacheService(TestConfiguration.EnvRedisUri);
            await cache.PushToQueue(TestQueueName, new List <Cat> {
                new Cat {
                    Name = "NotDead", Age = 3
                }
            });

            Cat cat1 = await cache.PopFromQueue <Cat>(TestQueueName, TCachePopMode.Get);

            Cat cat2 = await cache.PopFromQueue <Cat>(TestQueueName, TCachePopMode.Get);

            bool done = cat1.Name == "NotDead" && cat2.Name == "NotDead";

            // make sure the queue is empty
            Cat cat3 = await cache.PopFromQueue <Cat>(TestQueueName, TCachePopMode.Delete);

            Cat cat4 = await cache.PopFromQueue <Cat>(TestQueueName, TCachePopMode.Delete);

            if (cat3 != null)
            {
                Console.WriteLine(cat3.Name);
            }

            if (cat4 != null)
            {
                Console.WriteLine(cat4.Name);
            }

            done = done && cat3 != null && cat4 == null;

            // remove the queue
            await cache.RemoveQueue(TestQueueName);

            // result
            Assert.True(done);
        }
Ejemplo n.º 20
0
 public QueueService()
 {
     _cacheService = new TCacheService(Configuration.RedisConnection);
 }