public async Task LoginTest() { var client = factory.Create(mock => { //拦截服务端请求微信api的请求 mock.When("https://api.weixin.qq.com/sns/jscode2session").Respond("application/json", "{\"session_key\":\"Pw2PbhyOuHiuz7W4QfimKw== \",\"openid\":\"oxihd5c4EBDVEUNCLRJhvkS6l1Xg\"}"); }); var actual = await client.GetStringAsync("/api/account/login/abcdef"); Assert.NotEqual("", actual); }
public ThermometerControllerTest(TestWebApplicationFactory <Startup> factory) { client = factory.Create(mock => { //拦截服务端请求微信api的请求 mock.When("https://api.weixin.qq.com/sns/jscode2session").Respond("application/json", "{\"session_key\":\"Pw2PbhyOuHiuz7W4QfimKw== \",\"openid\":\"oxihd5c4EBDVEUNCLRJhvkS6l1Xg\"}"); }); var json = client.GetStringAsync("/api/account/login/abcdef").Result; var actual = new { Session = string.Empty }; actual = JsonConvert.DeserializeAnonymousType(json, actual); session = actual.Session; }