Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/07/10 01:03:47 (14 years ago)
Author:
dkahn
Message:

#1061 Implemented GetAllUsers with unit test. Returning an ordered collection is still to be done

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Services.Authentication Prototype/UnitTests/HeuristicLabMembershipProviderTest.cs

    r4004 r4006  
    8989    [TestMethod()]
    9090    public void PasswordStrengthRegularExpressionTest() {
    91       MembershipProvider target = Membership.Provider; 
     91      MembershipProvider target = Membership.Provider;
    9292      string actual;
    9393      actual = target.PasswordStrengthRegularExpression;
     
    100100    [TestMethod()]
    101101    public void PasswordFormatTest() {
    102       MembershipProvider target = Membership.Provider; 
     102      MembershipProvider target = Membership.Provider;
    103103      MembershipPasswordFormat actual;
    104104      actual = target.PasswordFormat;
     
    123123    public void MinRequiredPasswordLengthTest() {
    124124      MembershipProvider target = Membership.Provider;  // TODO: Initialize to an appropriate value
    125      
    126       MembershipCreateStatus status;
    127       target.CreateUser("username", "", "mail", "question", "answer", true, null,out status);
     125
     126      MembershipCreateStatus status;
     127      target.CreateUser("username", "", "mail", "question", "answer", true, null, out status);
    128128      Assert.AreEqual(status, MembershipCreateStatus.InvalidPassword);
    129129      target.CreateUser("username", "testusername", "mail", "question", "answer", true, null, out status);
     
    149149    [TestMethod()]
    150150    public void MaxInvalidPasswordAttemptsTest() {
    151       MembershipProvider target = Membership.Provider; 
     151      MembershipProvider target = Membership.Provider;
    152152      int actual;
    153153      actual = target.MaxInvalidPasswordAttempts;
     
    160160    [TestMethod()]
    161161    public void EnablePasswordRetrievalTest() {
    162       MembershipProvider target = Membership.Provider; 
     162      MembershipProvider target = Membership.Provider;
    163163      bool actual;
    164164      actual = target.EnablePasswordRetrieval;
     
    182182    [TestMethod()]
    183183    public void ApplicationNameTest() {
    184       MembershipProvider target = Membership.Provider; 
     184      MembershipProvider target = Membership.Provider;
    185185      string expected = string.Empty; // TODO: Initialize to an appropriate value
    186186      string actual;
     
    196196    [TestMethod()]
    197197    public void ValidateUserTest() {
    198       MembershipProvider target = Membership.Provider; 
     198      MembershipProvider target = Membership.Provider;
    199199      MembershipCreateStatus status;
    200200      target.CreateUser("testname", "newPassword", "testemail", "testquestion", "testanswer", true, null, out status);
     
    207207    [TestMethod()]
    208208    public void ValidateUserTestEncrypted() {
    209       MembershipProvider target = Membership.Provider; 
     209      MembershipProvider target = Membership.Provider;
    210210      NameValueCollection config = new NameValueCollection();
    211211      config.Add("passwordFormat", "Encrypted");
     
    241241    ///</summary>
    242242    [TestMethod()]
    243     public void LockUserTest()
    244     {
    245         MembershipProvider target = Membership.Provider;
    246         MembershipCreateStatus status;
    247         Persistence.HeuristicLabMembershipUser user = (Persistence.HeuristicLabMembershipUser)target.CreateUser("testname", "newPassword", "testemail", "testquestion", "testanswer", true, null, out status);
    248         user.UnlockUser();
    249         HeuristicLabUser dbUser = db.HeuristicLabUsers.Single(u => u.UserName == "testname");
    250         Assert.IsFalse(dbUser.Locked);
    251         Assert.IsTrue(dbUser.Locked);
    252        
    253     }
    254 
    255  
     243    public void LockUserTest() {
     244      MembershipProvider target = Membership.Provider;
     245      MembershipCreateStatus status;
     246      Persistence.HeuristicLabMembershipUser user = (Persistence.HeuristicLabMembershipUser)target.CreateUser("testname", "newPassword", "testemail", "testquestion", "testanswer", true, null, out status);
     247      user.UnlockUser();
     248      HeuristicLabUser dbUser = db.HeuristicLabUsers.Single(u => u.UserName == "testname");
     249      Assert.IsFalse(dbUser.Locked);
     250      Assert.IsTrue(dbUser.Locked);
     251
     252    }
     253
     254
    256255
    257256    /// <summary>
     
    351350      MembershipCreateStatus status;
    352351      int totalRecords;
     352      int numberOfUsers = 13;
     353      int pageSize = 5;
    353354
    354355      // Create some users
    355       for (int i = 0; i < 50; i++)
    356       {
    357           target.CreateUser("User " + i, "newPassword " + i, "testemail " + i, "testquestion " + i, "testanswer " + i, true, null, out status);
    358       }
    359 
    360       MembershipUserCollection users = target.GetAllUsers(0, 5, out totalRecords);
    361 
    362       int j = 0;
     356      for (int i = 0; i < numberOfUsers; i++) {
     357        target.CreateUser("User " + i, "newPassword " + i, "testemail " + i, "testquestion " + i, "testanswer " + i, true, null, out status);
     358      }
     359
     360      // 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);
     362      HeuristicLabMembershipUser firstUser = null;
     363      HeuristicLabMembershipUser lastUser = null;
    363364      foreach (HeuristicLabMembershipUser user in users) {
    364         Assert.Equals("User " + j, user.UserName);
    365         j++;
    366       }
    367 
    368 
     365        if (firstUser == null) {
     366          firstUser = user;
     367        }
     368        lastUser = user;
     369      }
     370      Assert.AreEqual("User 5", firstUser.UserName);
     371      Assert.AreEqual("User 9", lastUser.UserName);
     372
     373
     374      // simulate paging and make sure that a valid empty collection is returned in the end
     375      int pageIndex = 0;
     376      while ((users = target.GetAllUsers(pageIndex, pageSize, out totalRecords)).Count != 0) {
     377
     378        // check that totalRecords constantly equals the number of created users
     379        Assert.AreEqual(numberOfUsers, totalRecords);
     380
     381        int j = pageIndex * pageSize;
     382        foreach (HeuristicLabMembershipUser user in users) {
     383          Assert.AreEqual("User " + j, user.UserName);
     384          j++;
     385        }
     386        pageIndex++;
     387      }
     388
     389      // Make sure that we ended up at the last page
     390      Assert.AreEqual(3, pageIndex);
    369391    }
    370392
     
    497519    }
    498520
    499    
     521
    500522    [TestMethod()]
    501523    public void NoDuplicateUserNameTest() {
Note: See TracChangeset for help on using the changeset viewer.