public void TestPasswords() { var email = Email; var password = Password; var accountModel = new AccountModel { UserName = email, Password = NewPassword }; var token = GetToken(accountModel); var pass = NewPassword;//"test@123B";// var client = GetClient(); client.DefaultRequestHeaders.Add("Authorization", token.TokenType + " " + token.AccessToken); var changePassModel = new ChangePasswordModel { OldPassword = NewPassword, NewPassword = pass, ConfirmPassword = pass }; var cRes = client.PostAsJsonAsync(routPrefix+"/ChangePassword", changePassModel).Result; var content = cRes.Content.ReadAsStringAsync().Result; Assert.AreEqual(HttpStatusCode.OK, cRes.StatusCode); // If password has been setted, will throw exception // {"Message":"请求无效。","ModelState":{"":["已为用户设置了密码。"]}} token = GetToken(new AccountModel {UserName = Email, Password = pass}); client.DefaultRequestHeaders.Remove("Authorization"); client.DefaultRequestHeaders.Add("Authorization", token.TokenType + " " + token.AccessToken); var setPassModel = new SetPasswordModel { NewPassword = password, ConfirmPassword = password }; var sRes = client.PostAsJsonAsync(routPrefix+"/SetPassword", setPassModel).Result; var sContent = sRes.Content.ReadAsStringAsync().Result; Assert.AreEqual(HttpStatusCode.BadRequest, sRes.StatusCode); }
public void TestPasswords() { var email = Email; var password = Password; var accountModel = new AccountModel { UserName = email, Password = NewPassword }; var token = GetToken(accountModel); var pass = NewPassword;//"test@123B";// var client = GetClient(); client.DefaultRequestHeaders.Add("Authorization", token.TokenType + " " + token.AccessToken); var changePassModel = new ChangePasswordModel { OldPassword = NewPassword, NewPassword = pass, ConfirmPassword = pass }; var cRes = client.PostAsJsonAsync(routPrefix + "/ChangePassword", changePassModel).Result; var content = cRes.Content.ReadAsStringAsync().Result; Assert.AreEqual(HttpStatusCode.OK, cRes.StatusCode); // If password has been setted, will throw exception // {"Message":"请求无效。","ModelState":{"":["已为用户设置了密码。"]}} token = GetToken(new AccountModel { UserName = Email, Password = pass }); client.DefaultRequestHeaders.Remove("Authorization"); client.DefaultRequestHeaders.Add("Authorization", token.TokenType + " " + token.AccessToken); var setPassModel = new SetPasswordModel { NewPassword = password, ConfirmPassword = password }; var sRes = client.PostAsJsonAsync(routPrefix + "/SetPassword", setPassModel).Result; var sContent = sRes.Content.ReadAsStringAsync().Result; Assert.AreEqual(HttpStatusCode.BadRequest, sRes.StatusCode); }