.NET Core 3.1中ChangeEmailAsync的集成测试

时间:2020-05-04 14:08:14

标签: asp.net-mvc .net-core-3.1

我正在尝试为更改EmailID编写集成测试用例。

cshtml.cs文件

var token = await _userManager.GenerateChangeEmailTokenAsync(user, Input.Email);
var changeEmailResult = await _userManager.ChangeEmailAsync(user, Input.Email, token);

[Fact]
public async Task OnPostUpdateEmailAsync_WithValidInput_ShouldReturnSuccessMessage()
{
    await _client.LoginAsync("test1@test.com", TestData.AlicePassword);

    var response = await _client.SubmitAsync("./OnPostUpdateEmailAsync", new
        {
            Email = "testemail@test.com",
            Password_ChangeEmail = "Password1"
        });

    response.AssertOnPage("./ChangeEmailPassword/UpdateEmail");
    response.EnsureSuccessStatusCode();

    var document = await response.GetDocument();
    document.QuerySelectorAll(".alert-success")
        .AssertCount(1)
        .AssertHasTextEqual(
            $"The email address has been changed successfully.");
}

[Fact]
public async Task OnPostResetPasswordAsync_WithWrongConfirmPassword_ShouldReturnErrorMessage()
{
    await _client.LoginAsync(TestData.AliceEmail, TestData.AlicePassword);

    var response = await _client.SubmitAsync("./ChangeEmailPassword/OnPostResetPasswordAsync", new
        {
            OldPassword = "OldPassword1",
            Password = "NewPassword1",
            ConfirmPassword = "NewPassword1"
        });

    response.AssertOnPage("./ChangeEmailPassword/ResetPassword");
    response.EnsureSuccessStatusCode();

    var document = await response.GetDocument();
    document.QuerySelectorAll(".alert-danger")
        .AssertCount(1)
        .AssertHasTextEqual($"Error: The passwords do not match.");
    }

它工作正常,但执行此操作后,所有其他测试用例均失败。我可以假设我们正在此处更改电子邮件ID,但对于其他人,它仍在寻找旧的电子邮件ID。可能是我在这里错了。要求大家,请帮助我。

0 个答案:

没有答案