public void Validate_AgentNoUse_ReturnForbidden(int useState, HttpStatusCode expectedCode) { //配置 IGetAgentInfoService getAgentInfoService = Substitute.For <IGetAgentInfoService>(); ICheckGetSecCode checkGetSecCode = Substitute.For <ICheckGetSecCode>(); getAgentInfoService.GetAgentModelFactory(Arg.Any <int>()).Returns(new bx_agent() { IsUsed = useState }); ValidateService validateService = new ValidateService(getAgentInfoService, checkGetSecCode); //操作 var result = validateService.Validate(new BaseRequest() { Agent = 1 }, null); //断言 Assert.AreEqual(expectedCode, result.Status); }
public void Validate_AgentCanUse_NextCalled() { //配置 IGetAgentInfoService getAgentInfoService = Substitute.For <IGetAgentInfoService>(); ICheckGetSecCode checkGetSecCode = Substitute.For <ICheckGetSecCode>(); getAgentInfoService.GetAgentModelFactory(Arg.Any <int>()).Returns(new bx_agent() { IsUsed = 1 }); ValidateService validateService = new ValidateService(getAgentInfoService, checkGetSecCode); //操作 var result = validateService.Validate(new BaseRequest() { Agent = 1 }, null); //断言 checkGetSecCode.Received().ValidateReqest(null, Arg.Any <string>(), Arg.Any <string>()); }
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); }
public ValidateService(IGetAgentInfoService getAgentInfoService, ICheckGetSecCode checkGetSecCode) { _getAgentInfoService = getAgentInfoService; _checkGetSecCode = checkGetSecCode; }