Beetle.Redis的List和MapSet对象

List
[TestMethod]
        public void LST_POP_PUSH()
        {
            ProtobufList<UserBase> lst = new Redis.ProtobufList<UserBase>("USERS");
            lst.Push(new UserBase { Name = "henry", Age = 18, City = "gz", Counrty = "cn" });
            Assert.AreEqual("henry", lst.Pop().Name);
        }
        [TestMethod]
        public void LST_REMOVE_ADD()
        {
            ProtobufList<UserBase> lst = new Redis.ProtobufList<UserBase>("USERS");
            lst.Add(new UserBase { Name = "henry", Age = 18, City = "gz", Counrty = "cn" });
            lst.Add(new UserBase { Name = "bbq", Age = 18, City = "gz", Counrty = "cn" });
            Assert.AreEqual("bbq", lst.Remove().Name);
        }
        [TestMethod]
        public void LST_Length()
        {
            ProtobufList<UserBase> lst = new Redis.ProtobufList<UserBase>("USERS");
            lst.Clear();
            lst.Add(new UserBase { Name = "henry", Age = 18, City = "gz", Counrty = "cn" });
            lst.Add(new UserBase { Name = "bbq", Age = 18, City = "gz", Counrty = "cn" });
            Assert.AreEqual(lst.Count(), 2);
        }
        [TestMethod]
        public void LST_Region()
        {
            ProtobufList<UserBase> lst = new Redis.ProtobufList<UserBase>("USERS");
            lst.Clear();
            for (int i = 0; i < 10; i++)
            {
                lst.Add(new UserBase { Name = "henry" + i, Age = 18, City = "gz", Counrty = "cn" });
            }
            IList<UserBase> items = lst.Range();
            Assert.AreEqual(items[0].Name, "henry0");
            Assert.AreEqual(items[9].Name, "henry9");
            items = lst.Range(5, 7);
            Assert.AreEqual(items[0].Name, "henry5");
            Assert.AreEqual(items[2].Name, "henry7");
        }
MapSet
[TestMethod]
        public void MapSet()
        {

            JsonMapSet map = new Redis.JsonMapSet("HENRY_INFO");
            UserBase ub = new UserBase();
            ub.Name = "henryfan";
            ub.City = "gz";
            ub.Counrty = "cn";
            ub.Age = 10;
            Contact contact = new Contact();
            contact.EMail = "hernyfan@msn.com";
            contact.QQ = "28304340";
            contact.Phone = "13660223497";
            map.Set(ub, contact);
            IList<object> data = map.Get<UserBase, Contact>();
            Assert.AreEqual(ub.Name, ((UserBase)data[0]).Name);
            Assert.AreEqual(contact.Phone, ((Contact)data[1]).Phone);

        }
        [TestMethod]
        public void MapSetdRemove()
        {
            JsonMapSet map = new JsonMapSet("HENRY_INFO");
            UserBase ub = new UserBase();
            ub.Name = "henryfan";
            ub.City = "gz";
            ub.Counrty = "cn";
            ub.Age = 10;
            Contact contact = new Contact();
            contact.EMail = "hernyfan@msn.com";
            contact.QQ = "28304340";
            contact.Phone = "13660223497";
            map.Set(ub, contact);
            map.Remove<Contact>();
            contact = map.Get<Contact>();
            Assert.AreEqual(null, contact);

        }
        [TestMethod]
        public void MapSetClear()
        {
            JsonMapSet map = new JsonMapSet("HENRY_INFO");
            UserBase ub = new UserBase();
            ub.Name = "henryfan";
            ub.City = "gz";
            ub.Counrty = "cn";
            ub.Age = 10;
            Contact contact = new Contact();
            contact.EMail = "hernyfan@msn.com";
            contact.QQ = "28304340";
            contact.Phone = "13660223497";
            map.Set(ub, contact);
            map.Clear();
            IList<object> data = map.Get<UserBase, Contact>();
            Assert.AreEqual(null, data[0]);
            Assert.AreEqual(null, data[1]);
        }


转载于:https://my.oschina.net/ikende/blog/157698

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值