public async Task UT_Cache_RawOverrideSerializer_Async()
        {
            var raw = new RawSerializer();

            raw.SetSerializerFor <User>(u => Encoding.UTF8.GetBytes(u.Id.ToString()),
                                        b => new User()
            {
                Id = int.Parse(Encoding.UTF8.GetString(b))
            });
            var ctx = new Context(Common.Config, raw);

            Thread.Sleep(100);
            var users = await GetUsersAsync();

            string key  = "UT_Cache_RawOverrideSerializer_Async";
            string key2 = "UT_Cache_RawOverrideSerializer_Async2";

            ctx.Cache.Remove(new[] { key, key2 });
            await ctx.Cache.SetObjectAsync(key, users[0]);

            await ctx.Cache.SetHashedAsync(key2, "X", users[1]);

            var v = await ctx.Cache.GetObjectAsync <User>(key);

            var v2 = await ctx.Cache.GetHashedAsync <User>(key2, "X");

            var v3 = await ctx.Cache.GetObjectAsync <int>(key);

            Assert.AreEqual(users[0].Id, v.Id);
            Assert.AreEqual(users[1].Id, v2.Id);
            Assert.AreEqual(users[0].Id, v3);
        }
        public void UT_Cache_RawOverrideSerializer_object()
        {
            var raw = new RawSerializer();

            raw.SetSerializerFor <object>(o => Encoding.UTF8.GetBytes(o.GetHashCode().ToString()),
                                          b => int.Parse(Encoding.UTF8.GetString(b)));
            var ctx = new Context(Common.Config, raw);

            Thread.Sleep(1000);
            string key = "UT_Cache_RawOverrideSerializer_object";

            ctx.Cache.Remove(new[] { key });
            ctx.Cache.SetObject(key, this);
            var v = ctx.Cache.GetObject <int>(key);

            Assert.AreEqual(this.GetHashCode(), v);
        }
        public async Task UT_Cache_RawOverrideSerializer_object_Async()
        {
            var raw = new RawSerializer();

            raw.SetSerializerFor <object>(o => Encoding.UTF8.GetBytes(o.GetHashCode().ToString()),
                                          b => int.Parse(Encoding.UTF8.GetString(b)));
            var ctx = new Context(Common.Config, raw);

            Thread.Sleep(100);
            string key = "UT_Cache_RawOverrideSerializer_object_Async";

            ctx.Cache.Remove(new[] { key });
            User usr = new User();
            await ctx.Cache.SetObjectAsync <object>(key, usr);

            var v = await ctx.Cache.GetObjectAsync <object>(key);

            Assert.AreEqual(usr.GetHashCode(), v);
        }
 public void UT_Cache_RawOverrideSerializer()
 {
     var raw = new RawSerializer();
     raw.SetSerializerFor<User>(u => Encoding.UTF8.GetBytes(u.Id.ToString()),
         b => new User() {Id = int.Parse(Encoding.UTF8.GetString(b))});
     var ctx = new Context(Common.Config, raw);
     Thread.Sleep(1000);
     var users = GetUsers();
     string key = "UT_Cache_RawOverrideSerializer";
     string key2 = "UT_Cache_RawOverrideSerializer2";
     ctx.Cache.Remove(new[] {key, key2});
     ctx.Cache.SetObject(key, users[0]);
     ctx.Cache.SetHashed(key2, "X", users[1]);
     var v = ctx.Cache.GetObject<User>(key);
     var v2 = ctx.Cache.GetHashed<User>(key2, "X");
     var v3 = ctx.Cache.GetObject<int>(key);
     Assert.AreEqual(users[0].Id, v.Id);
     Assert.AreEqual(users[1].Id, v2.Id);
     Assert.AreEqual(users[0].Id, v3);
 }
 public void UT_Cache_RawOverrideSerializer_object()
 {
     var raw = new RawSerializer();
     raw.SetSerializerFor<object>(o => Encoding.UTF8.GetBytes(o.GetHashCode().ToString()),
         b => int.Parse(Encoding.UTF8.GetString(b)));
     var ctx = new Context(Common.Config, raw);
     Thread.Sleep(1000);
     string key = "UT_Cache_RawOverrideSerializer_object";
     ctx.Cache.Remove(new[] { key });
     User usr = new User();
     ctx.Cache.SetObject<object>(key, usr);
     var v = ctx.Cache.GetObject<object>(key);
     Assert.AreEqual(usr.GetHashCode(), v);
 }