- Timestamp:
- 07/07/10 02:20:51 (14 years ago)
- Location:
- branches/HeuristicLab.Services.Authentication Prototype
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Services.Authentication Prototype/Service/Provider/HeuristicLabMembershipProvider.cs
r4007 r4008 242 242 243 243 244 244 /// <summary> 245 /// Returns a paged collection of users that match a given e-mail address 246 /// TODO: Return a sorted result set 247 /// </summary> 248 /// <param name="emailToMatch"></param> 249 /// <param name="pageIndex"></param> 250 /// <param name="pageSize"></param> 251 /// <param name="totalRecords"></param> 252 /// <returns></returns> 245 253 public override MembershipUserCollection FindUsersByEmail(string emailToMatch, int pageIndex, int pageSize, out int totalRecords) { 246 throw new NotImplementedException(); 247 totalRecords = 0; 248 using (DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext()) { 249 // don't test db - throw an exception instead if something wents wrong 250 // bail out if there are no records 251 if (0 == (totalRecords = db.HeuristicLabUsers.Count<HeuristicLabUser>())) return new MembershipUserCollection(); 252 253 MembershipUserCollection userCollection = new MembershipUserCollection(); 254 255 } 256 } 257 258 254 using (DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext()) { 255 IQueryable<HeuristicLabUser> users = (from u in db.HeuristicLabUsers where u.Email == emailToMatch select u); 256 return PagedCollection(users, pageIndex, pageSize, out totalRecords); 257 } 258 } 259 260 /// <summary> 261 /// Returns a paged collection of users that match a given username 262 /// TODO: Return a sorted result set 263 /// </summary> 264 /// <param name="usernameToMatch"></param> 265 /// <param name="pageIndex"></param> 266 /// <param name="pageSize"></param> 267 /// <param name="totalRecords"></param> 268 /// <returns></returns> 259 269 public override MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords) { 260 throw new NotImplementedException(); 261 } 262 270 using (DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext()) { 271 IQueryable<HeuristicLabUser> users = (from u in db.HeuristicLabUsers where u.UserName == usernameToMatch select u); 272 return PagedCollection(users, pageIndex, pageSize, out totalRecords); 273 } 274 275 } 276 277 /// <summary> 278 /// Returns a paged collection of all users 279 /// TODO: Return a sorted result set 280 /// </summary> 281 /// <param name="pageIndex"></param> 282 /// <param name="pageSize"></param> 283 /// <param name="totalRecords"></param> 284 /// <returns></returns> 263 285 public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords) { 264 286 using (DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext()) { … … 268 290 return PagedCollection(users, pageIndex, pageSize, out totalRecords); 269 291 } 292 270 293 } 271 294 -
branches/HeuristicLab.Services.Authentication Prototype/UnitTests/HeuristicLabMembershipProviderTest.cs
r4006 r4008 349 349 MembershipProvider target = Membership.Provider; 350 350 MembershipCreateStatus status; 351 MembershipUserCollection users; 351 352 int totalRecords; 352 353 int numberOfUsers = 13; 353 354 int pageSize = 5; 354 355 356 // make sure that we get an empty result if there are no users 357 Assert.AreEqual(0, target.GetAllUsers(1, pageSize, out totalRecords).Count); 358 355 359 // Create some users 356 360 for (int i = 0; i < numberOfUsers; i++) { … … 359 363 360 364 // basic proof as in http://msdn.microsoft.com/en-us/library/system.web.security.membershipprovider.getallusers.aspx 361 MembershipUserCollectionusers = target.GetAllUsers(1, pageSize, out totalRecords);365 users = target.GetAllUsers(1, pageSize, out totalRecords); 362 366 HeuristicLabMembershipUser firstUser = null; 363 367 HeuristicLabMembershipUser lastUser = null; … … 371 375 Assert.AreEqual("User 9", lastUser.UserName); 372 376 373 374 377 // simulate paging and make sure that a valid empty collection is returned in the end 375 378 int pageIndex = 0; … … 389 392 // Make sure that we ended up at the last page 390 393 Assert.AreEqual(3, pageIndex); 394 395 // Make sure that we get an empty result if the page index is out of bounds 396 Assert.AreEqual(0, target.GetAllUsers(42, pageSize, out totalRecords).Count); 391 397 } 392 398 … … 396 402 [TestMethod()] 397 403 public void FindUsersByNameTest() { 398 MembershipProvider target = Membership.Provider; // TODO: Initialize to an appropriate value 399 string usernameToMatch = string.Empty; // TODO: Initialize to an appropriate value 400 int pageIndex = 0; // TODO: Initialize to an appropriate value 401 int pageSize = 0; // TODO: Initialize to an appropriate value 402 int totalRecords = 0; // TODO: Initialize to an appropriate value 403 int totalRecordsExpected = 0; // TODO: Initialize to an appropriate value 404 MembershipUserCollection expected = null; // TODO: Initialize to an appropriate value 405 MembershipUserCollection actual; 406 actual = target.FindUsersByName(usernameToMatch, pageIndex, pageSize, out totalRecords); 407 Assert.AreEqual(totalRecordsExpected, totalRecords); 408 Assert.AreEqual(expected, actual); 409 Assert.Inconclusive("Verify the correctness of this test method."); 404 MembershipProvider target = Membership.Provider; 405 MembershipCreateStatus status; 406 int totalRecords; 407 int pageSize = 5; 408 409 target.CreateUser("User 1", "newPassword ", "foo@bar.com", "testquestion ", "testanswer ", true, null, out status); 410 target.CreateUser("User 2", "newPassword ", "foo@baz.com", "testquestion ", "testanswer ", true, null, out status); 411 MembershipUserCollection users = target.FindUsersByName("User 2", 0, pageSize, out totalRecords); 412 HeuristicLabMembershipUser firstUser = null; 413 HeuristicLabMembershipUser lastUser = null; 414 foreach (HeuristicLabMembershipUser user in users) { 415 if (firstUser == null) { 416 firstUser = user; 417 } 418 lastUser = user; 419 } 420 Assert.AreEqual("User 2", firstUser.UserName); 421 Assert.AreEqual("User 2", lastUser.UserName); 422 Assert.AreEqual(1, totalRecords); 410 423 } 411 424 … … 415 428 [TestMethod()] 416 429 public void FindUsersByEmailTest() { 417 MembershipProvider target = Membership.Provider; // TODO: Initialize to an appropriate value 418 string emailToMatch = string.Empty; // TODO: Initialize to an appropriate value 419 int pageIndex = 0; // TODO: Initialize to an appropriate value 420 int pageSize = 0; // TODO: Initialize to an appropriate value 421 int totalRecords = 0; // TODO: Initialize to an appropriate value 422 int totalRecordsExpected = 0; // TODO: Initialize to an appropriate value 423 MembershipUserCollection expected = null; // TODO: Initialize to an appropriate value 424 MembershipUserCollection actual; 425 actual = target.FindUsersByEmail(emailToMatch, pageIndex, pageSize, out totalRecords); 426 Assert.AreEqual(totalRecordsExpected, totalRecords); 427 Assert.AreEqual(expected, actual); 428 Assert.Inconclusive("Verify the correctness of this test method."); 430 MembershipProvider target = Membership.Provider; 431 MembershipCreateStatus status; 432 int totalRecords; 433 int pageSize = 5; 434 435 target.CreateUser("User 1", "newPassword ", "foo@bar.com", "testquestion ", "testanswer ", true, null, out status); 436 target.CreateUser("User 2", "newPassword ", "foo@baz.com", "testquestion ", "testanswer ", true, null, out status); 437 MembershipUserCollection users = target.FindUsersByEmail("foo@bar.com", 0, pageSize, out totalRecords); 438 HeuristicLabMembershipUser firstUser = null; 439 HeuristicLabMembershipUser lastUser = null; 440 foreach (HeuristicLabMembershipUser user in users) { 441 if (firstUser == null) { 442 firstUser = user; 443 } 444 lastUser = user; 445 } 446 Assert.AreEqual("User 1", firstUser.UserName); 447 Assert.AreEqual("User 1", lastUser.UserName); 448 Assert.AreEqual(1, totalRecords); 429 449 } 430 450
Note: See TracChangeset
for help on using the changeset viewer.