2
我是Moq的新手,需要知道我是否正確執行此操作。Moq和DataContext
在AccountController.cs我有這樣的:
int id = _userRepository.GetProfileFromUserName(userName).ProfileID;
UserRepository被嘲笑,但簡檔來自DataContext的,所以我在 AccountControllerTests.cs這樣做:
mockUserReposository.Setup(gp => gp.GetProfileFromUserName(userName)).Returns(new Profile { ProfileID = 1 });
這樣我獲取id變量等於1,並確保ProfileID在AccountController.cs中調用時不使用DataContext中的一個。
這是正確的做法嗎?或者我不知何故需要從Linq到SQL模擬整個Profile表?