Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3977


Ignore:
Timestamp:
06/29/10 19:45:09 (14 years ago)
Author:
dkahn
Message:

#1061 GetAllUsers with unit test. Under construction.

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

Legend:

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

    r3966 r3977  
    1111using Persistence;
    1212
     13
    1314namespace Service.Provider {
    1415  class HeuristicLabMembershipProvider : MembershipProvider {
     
    249250    }
    250251
     252    // not for production use - fab and dkhan are currently working on that
    251253    public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords) {
    252       throw new NotImplementedException();
     254      totalRecords = 0;
     255      using (DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext()) {
     256        if (db == null) {
     257          totalRecords = 0;
     258          return new MembershipUserCollection();
     259        }
     260
     261        // bail out if there are no records
     262        if (0 == (totalRecords = db.HeuristicLabUsers.Count<HeuristicLabUser>())) return new MembershipUserCollection();
     263
     264        MembershipUserCollection userCollection = new MembershipUserCollection();
     265        int skip = (pageIndex == 0) ? 0 : (pageIndex * pageSize) - 1;
     266
     267        var users = from u in db.HeuristicLabUsers select u;
     268
     269        foreach (HeuristicLabUser u in users) {
     270
     271          // this leads to a npe
     272          if (u != null) {
     273            userCollection.Add(u);
     274          }
     275        }
     276        return userCollection;
     277      }
    253278    }
    254279
  • branches/HeuristicLab.Services.Authentication Prototype/UnitTests/HeuristicLabMembershipProviderTest.cs

    r3974 r3977  
    339339    /// <summary>
    340340    ///A test for GetAllUsers
     341    ///
     342    /// work in progress
    341343    ///</summary>
    342344    [TestMethod()]
    343345    public void GetAllUsersTest() {
    344       HeuristicLabMembershipProvider target = new HeuristicLabMembershipProvider(); // TODO: Initialize to an appropriate value
    345       int pageIndex = 0; // TODO: Initialize to an appropriate value
    346       int pageSize = 0; // TODO: Initialize to an appropriate value
    347       int totalRecords = 0; // TODO: Initialize to an appropriate value
    348       int totalRecordsExpected = 0; // TODO: Initialize to an appropriate value
    349       MembershipUserCollection expected = null; // TODO: Initialize to an appropriate value
    350       MembershipUserCollection actual;
    351       actual = target.GetAllUsers(pageIndex, pageSize, out totalRecords);
    352       Assert.AreEqual(totalRecordsExpected, totalRecords);
    353       Assert.AreEqual(expected, actual);
    354       Assert.Inconclusive("Verify the correctness of this test method.");
     346      HeuristicLabMembershipProvider target = new HeuristicLabMembershipProvider();
     347      MembershipCreateStatus status;
     348      int totalRecords;
     349
     350      // Create some users
     351      for (int i = 0; i < 50; i++)
     352      {
     353          target.CreateUser("User " + i, "newPassword " + i, "testemail " + i, "testquestion " + i, "testanswer " + i, true, null, out status);
     354      }
     355
     356      MembershipUserCollection users = target.GetAllUsers(0, 5, out totalRecords);
     357
     358      int j = 0;
     359      foreach (HeuristicLabUser user in users) {
     360        Assert.Equals("User " + j, user.UserName);
     361        j++;
     362      }
     363
     364
    355365    }
    356366
Note: See TracChangeset for help on using the changeset viewer.