public async Task Allinpay_ExecPayNotifyAsync_Test() { //Mock HttpRequest var httpRequestMock = Substitute.For <HttpRequest>(); //伪造支付参数 var dic = new Dictionary <string, string>() { { "acct", "ouiSX5NVuuNgcwRchQf - q4cK_vG4" }, { "appid", configuration["Allinpay:AppId"] }, { "chnlid", "213186760" }, { "chnltrxid", "4200000447201910244661192735" }, { "cmid", "305235533" }, { "cusid", configuration["Allinpay:CusId"] }, { "cusorderid", "ouiSX5NVuuNgcwRchQf - q4cK_vG4" }, { "fee", "0" }, //外部交易单号 { "outtrxid", outTradeNo }, { "paytime", DateTime.Now.ToString("yyyyMMddHHmmss") }, { "signtype", "MD5" }, { "termauthno", "CFT" }, { "termrefnum", "4200000447201910244661192735" }, { "termtraceno", "0" }, //金额 { "trxamt", "1" }, { "trxcode", "VSP501" }, { "trxdate", "20191024" }, { "trxid", "121964420000012121" }, { "trxreserved", "缴费支付" }, { "trxstatus", "0000" }, }; //制造签名 var sign = AllinpayUtil.SignParam(dic, configuration["Allinpay:AppKey"]); dic.Add("sign", sign); dic.Remove("key"); //Mock HttpRequest 的表单参数 var formDic = dic.ToDictionary(item => item.Key, item => new Microsoft.Extensions.Primitives.StringValues(item.Value)); httpRequestMock.Form.Returns(new FormCollection(formDic, null)); //执行支付回调 await paymentManager.ExecPayNotifyAsync(new PayNotifyInput() { Provider = "allinpay", Request = httpRequestMock }); //验证交易日志 UsingDbContext(context => { context.TransactionLogs.First(p => p.OutTradeNo == outTradeNo).TransactionState.ShouldBe(TransactionStates.Success); context.TransactionLogs.First(p => p.OutTradeNo == outTradeNo).PayTime.HasValue.ShouldBeTrue(); context.TransactionLogs.First(p => p.OutTradeNo == outTradeNo).Exception.ShouldBeNull(); }); }