public TCacheGetTests() { using (TCacheService cache = new TCacheService()) { bool cleaned = cache.RemoveKey(TestQueueName).Result&& cache.RemoveKey(TestQueueNameSecond).Result; } }
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); } } }
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); } } }
public TCacheCreatePushTests() { using (TCacheService cache = new TCacheService()) { bool cleaned = cache.RemoveKey(TestQueueName).Result; } }
public async Task RemoveKeyNoKey() { using (TCacheService cache = new TCacheService(TestConfiguration.EnvRedisUri)) { bool result = await cache.RemoveKey("blah blah blah"); Assert.True(result); } }
public async Task GetEmptyNoTypeQueue() { using (TCacheService cache = new TCacheService(TestConfiguration.EnvRedisUri)) { string noCat = await cache.PopFromQueue(TestQueueNameEmpty); Assert.Null(noCat); } }
public async Task GetEmptyTypesValue() { using (TCacheService cache = new TCacheService(TestConfiguration.EnvRedisUri)) { Cat value = await cache.GetValueFromKey <Cat>("test4"); Assert.Null(value); } }
public async Task RemoveQueue() { using (TCacheService cache = new TCacheService(TestConfiguration.EnvRedisUri)) { await cache.RemoveKey(TestQueueName); bool exists = await cache.QueueExists(TestQueueName); Assert.False(exists); } }
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); }
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)); }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } } }
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); }
public QueueService() { _cacheService = new TCacheService(Configuration.RedisConnection); }