Index: /branches/HeuristicLab.Services.Authentication Prototype/Service/Provider/HeuristicLabMembershipProvider.cs
===================================================================
--- /branches/HeuristicLab.Services.Authentication Prototype/Service/Provider/HeuristicLabMembershipProvider.cs	(revision 4007)
+++ /branches/HeuristicLab.Services.Authentication Prototype/Service/Provider/HeuristicLabMembershipProvider.cs	(revision 4008)
@@ -242,23 +242,45 @@
 
 
-
+    /// <summary>
+    /// Returns a paged collection of users that match a given e-mail address
+    /// TODO: Return a sorted result set
+    /// </summary>
+    /// <param name="emailToMatch"></param>
+    /// <param name="pageIndex"></param>
+    /// <param name="pageSize"></param>
+    /// <param name="totalRecords"></param>
+    /// <returns></returns>
     public override MembershipUserCollection FindUsersByEmail(string emailToMatch, int pageIndex, int pageSize, out int totalRecords) {
-      throw new NotImplementedException();
-      totalRecords = 0;
-      using (DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext()) {
-        // don't test db - throw an exception instead if something wents wrong
-        // bail out if there are no records
-        if (0 == (totalRecords = db.HeuristicLabUsers.Count<HeuristicLabUser>())) return new MembershipUserCollection();
-
-        MembershipUserCollection userCollection = new MembershipUserCollection();
-
-      }
-    }
-
-
+      using (DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext()) {
+        IQueryable<HeuristicLabUser> users = (from u in db.HeuristicLabUsers where u.Email == emailToMatch select u);
+        return PagedCollection(users, pageIndex, pageSize, out totalRecords);
+      }
+    }
+
+    /// <summary>
+    /// Returns a paged collection of users that match a given username
+    /// TODO: Return a sorted result set
+    /// </summary>
+    /// <param name="usernameToMatch"></param>
+    /// <param name="pageIndex"></param>
+    /// <param name="pageSize"></param>
+    /// <param name="totalRecords"></param>
+    /// <returns></returns>
     public override MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords) {
-      throw new NotImplementedException();
-    }
-
+      using (DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext()) {
+        IQueryable<HeuristicLabUser> users = (from u in db.HeuristicLabUsers where u.UserName == usernameToMatch select u);
+        return PagedCollection(users, pageIndex, pageSize, out totalRecords);
+      }
+      
+    }
+
+    /// <summary>
+    /// Returns a paged collection of all users
+    /// TODO: Return a sorted result set
+    /// </summary>
+    /// <param name="pageIndex"></param>
+    /// <param name="pageSize"></param>
+    /// <param name="totalRecords"></param>
+    /// <returns></returns>
     public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords) {
       using (DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext()) {
@@ -268,4 +290,5 @@
         return PagedCollection(users, pageIndex, pageSize, out totalRecords);
       }
+      
     }
 
Index: /branches/HeuristicLab.Services.Authentication Prototype/UnitTests/HeuristicLabMembershipProviderTest.cs
===================================================================
--- /branches/HeuristicLab.Services.Authentication Prototype/UnitTests/HeuristicLabMembershipProviderTest.cs	(revision 4007)
+++ /branches/HeuristicLab.Services.Authentication Prototype/UnitTests/HeuristicLabMembershipProviderTest.cs	(revision 4008)
@@ -349,8 +349,12 @@
       MembershipProvider target = Membership.Provider;
       MembershipCreateStatus status;
+      MembershipUserCollection users;
       int totalRecords;
       int numberOfUsers = 13;
       int pageSize = 5;
 
+      // make sure that we get an empty result if there are no users
+      Assert.AreEqual(0, target.GetAllUsers(1, pageSize, out totalRecords).Count);
+
       // Create some users
       for (int i = 0; i < numberOfUsers; i++) {
@@ -359,5 +363,5 @@
 
       // 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);
+      users = target.GetAllUsers(1, pageSize, out totalRecords);
       HeuristicLabMembershipUser firstUser = null;
       HeuristicLabMembershipUser lastUser = null;
@@ -371,5 +375,4 @@
       Assert.AreEqual("User 9", lastUser.UserName);
 
-
       // simulate paging and make sure that a valid empty collection is returned in the end
       int pageIndex = 0;
@@ -389,4 +392,7 @@
       // Make sure that we ended up at the last page
       Assert.AreEqual(3, pageIndex);
+
+      // Make sure that we get an empty result if the page index is out of bounds
+      Assert.AreEqual(0, target.GetAllUsers(42, pageSize, out totalRecords).Count);
     }
 
@@ -396,16 +402,23 @@
     [TestMethod()]
     public void FindUsersByNameTest() {
-      MembershipProvider target = Membership.Provider; // TODO: Initialize to an appropriate value
-      string usernameToMatch = string.Empty; // TODO: Initialize to an appropriate value
-      int pageIndex = 0; // TODO: Initialize to an appropriate value
-      int pageSize = 0; // TODO: Initialize to an appropriate value
-      int totalRecords = 0; // TODO: Initialize to an appropriate value
-      int totalRecordsExpected = 0; // TODO: Initialize to an appropriate value
-      MembershipUserCollection expected = null; // TODO: Initialize to an appropriate value
-      MembershipUserCollection actual;
-      actual = target.FindUsersByName(usernameToMatch, pageIndex, pageSize, out totalRecords);
-      Assert.AreEqual(totalRecordsExpected, totalRecords);
-      Assert.AreEqual(expected, actual);
-      Assert.Inconclusive("Verify the correctness of this test method.");
+      MembershipProvider target = Membership.Provider;
+      MembershipCreateStatus status;
+      int totalRecords;
+      int pageSize = 5;
+
+      target.CreateUser("User 1", "newPassword ", "foo@bar.com", "testquestion ", "testanswer ", true, null, out status);
+      target.CreateUser("User 2", "newPassword ", "foo@baz.com", "testquestion ", "testanswer ", true, null, out status);
+      MembershipUserCollection users = target.FindUsersByName("User 2", 0, pageSize, out totalRecords);
+      HeuristicLabMembershipUser firstUser = null;
+      HeuristicLabMembershipUser lastUser = null;
+      foreach (HeuristicLabMembershipUser user in users) {
+        if (firstUser == null) {
+          firstUser = user;
+        }
+        lastUser = user;
+      }
+      Assert.AreEqual("User 2", firstUser.UserName);
+      Assert.AreEqual("User 2", lastUser.UserName);
+      Assert.AreEqual(1, totalRecords);
     }
 
@@ -415,16 +428,23 @@
     [TestMethod()]
     public void FindUsersByEmailTest() {
-      MembershipProvider target = Membership.Provider; // TODO: Initialize to an appropriate value
-      string emailToMatch = string.Empty; // TODO: Initialize to an appropriate value
-      int pageIndex = 0; // TODO: Initialize to an appropriate value
-      int pageSize = 0; // TODO: Initialize to an appropriate value
-      int totalRecords = 0; // TODO: Initialize to an appropriate value
-      int totalRecordsExpected = 0; // TODO: Initialize to an appropriate value
-      MembershipUserCollection expected = null; // TODO: Initialize to an appropriate value
-      MembershipUserCollection actual;
-      actual = target.FindUsersByEmail(emailToMatch, pageIndex, pageSize, out totalRecords);
-      Assert.AreEqual(totalRecordsExpected, totalRecords);
-      Assert.AreEqual(expected, actual);
-      Assert.Inconclusive("Verify the correctness of this test method.");
+      MembershipProvider target = Membership.Provider;
+      MembershipCreateStatus status;
+      int totalRecords;
+      int pageSize = 5;
+
+      target.CreateUser("User 1", "newPassword ", "foo@bar.com", "testquestion ", "testanswer ", true, null, out status);
+      target.CreateUser("User 2", "newPassword ", "foo@baz.com", "testquestion ", "testanswer ", true, null, out status);
+      MembershipUserCollection users = target.FindUsersByEmail("foo@bar.com", 0, pageSize, out totalRecords);
+      HeuristicLabMembershipUser firstUser = null;
+      HeuristicLabMembershipUser lastUser = null;
+      foreach (HeuristicLabMembershipUser user in users) {
+        if (firstUser == null) {
+          firstUser = user;
+        }
+        lastUser = user;
+      }
+      Assert.AreEqual("User 1", firstUser.UserName);
+      Assert.AreEqual("User 1", lastUser.UserName);
+      Assert.AreEqual(1, totalRecords);
     }
 
