Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4008


Ignore:
Timestamp:
07/07/10 02:20:51 (14 years ago)
Author:
dkahn
Message:

#1061 Extended tests for GetAllUsers() and added FindUsersByEmail() and FindUsersByName() plus unit tests.

Location:
branches/HeuristicLab.Services.Authentication Prototype
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Services.Authentication Prototype/Service/Provider/HeuristicLabMembershipProvider.cs

    r4007 r4008  
    242242
    243243
    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>
    245253    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>
    259269    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>
    263285    public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords) {
    264286      using (DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext()) {
     
    268290        return PagedCollection(users, pageIndex, pageSize, out totalRecords);
    269291      }
     292     
    270293    }
    271294
  • branches/HeuristicLab.Services.Authentication Prototype/UnitTests/HeuristicLabMembershipProviderTest.cs

    r4006 r4008  
    349349      MembershipProvider target = Membership.Provider;
    350350      MembershipCreateStatus status;
     351      MembershipUserCollection users;
    351352      int totalRecords;
    352353      int numberOfUsers = 13;
    353354      int pageSize = 5;
    354355
     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
    355359      // Create some users
    356360      for (int i = 0; i < numberOfUsers; i++) {
     
    359363
    360364      // basic proof as in http://msdn.microsoft.com/en-us/library/system.web.security.membershipprovider.getallusers.aspx
    361       MembershipUserCollection users = target.GetAllUsers(1, pageSize, out totalRecords);
     365      users = target.GetAllUsers(1, pageSize, out totalRecords);
    362366      HeuristicLabMembershipUser firstUser = null;
    363367      HeuristicLabMembershipUser lastUser = null;
     
    371375      Assert.AreEqual("User 9", lastUser.UserName);
    372376
    373 
    374377      // simulate paging and make sure that a valid empty collection is returned in the end
    375378      int pageIndex = 0;
     
    389392      // Make sure that we ended up at the last page
    390393      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);
    391397    }
    392398
     
    396402    [TestMethod()]
    397403    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);
    410423    }
    411424
     
    415428    [TestMethod()]
    416429    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);
    429449    }
    430450
Note: See TracChangeset for help on using the changeset viewer.