public void GetCacheChannelList_ConfigsHasMany_ReturnsList() { IHashOperator hashOperator = Substitute.For <IHashOperator>(); hashOperator.Get <CacheChannelModel>(Arg.Any <string>(), Arg.Any <string>()).Returns(x => new CacheChannelModel()); ChannelModelMapRedisService channelModelMapRedisService = new ChannelModelMapRedisService(hashOperator); List <bx_agent_config> list = new List <bx_agent_config>() { new bx_agent_config() { isurl = 1, bx_url = "aaa" }, new bx_agent_config() { isurl = 1, bx_url = "bbb" }, new bx_agent_config() { isurl = 1, bx_url = "ccc" } }; var result = channelModelMapRedisService.GetCacheChannelList(list); hashOperator.Received(3).Get <CacheChannelModel>(Arg.Any <string>(), Arg.Any <string>()); }
public List <CacheChannelModel> GetCacheChannelList(List <bx_agent_config> configs) { var list = new List <CacheChannelModel>(); CacheChannelModel model; //取哈希值的单条key,是配置表里的url作为key来取值的 string redisUrlKey = string.Empty; foreach (var item in configs) { //获取渠道配置url redisUrlKey = item.isurl == 1 ? item.bx_url : item.macurl; //获取单个渠道状态的模型 model = new CacheChannelModel(); if (!string.IsNullOrEmpty(redisUrlKey)) { model = _hashOperator.Get <CacheChannelModel>(_hashKey, redisUrlKey); if (model != null) { list.Add(model); } } } return(list); }
public void GetCacheChannelList_HashNotNull_ReturnsTrue() { IHashOperator hashOperator = Substitute.For <IHashOperator>(); hashOperator.Get <CacheChannelModel>(Arg.Any <string>(), Arg.Any <string>()).Returns(x => new CacheChannelModel()); ChannelModelMapRedisService channelModelMapRedisService = new ChannelModelMapRedisService(hashOperator); var result = channelModelMapRedisService.GetCacheChannelList(new List <bx_agent_config>() { new bx_agent_config() { isurl = 1, bx_url = "aaa" } }); Assert.AreEqual(true, result.Any()); }