jeudi 25 juin 2015

Unit Test - Invalid Operation Exception

My Unit Test is returning an error stating: System.InvalidOperationException: Sequence contains no matching element.

When I start debugging, it automatically stops my debugger after hitting var result = _forgotPass.SendEmail(...); Why is it throwing this exception and how can I fix this issue?

Error: System.InvalidOperationException: Sequence contains no matching element.

Unit Test:

[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"));
}

Aucun commentaire:

Enregistrer un commentaire