public void integration_test_for_user_upload_info() { var namevalues = new NameValueCollection(); namevalues[MobileParam.Key_IMSI] = TEST_IMSI; _requestRepoMock.Setup<NameValueCollection>(m => m.Header).Returns(namevalues); MobileParam mobileParam = new MobileParam(requestRepo); var realRedisService = new RedisService(); var realRedisLogger = new RedisLogger(); realRedisService.FlushAll(); realRedisLogger.Flush(); UserInteractService userInteractService = new UserInteractService(realRedisLogger, realRedisService, new UserInteractUIService(realRedisService)); //first time , add UserUploadInfo userUploadInfo = new UserUploadInfo { ActivityInfos = GetAndroidUserAppActivityInfos(), AppInfos = GetAppInfos(), AppTrafficInfos = GetAppTrafficInfos() }; userInteractService.SaveUserUploadInfos(mobileParam, userUploadInfo); //second time , update namevalues = new NameValueCollection(); namevalues[MobileParam.Key_IMSI] = TEST_IMSI; namevalues[MobileParam.Key_IsTouch] = "1"; _requestRepoMock.Setup<NameValueCollection>(m => m.Header).Returns(namevalues); mobileParam = new MobileParam(requestRepo); userInteractService.SaveUserUploadInfos(mobileParam, userUploadInfo); Assert.NotNull(realRedisService.GetValueFromHash<string>("U:9460002850533220", "com.packagename.app1")); using (var redis = RedisClientManager.GetReadOnlyClient()) { Assert.Equal(2, redis.GetListCount("Queue:AndroidUserUploadInfo:Logger")); var secondAndroidUserUploadInfo = JsonConvert.DeserializeObject<LogModel>(redis.GetItemFromList("Queue:AndroidUserUploadInfo:Logger", 1)); Assert.Equal(LogOperationType.Update, secondAndroidUserUploadInfo.Operation); Assert.Equal(6, redis.GetListCount("Queue:AndroidUserAppInfo:Logger")); Assert.Equal(4, redis.GetListCount("Queue:AndroidUserAppTrafficInfo:AndroidUserAppTrafficInfoLogger")); Assert.Equal(4, redis.GetListCount("Queue:AndroidUserAppActivityInfo:AndroidUserAppActivityInfoLogger")); } }
public void parse_client_upload_json_to_proper_entity() { string json = "{\"apps\":[{\"pkg\":\"com.tyd.weather\",\"ver\":\"21\",\"vername\":\"1.2.1\",\"md5\":\"5454212125454asfda3\",\"action\":0},{\"pkg\":\"com.tyd.music\",\"ver\":\"21\",\"vername\":\"2.2.1\",\"md5\":\"jdlfjalj459895894\",\"action\":0}],\"traffics\":[{\"pkg\":\"com.tyd.weather\",\"traffic\":10024},{\"pkg\":\"com.tyd.music\",\"traffic\":23232}],\"activities\":[{\"pkg\":\"com.tyd.weather\",\"times\":\"0|0|0|0|0|0|0|0|0|0|22|3|3|0|2|2|2|2|2|2|2|0|0|0\"},{\"pkg\":\"com.tyd.music\",\"times\":\"0|0|0|0|0|0|0|0|0|0|22|3|3|0|2|2|2|2|2|2|2|0|0|0\"}],\"from\":\"2012-05-13T00:00:00+08:00\",\"to\":\"2012-05-15T00:00:00+08:00\"}"; ClientData clientData = JsonConvert.DeserializeObject<ClientData>(json); var realRedisService = new RedisService(); var realRedisLogger = new RedisLogger(); UserInteractService userInteractService = new UserInteractService(realRedisLogger, realRedisService, new UserInteractUIService(realRedisService)); var userUploadInfo = userInteractService.GetUserUploadInfo(clientData, TEST_IMSI); Assert.Equal(2, userUploadInfo.ActivityInfos.Count); Assert.Equal(22, userUploadInfo.ActivityInfos[0].Eleven); Assert.Equal(2, userUploadInfo.AppInfos.Count); Assert.Equal("5454212125454asfda3", userUploadInfo.AppInfos[0].AndroidUserAppInfo.MD5); Assert.Equal(2, userUploadInfo.AppTrafficInfos.Count); Assert.Equal(10024, userUploadInfo.AppTrafficInfos[0].Traffic); }