Estoy escribiendo un proveedor de perfil personalizado, pero todavía tengo la intención de utilizar el AspNetSqlMembershipProvider predeterminado como mi proveedor de membresía. Mi método GetAllProfiles() en el profesional de perfil es el siguiente:Membresía burlona
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 }
¿Cómo se burlan de la llamada Membership.GetUser() para que yo pueda escribir pruebas de este método? Alguna sugerencia o ejemplos? Gracias.
Sí, estaba pensando acerca del uso de Typemock o Moq, pero no he visto ningún ejemplo de este escenario particular. Voy a jugar con una inyección como sugirió para ver cómo funciona. Gracias. –