NUnit と NMock2 を使用して、同じ SqlParameters だと思っていたものを比較できませんでした。
SqlParameter param1 = new SqlParameter("@Id", 1);
SqlParameter param2 = new SqlParameter("@Id", 1);
Assert.IsTrue(param1.Equals(param2)); // This failed
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();
}
私はこのエラーを受け取りました:
NMock2.Internal.ExpectationException: sqlDao.ExecuteNonQuery("usp_Update_Comment", ) の予期しない呼び出し 予想: 1 回: sqlDao.ExecuteNonQuery("usp_Update_Comment" と等しい、<@ChangeId> と等しい) [0 回呼び出された]
質問:
- パラメータがSqlParameterであると予想した場合、NMock2でどのようにテストしますか?
- 2 つの SqlParameters の等価性をどのように比較しますか?