public void Can_store_as_Hash()
        {
            var dto = new HashTest {
                Id = 1
            };

            Redis.StoreAsHash(dto);

            var storedHash = Redis.GetHashKeys(dto.ToUrn());

            Assert.That(storedHash, Is.EquivalentTo(new[] { "Id" }));

            var hold = RedisClient.ConvertToHashFn;

            RedisClient.ConvertToHashFn = o =>
            {
                var map = new Dictionary <string, string>();
                o.ToObjectDictionary().Each(x => map[x.Key] = (x.Value ?? "").ToJsv());
                return(map);
            };

            Redis.StoreAsHash(dto);
            storedHash = Redis.GetHashKeys(dto.ToUrn());
            Assert.That(storedHash, Is.EquivalentTo(new[] { "Id", "Name" }));

            RedisClient.ConvertToHashFn = hold;
        }
Exemple #2
0
        public void Can_store_as_Hash()
        {
            var dto = new HashTest {
                Id = 1
            };

            this.Redis.StoreAsHash(dto);

            var storedHash = this.Redis.GetHashKeys(dto.ToUrn());

            Assert.That(storedHash, Is.EquivalentTo(new[] { "Id" }));

            var hold = RedisClient.ConvertToHashFn;

            RedisClient.ConvertToHashFn = o => {
                var dictionary = JObject.FromObject(o).ToObject <Dictionary <string, string> >();
                var dict       = new Dictionary <string, string>();
                foreach (var pair in dictionary)
                {
                    dict[pair.Key] = pair.Value ?? "";
                }

                return(dict);
            };

            this.Redis.StoreAsHash(dto);
            storedHash = this.Redis.GetHashKeys(dto.ToUrn());
            Assert.That(storedHash, Is.EquivalentTo(new[] { "Id", "Name" }));

            RedisClient.ConvertToHashFn = hold;
        }
        public void Can_store_as_Hash()
        {
            var dto = new HashTest { Id = 1 };
            Redis.StoreAsHash(dto);

            var storedHash = Redis.GetHashKeys(dto.ToUrn());
            Assert.That(storedHash, Is.EquivalentTo(new[] { "Id" }));

            var hold = RedisClient.ConvertToHashFn;
            RedisClient.ConvertToHashFn = o =>
            {
                var map = new Dictionary<string, string>();
                o.ToObjectDictionary().Each(x => map[x.Key] = (x.Value ?? "").ToJsv());
                return map;
            };

            Redis.StoreAsHash(dto);
            storedHash = Redis.GetHashKeys(dto.ToUrn());
            Assert.That(storedHash, Is.EquivalentTo(new[] { "Id", "Name" }));

            RedisClient.ConvertToHashFn = hold;
        }