Exemplo n.º 1
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);
                }
            }
        }
Exemplo 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);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create a new user
        /// </summary>
        /// <param name="user"><see cref="CreateUser"/> required information to create a user</param>
        /// <returns></returns>
        public async Task <User> CreateUser(CreateUser user)
        {
            if (string.IsNullOrEmpty(user.DisplayName))
            {
                throw new ArgumentException("You must provide a display name!");
            }

            var(Hashed, Plaintext) = await CreateAndHashPassword();

            User newUser = new User
            {
                _Id           = Guid.NewGuid(),
                DisplayName   = user.DisplayName.Trim(),
                Password      = Hashed,
                LoginAttempts = 0,
                Locked        = false
            };

            await _cacheService.SetObjectAsKeyValue(_userPrefix + newUser._Id.ToString(), newUser);

            // temp assignment of password
            newUser.Password = Plaintext;

            return(newUser);
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 6
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);
                }
            }
        }
Exemplo n.º 7
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);
            }
        }
Exemplo n.º 8
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);
            }
        }
Exemplo n.º 9
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);
            }
        }
Exemplo n.º 10
0
 public async Task <bool> SetKey(string keyName, object value)
 {
     return(await _cacheService.SetObjectAsKeyValue(keyName, value));
 }