public void DefaultSerialize() {
            var person = new Person {
                Id = 2,
                Name = "Rattz",
                Address = new Address {
                    Line1 = "Haidin Shuzhoujie",
                    Line2 = "Beijing China"
                }
            };

            var serializeObject = typeof(DefaultTranscoder).GetMethod("SerializeObject", BindingFlags.Instance | BindingFlags.NonPublic);
            Assert.IsNotNull(serializeObject);
            var buffer = (ArraySegment<Byte>)serializeObject.Invoke(new DefaultTranscoder(), new Object[] { person });

            var deserializeObject = typeof(NewtonsoftJsonTranscoder).GetMethod("DeserializeObject", BindingFlags.Instance | BindingFlags.NonPublic);
            Assert.IsNotNull(serializeObject);
            var binary = deserializeObject.Invoke(new NewtonsoftJsonTranscoder(), new Object[] { buffer });
            Assert.IsTrue(binary is Person);
        }
Ejemplo n.º 2
0
        public void Online() {
            using (MemcachedClient client = new MemcachedClient("enyim.com/memcached")) {
                String key = Guid.NewGuid().ToString("n");
                Object value = client.Get(key);
                Assert.IsNull(value);

                var exist = client.TryGet(key, out value);
                Assert.IsFalse(exist);
                Assert.IsNull(value);

                value = new Person {
                    Id = 2,
                    Name = "Rattz",
                    Address = new Address {
                        Line1 = "Haidin Shuzhoujie",
                        Line2 = "Beijing China"
                    }
                };
                client.Store(StoreMode.Set, key, value);
                exist = client.TryGet(key, out value);
                Assert.IsTrue(exist);
                Assert.IsNotNull(value);
            }
        }
Ejemplo n.º 3
0
        public void Compatibility2() {
            var cache = new MemcachedCacheProvider("Test");
            var person = new Person {
                Id = 2,
                Name = "Rattz",
                Address = new Address {
                    Line1 = "Haidin Shuzhoujie",
                    Line2 = "Beijing China"
                }
            };

            var key = "Person";
            cache.Overwrite(key, person, TimeSpan.FromHours(1D));
            Person personOut;
            var exist = cache.TryGet<Person>(key, out personOut);
            Assert.IsTrue(exist);
            Assert.IsNotNull(personOut);
        }