单元测试 - 无效的操作异常

时间:2015-06-25 15:36:40

标签: c# asp.net unit-testing

我的 单元测试 返回错误说明:System.InvalidOperationException: Sequence contains no matching element.

当我开始调试时,它会在点击var result = _forgotPass.SendEmail(...);之后自动停止调试器。为什么它会抛出此异常 以及如何解决这个问题?

错误: System.InvalidOperationException: Sequence contains no matching element.

单元测试:

[TestMethod]
public void SendEmail()
{
    //Arrange
    _getUrl.Setup(mock => mock.AddUrlLink(It.IsAny<string>())).Returns(new ApiResponse<Status, string>(Status.Success, "link"));
    _emailMock.Setup(mock => mock.Send(It.IsAny<CarrierModel>())).Returns(new ApiResponse<bool, string>(false, ""));

    //Act
    var result = _forgotPass.SendEmail("myemail@gmail.com");

    //Assert
    Assert.AreEqual(Status.EmailFailed, result.Status);
    Assert.IsNull(result.Body);
    Assert.IsTrue(result.Messages.Any(m => m == "Email Failed"));
}

0 个答案:

没有答案