Example #1
0
        public void PostSubmitInfo_MessageCenterIsNull_ReturnOK()
        {
            //配置
            IValidateService validateService = Substitute.For <IValidateService>();
            IMessageCenter   messageCenter   = Substitute.For <IMessageCenter>();
            IRemoveHeBaoKey  removeHeBaoKey  = Substitute.For <IRemoveHeBaoKey>();
            IPostValidate    postValidate    = Substitute.For <IPostValidate>();

            validateService.Validate(Arg.Any <PostSubmitInfoRequest>(), Arg.Any <IEnumerable <KeyValuePair <string, string> > >()).Returns(new BaseResponse()
            {
                Status = HttpStatusCode.OK
            });
            postValidate.SubmitInfoValidate(Arg.Any <PostSubmitInfoRequest>()).Returns(Tuple.Create <BaseResponse, bx_userinfo, bx_submit_info>(new BaseResponse()
            {
                Status = HttpStatusCode.OK
            }, new bx_userinfo(), new bx_submit_info()));
            removeHeBaoKey.RemoveHeBao(Arg.Any <PostSubmitInfoRequest>()).Returns(x => "test-string");
            messageCenter.SendToMessageCenter(Arg.Any <string>(), Arg.Any <string>()).Returns(x => null);
            PostSubmitInfoService postSubmitInfoService = new PostSubmitInfoService(validateService, messageCenter, removeHeBaoKey, postValidate);
            //操作
            var result = postSubmitInfoService.PostSubmitInfo(new PostSubmitInfoRequest()
            {
                Source = 1
            }, null);

            //断言
            Assert.AreEqual(HttpStatusCode.OK, result.Status);
        }
Example #2
0
        public void PostSubmitInfo_HeBaoKeyIsException_ReturnExpectationFailed()
        {
            //配置
            IValidateService validateService = Substitute.For <IValidateService>();
            IMessageCenter   messageCenter   = Substitute.For <IMessageCenter>();
            IRemoveHeBaoKey  removeHeBaoKey  = Substitute.For <IRemoveHeBaoKey>();
            IPostValidate    postValidate    = Substitute.For <IPostValidate>();

            validateService.Validate(Arg.Any <PostSubmitInfoRequest>(), Arg.Any <IEnumerable <KeyValuePair <string, string> > >()).Returns(new BaseResponse()
            {
                Status = HttpStatusCode.OK
            });
            postValidate.SubmitInfoValidate(Arg.Any <PostSubmitInfoRequest>()).Returns(Tuple.Create <BaseResponse, bx_userinfo, bx_submit_info>(new BaseResponse()
            {
                Status = HttpStatusCode.OK
            }, new bx_userinfo(), new bx_submit_info()));
            removeHeBaoKey.When(x => x.RemoveHeBao(Arg.Any <PostSubmitInfoRequest>())).Do(info =>
            {
                throw new RedisOperateException();
            });
            PostSubmitInfoService postSubmitInfoService = new PostSubmitInfoService(validateService, messageCenter, removeHeBaoKey, postValidate);
            //操作
            var result = postSubmitInfoService.PostSubmitInfo(new PostSubmitInfoRequest()
            {
                Source = 1, LicenseNo = "京", Agent = 102, CustKey = "aaaaa", RenewalCarType = 0
            }, null);

            //断言
            Assert.AreEqual(HttpStatusCode.ExpectationFailed, result.Status);
        }
Example #3
0
        public void PostSubmitInfo_SubmitInfoValidateNoPass_ReturnNotAcceptable()
        {
            //配置
            IValidateService validateService       = Substitute.For <IValidateService>();
            IMessageCenter   messageCenter         = Substitute.For <IMessageCenter>();
            IRemoveHeBaoKey  removeHeBaoKeyService = Substitute.For <IRemoveHeBaoKey>();
            IPostValidate    postValidate          = Substitute.For <IPostValidate>();

            validateService.Validate(Arg.Any <PostSubmitInfoRequest>(), Arg.Any <IEnumerable <KeyValuePair <string, string> > >()).Returns(new BaseResponse()
            {
                Status = HttpStatusCode.OK
            });
            postValidate.SubmitInfoValidate(Arg.Any <PostSubmitInfoRequest>()).Returns(Tuple.Create <BaseResponse, bx_userinfo, bx_submit_info>(new BaseResponse()
            {
                Status = HttpStatusCode.NotAcceptable
            }, null, null));
            PostSubmitInfoService postSubmitInfoService = new PostSubmitInfoService(validateService, messageCenter, removeHeBaoKeyService, postValidate);
            //操作
            var result = postSubmitInfoService.PostSubmitInfo(new PostSubmitInfoRequest(), null);

            //断言
            Assert.AreEqual(HttpStatusCode.NotAcceptable, result.Status);
        }
Example #4
0
        public PostSubmitInfoResponse PostSubmitInfo(PostSubmitInfoRequest request, IEnumerable <KeyValuePair <string, string> > pairs)
        {
            PostSubmitInfoResponse response = new PostSubmitInfoResponse();
            //校验:1基础校验
            BaseResponse baseResponse = _validateService.Validate(request, pairs);

            if (baseResponse.Status == HttpStatusCode.Forbidden)
            {
                response.Status = HttpStatusCode.Forbidden;
                return(response);
            }
            //校验2
            var validateResult = _postValidate.SubmitInfoValidate(request);

            if (validateResult.Item1.Status == HttpStatusCode.NotAcceptable)
            {
                response.Status = HttpStatusCode.NotAcceptable;
                return(response);
            }
            //实现
            //清理缓存
            string baojiaCacheKey = string.Empty;

            try
            {
                baojiaCacheKey = _removeHeBaoKey.RemoveHeBao(request);
            }
            catch (RedisOperateException exception)
            {
                response.Status = HttpStatusCode.ExpectationFailed;
                response.ErrMsg = exception.Message;
                return(response);
            }
            //中心传的商业险投保单号赋值
            string strBizNo = string.Empty;
            //中心传的商业险投保单号赋值
            string strForceNo = string.Empty;

            if (request.Source == 4 || request.Source == 1)
            {
                //人保、太保用tno
                strBizNo   = validateResult.Item3.biz_tno ?? "";
                strForceNo = validateResult.Item3.force_tno ?? "";
            }
            else
            {
                //非人保、非太保的用pno
                strBizNo   = validateResult.Item3.biz_pno ?? "";
                strForceNo = validateResult.Item3.force_pno ?? "";
            }
            //通知中心
            var msgBody = new
            {
                B_Uid          = validateResult.Item2.Id,
                Source         = SourceGroupAlgorithm.GetOldSource(request.Source),
                BiztNo         = strBizNo,
                ForcetNo       = strForceNo,
                LicenseNo      = validateResult.Item2.LicenseNo,
                NotifyCacheKey = baojiaCacheKey
            };

            //发送重新核保消息
            try
            {
                var msgbody = _messageCenter.SendToMessageCenter(msgBody.ToJson(),
                                                                 ConfigurationManager.AppSettings["MessageCenter"],
                                                                 ConfigurationManager.AppSettings["BxHeBaoAgainName"]);
            }
            catch (MessageException exception)
            {
                response.Status = HttpStatusCode.ExpectationFailed;
                response.ErrMsg = exception.Message;
                return(response);
            }
            response.Status = HttpStatusCode.OK;
            return(response);
        }