Index: /branches/HeuristicLab.Services.Authentication Prototype/Service/Provider/HeuristicLabMembershipProvider.cs
===================================================================
--- /branches/HeuristicLab.Services.Authentication Prototype/Service/Provider/HeuristicLabMembershipProvider.cs	(revision 4005)
+++ /branches/HeuristicLab.Services.Authentication Prototype/Service/Provider/HeuristicLabMembershipProvider.cs	(revision 4006)
@@ -125,6 +125,4 @@
       }
     }
-
-
 
     public override bool ChangePassword(string username, string oldPassword, string newPassword) {
@@ -253,5 +251,4 @@
     }
 
-    // not for production use - fab and dkhan are currently working on that
     public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords) {
       totalRecords = 0;
@@ -266,14 +263,10 @@
 
         MembershipUserCollection userCollection = new MembershipUserCollection();
-        int skip = (pageIndex == 0) ? 0 : (pageIndex * pageSize) - 1;
-
-        var users = from u in db.HeuristicLabUsers select u;
-
-        foreach (HeuristicLabUser u in users) {
-
-          // this leads to a npe
-          if (u != null) {
-            userCollection.Add(u.getMembershipUser(this.Name));
-          }
+        int skip = (pageIndex == 0) ? 0 : (pageIndex * pageSize);
+
+        // .OrderBy(usr=>usr.UserName)
+        // skipped ordering for now as the default comparator seems to be wrong
+        foreach (HeuristicLabUser u in db.HeuristicLabUsers.Skip(skip).Take(pageSize)) {
+          userCollection.Add(u.getMembershipUser(this.Name));
         }
         return userCollection;
Index: /branches/HeuristicLab.Services.Authentication Prototype/UnitTests/HeuristicLabMembershipProviderTest.cs
===================================================================
--- /branches/HeuristicLab.Services.Authentication Prototype/UnitTests/HeuristicLabMembershipProviderTest.cs	(revision 4005)
+++ /branches/HeuristicLab.Services.Authentication Prototype/UnitTests/HeuristicLabMembershipProviderTest.cs	(revision 4006)
@@ -89,5 +89,5 @@
     [TestMethod()]
     public void PasswordStrengthRegularExpressionTest() {
-      MembershipProvider target = Membership.Provider;  
+      MembershipProvider target = Membership.Provider;
       string actual;
       actual = target.PasswordStrengthRegularExpression;
@@ -100,5 +100,5 @@
     [TestMethod()]
     public void PasswordFormatTest() {
-      MembershipProvider target = Membership.Provider;  
+      MembershipProvider target = Membership.Provider;
       MembershipPasswordFormat actual;
       actual = target.PasswordFormat;
@@ -123,7 +123,7 @@
     public void MinRequiredPasswordLengthTest() {
       MembershipProvider target = Membership.Provider;  // TODO: Initialize to an appropriate value
-     
-      MembershipCreateStatus status;
-      target.CreateUser("username", "", "mail", "question", "answer", true, null,out status);
+
+      MembershipCreateStatus status;
+      target.CreateUser("username", "", "mail", "question", "answer", true, null, out status);
       Assert.AreEqual(status, MembershipCreateStatus.InvalidPassword);
       target.CreateUser("username", "testusername", "mail", "question", "answer", true, null, out status);
@@ -149,5 +149,5 @@
     [TestMethod()]
     public void MaxInvalidPasswordAttemptsTest() {
-      MembershipProvider target = Membership.Provider;  
+      MembershipProvider target = Membership.Provider;
       int actual;
       actual = target.MaxInvalidPasswordAttempts;
@@ -160,5 +160,5 @@
     [TestMethod()]
     public void EnablePasswordRetrievalTest() {
-      MembershipProvider target = Membership.Provider;  
+      MembershipProvider target = Membership.Provider;
       bool actual;
       actual = target.EnablePasswordRetrieval;
@@ -182,5 +182,5 @@
     [TestMethod()]
     public void ApplicationNameTest() {
-      MembershipProvider target = Membership.Provider;  
+      MembershipProvider target = Membership.Provider;
       string expected = string.Empty; // TODO: Initialize to an appropriate value
       string actual;
@@ -196,5 +196,5 @@
     [TestMethod()]
     public void ValidateUserTest() {
-      MembershipProvider target = Membership.Provider;  
+      MembershipProvider target = Membership.Provider;
       MembershipCreateStatus status;
       target.CreateUser("testname", "newPassword", "testemail", "testquestion", "testanswer", true, null, out status);
@@ -207,5 +207,5 @@
     [TestMethod()]
     public void ValidateUserTestEncrypted() {
-      MembershipProvider target = Membership.Provider;  
+      MembershipProvider target = Membership.Provider;
       NameValueCollection config = new NameValueCollection();
       config.Add("passwordFormat", "Encrypted");
@@ -241,17 +241,16 @@
     ///</summary>
     [TestMethod()]
-    public void LockUserTest()
-    {
-        MembershipProvider target = Membership.Provider;
-        MembershipCreateStatus status;
-        Persistence.HeuristicLabMembershipUser user = (Persistence.HeuristicLabMembershipUser)target.CreateUser("testname", "newPassword", "testemail", "testquestion", "testanswer", true, null, out status);
-        user.UnlockUser();
-        HeuristicLabUser dbUser = db.HeuristicLabUsers.Single(u => u.UserName == "testname");
-        Assert.IsFalse(dbUser.Locked);
-        Assert.IsTrue(dbUser.Locked);
-       
-    }
-
-  
+    public void LockUserTest() {
+      MembershipProvider target = Membership.Provider;
+      MembershipCreateStatus status;
+      Persistence.HeuristicLabMembershipUser user = (Persistence.HeuristicLabMembershipUser)target.CreateUser("testname", "newPassword", "testemail", "testquestion", "testanswer", true, null, out status);
+      user.UnlockUser();
+      HeuristicLabUser dbUser = db.HeuristicLabUsers.Single(u => u.UserName == "testname");
+      Assert.IsFalse(dbUser.Locked);
+      Assert.IsTrue(dbUser.Locked);
+
+    }
+
+
 
     /// <summary>
@@ -351,20 +350,43 @@
       MembershipCreateStatus status;
       int totalRecords;
+      int numberOfUsers = 13;
+      int pageSize = 5;
 
       // Create some users
-      for (int i = 0; i < 50; i++)
-      {
-          target.CreateUser("User " + i, "newPassword " + i, "testemail " + i, "testquestion " + i, "testanswer " + i, true, null, out status);
-      }
-
-      MembershipUserCollection users = target.GetAllUsers(0, 5, out totalRecords);
-
-      int j = 0;
+      for (int i = 0; i < numberOfUsers; i++) {
+        target.CreateUser("User " + i, "newPassword " + i, "testemail " + i, "testquestion " + i, "testanswer " + i, true, null, out status);
+      }
+
+      // basic proof as in http://msdn.microsoft.com/en-us/library/system.web.security.membershipprovider.getallusers.aspx
+      MembershipUserCollection users = target.GetAllUsers(1, pageSize, out totalRecords);
+      HeuristicLabMembershipUser firstUser = null;
+      HeuristicLabMembershipUser lastUser = null;
       foreach (HeuristicLabMembershipUser user in users) {
-        Assert.Equals("User " + j, user.UserName);
-        j++;
-      }
-
-
+        if (firstUser == null) {
+          firstUser = user;
+        }
+        lastUser = user;
+      }
+      Assert.AreEqual("User 5", firstUser.UserName);
+      Assert.AreEqual("User 9", lastUser.UserName);
+
+
+      // simulate paging and make sure that a valid empty collection is returned in the end
+      int pageIndex = 0;
+      while ((users = target.GetAllUsers(pageIndex, pageSize, out totalRecords)).Count != 0) {
+
+        // check that totalRecords constantly equals the number of created users
+        Assert.AreEqual(numberOfUsers, totalRecords);
+
+        int j = pageIndex * pageSize;
+        foreach (HeuristicLabMembershipUser user in users) {
+          Assert.AreEqual("User " + j, user.UserName);
+          j++;
+        }
+        pageIndex++;
+      }
+
+      // Make sure that we ended up at the last page
+      Assert.AreEqual(3, pageIndex);
     }
 
@@ -497,5 +519,5 @@
     }
 
-    
+
     [TestMethod()]
     public void NoDuplicateUserNameTest() {
