Exemplo n.º 1
0
        /// <summary>
        /// 检测删除脏数据是否成功
        /// </summary>
        public void TestCheckDeleteBadDataIsSuccessfully()
        {
            //准备环境
            IEnumerable <SignPointActivityDto> actIdList =
                _signPointActivityRepository.Query <SignPointActivityDto>("select top  20  *  from  SignPointActivity");

            actIdList.ShouldNotBeNull();
            actIdList.Any().ShouldBe(true);
            //
            foreach (var act in actIdList)
            {
                _actuatorAppService.StartWorkFor(act.Id);
                _redisHelper.StringSet(SUCCESSACTIDQUEUEKEY, act.Id.ToString(), 60 * 60 * 24 * 3);
            }

            var rid = actIdList.ToList().GetRange(16, 1).FirstOrDefault().Id;

            //强制缓存在17条的位置停止
            _redisHelper.StringSet(SUCCESSACTIDQUEUEKEY, rid.ToString(), 60 * 60 * 24 * 3);

            //执行返回现场
            _actuatorAppService.BackToLastExport();


            //mongodb为缓存中最终添加的记录
            int mongoDbId = _signActivityRepository.Queryable().Max(t => t.RowId);

            mongoDbId.ShouldBe(rid);


            //MongoDb中没有相关记录
            IEnumerable <SignPointActivityDto> actList =
                _signPointActivityRepository.Query <SignPointActivityDto>(
                    "select top  3  *  from  SignPointActivity where id>@id", new { id = rid });

            foreach (var actItem in actList)
            {
                //活动数据不存在
                var actMongo = _signActivityRepository.FirstOrDefault(actItem.ActID.ToString());
                actMongo.ShouldBeNull();

                //用户数据不存在
                IEnumerable <string> openIdList = _signRecordsRepository
                                                  .Query <string>("select distinct  openid  from   SignRecords where  ActivityID=@actID ",
                                                                  new { actID = actItem.Id });
                foreach (var openId in openIdList)
                {
                    //活动数据不存在
                    UserSignActivity actMongoTemp =
                        _userSignActRepositoryMongo.FirstOrDefault(UserSignActivity.GetId(openId,
                                                                                          actItem.ActID.ToString()));
                    actMongoTemp.ShouldBeNull();
                }
            }

            var rids   = actIdList.Select(x => x.Id);
            var actids = actIdList.Select(x => x.ActID.ToString());

            //清理测试数据
            foreach (var act in actIdList)
            {
                _actuatorAppService.DeleteActData(act.Id, act.ActID.ToString());
            }
            //检测活动数据是否清除成功
            _signActivityRepository.Count(x => rids.Contains(x.RowId)).ShouldBe(0);
            _userSignActRepositoryMongo.Count(x => actids.Contains(x.ActivityId));
        }
Exemplo n.º 2
0
        public void IsSuccessSecondExport()
        {
            //准备环境
            IEnumerable <SignPointActivityDto> actIdList =
                _signPointActivityRepository.Query <SignPointActivityDto>("select top  20  *  from  SignPointActivity");

            actIdList.ShouldNotBeNull();
            actIdList.Any().ShouldBe(true);
            foreach (var act in actIdList)
            {
                _actuatorAppService.StartWorkFor(act.Id);
                _redisHelper.StringSet(SUCCESSACTIDQUEUEKEY, act.Id.ToString(), 60 * 60 * 24 * 3);
            }

            var entity = actIdList.ToList().GetRange(16, 1).FirstOrDefault();

            _redisHelper.StringSet(SUCCESSACTIDQUEUEKEY, entity.Id.ToString(), 60 * 60 * 24 * 3);

            var watch = new Stopwatch();

            watch.Start();

            //返回现场
            _actuatorAppService.ExcuteWorker(actIdList.Select(x => x.Id));

            //检测数据条目有没有跟数据库条目一致


            string actStr = _redisHelper.StringGet(SUCCESSACTIDQUEUEKEY);
            int    actId  = 0;

            if (!string.IsNullOrEmpty(actStr))
            {
                actId = Convert.ToInt32(actStr);
            }

            //缓存中的ID为最终添加的记录
            int mongoDbId = _signActivityRepository.Queryable().Max(t => t.RowId);

            actId.ShouldBe(actIdList.Max(t => t.Id));
            mongoDbId.ShouldBe(actId);


            //MongoDb中没有相关记录
            IEnumerable <SignPointActivityDto> actList =
                _signPointActivityRepository.Query <SignPointActivityDto>(
                    "select top  2  *  from  SignPointActivity where id>@id", new { id = actId });

            foreach (var actItem in actList)
            {
                //活动数据不存在
                var actMongo = _signActivityRepository.FirstOrDefault(actItem.ActID.ToString());
                actMongo.ShouldBeNull();

                //用户数据不存在
                IEnumerable <string> openIdList = _signRecordsRepository
                                                  .Query <string>("select distinct  openid  from   SignRecords where  ActivityID=@actID ",
                                                                  new { actID = actItem.Id });
                foreach (var openId in openIdList)
                {
                    //活动数据不存在
                    UserSignActivity actMongoTemp =
                        _userSignActRepositoryMongo.FirstOrDefault(UserSignActivity.GetId(openId,
                                                                                          actItem.ActID.ToString()));
                    actMongoTemp.ShouldBeNull();
                }
            }

            //清理测试数据
            foreach (var act in actIdList)
            {
                _actuatorAppService.DeleteActData(act.Id, act.ActID.ToString());
            }

            //重置缓存
            _redisHelper.StringSet(SUCCESSACTIDQUEUEKEY, "0", 60 * 60 * 24 * 3);
            watch.Stop();
            watch.ElapsedMilliseconds.ShouldBeLessThan(10000);
        }