私はカスタムプロファイルプロバイダを作成していますが、私はまだ、メンバーシッププロバイダとしてデフォルトのAspNetSqlMembershipProviderを使用するつもりです。私のプロフィールプロバイダでの私のGetAllProfiles()メソッドは次のようになります。Mocking Membership
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や部品番号を使用して考えていたが、私は、この特定のシナリオのいずれかの例を見ていません。私は、あなたがその仕組みがどのように見えるかを示唆しているように、注射して遊んでいきます。ありがとう。 –