Example #1
0
        public void Validate_SecCodeNoPass_ReturnFalse(bool useState, HttpStatusCode expectedCode)
        {
            //配置
            IGetAgentInfoService getAgentInfoService = Substitute.For <IGetAgentInfoService>();
            ICheckGetSecCode     checkGetSecCode     = Substitute.For <ICheckGetSecCode>();

            getAgentInfoService.GetAgentModelFactory(Arg.Any <int>()).Returns(new bx_agent()
            {
                IsUsed = 1
            });
            checkGetSecCode.ValidateReqest(null, Arg.Any <string>(), Arg.Any <string>()).Returns(useState);

            ValidateService validateService = new ValidateService(getAgentInfoService, checkGetSecCode);

            //操作
            var result = validateService.Validate(new BaseRequest()
            {
                Agent = 1
            }, null);

            //断言
            Assert.AreEqual(expectedCode, result.Status);
        }
Example #2
0
        public BaseResponse Validate(BaseRequest request, IEnumerable <KeyValuePair <string, string> > pairs)
        {
            BaseResponse response   = new BaseResponse();
            IBxAgent     agentModel = _getAgentInfoService.GetAgentModelFactory(request.Agent);

            if (!agentModel.AgentCanUse())
            {
                response.Status = HttpStatusCode.Forbidden;
                if (agentModel.endDate.HasValue && agentModel.endDate.Value < DateTime.Now)
                {
                    response.ErrMsg = string.Format("参数校验错误,账号已过期。过期时间为:{0}", agentModel.endDate.Value.ToString("yyyy-MM-dd HH:mm:ss"));
                    return(response);
                }
                response.ErrMsg = "参数校验错误,账号已禁用。";
                return(response);
            }
            if (!_checkGetSecCode.ValidateReqest(pairs, agentModel.SecretKey, request.SecCode))
            {
                response.Status = HttpStatusCode.Forbidden;
                response.ErrMsg = "参数校验错误,SecCode校验出错。";
                return(response);
            }
            return(response);
        }