Using NUnit and NMock2, I could not compare what I thought was the same SqlParameters:
SqlParameter param1 = new SqlParameter("@Id", 1);
SqlParameter param2 = new SqlParameter("@Id", 1);
Assert.IsTrue(param1.Equals(param2));
I came across this problem while trying to test method execution using NMock2
[Test]
public void UpdateComments()
{
const int arbitraryId = 1;
Comment comment = new Comment();
SqlParameter idParam = new SqlParameter("@ChangeId", arbitraryId);
Expect.Once.On(mockSqlDao).Method("ExecuteNonQuery")
.With("usp_Update_Comment", idParam);
changeDao.UpdateComment(arbitraryId, comment);
mocks.VerifyAllExpectationsHaveBeenMet();
}
I got this error:
NMock2.Internal.ExpectationException: unexpected call to sqlDao.ExecuteNonQuery ("usp_Update_Comment",) Expected: 1 time: sqlDao.ExecuteNonQuery (equal to "usp_Update_Comment", equal to <@ChangeId>) [called 0 times]
Questions:
- How do you test with NMock2 when you expected parameter SqlParameter?
- How do you compare the equality of two SqlParameters?
source
share