我正在寫一個自定義配置文件提供程序,但我仍然打算使用默認的AspNetSqlMembershipProvider作爲我的會員提供程序。在我的個人資料提供我GetAllProfiles()方法是這樣的:嘲笑會員
1 public override ProfileInfoCollection GetAllProfiles(ProfileAuthenticationOption authenticationOption, int pageIndex, int pageSize, out int totalRecords)
2 {
3 // Get the profiles
4 IQueryable<Profile> profiles = _profileRepository.GetAllProfiles();
5
6 // Convert to a ProfileInfoCollection
7 ProfileInfoCollection profileInfoCollection = new ProfileInfoCollection();
8 foreach (Profile profile in profiles)
9 {
10 MembershipUser user = Membership.GetUser(profile.UserId);
11
12 string username = user.UserName;
13 bool isAnonymous = false;
14 DateTime lastActivity = user.LastActivityDate;
15 DateTime lastUpdated = profile.LastUpdated;
16
17 ProfileInfo profileInfo = new ProfileInfo(username, isAnonymous, lastActivity, lastUpdated, 1);
18
19 profileInfoCollection.Add(profileInfo);
20 }
21
22 // Set the total number of records.
23 totalRecords = profiles.ToList().Count;
24
25 return profileInfoCollection;
26 }
如何嘲笑Membership.GetUser()調用,這樣我可以寫這種方法測試?任何建議或例子?謝謝。
是啊,我想使用TypeMock或起訂量,但我還沒有看到此特定情形的任何實例。我會按照你的建議玩一下注射,看看它是如何工作的。謝謝。 – 2009-06-08 21:05:02