Note that there are some explanatory texts on larger screens.

plurals
  1. POException thrown during test, leads to Item has already been added in dictionary
    primarykey
    data
    text
    <p>Im trying to execute this test method but it throws an exception. AS I step through the code to try to isolate the exception it leads me to:</p> <pre><code>public override MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords) </code></pre> <p>shown below the test method. The exception is thrown here with the following message </p> <pre><code>"Item has already been added. Key in dictionary: 'john' Key being added: 'john'". </code></pre> <p>Im not sure where to go from here. Can someone point me in the right direction? Also my test method is still in work, so if you see any errors, unless the errors directly cause the exception to be thrown, please overlook them.</p> <pre><code> [TestMethod] public void TestFindUsersByName()// filed a bug in TFS { try { //set test to create user MembershipProvider prov = this.GetMembershipProvider(); MembershipCreateStatus status; //creates users MembershipUser user1 = prov.CreateUser("johnUser1", "12345", "johnUser1@asc.edu", "", "", true, null, out status); MembershipUser user2 = prov.CreateUser("johnUser2", "12345", "johnUser2@asc.edu", "", "", true, null, out status); //gets users user1 = prov.GetUser("johnUser1", false); //not checking if user is online. Argument should be false. Not yet implemented user2 = prov.GetUser("johnUser2", false); int pageSize = 5; int pageIndex = 0; int totalRecords = 5; MembershipUserCollection coll = prov.FindUsersByName("john", pageIndex, pageSize, out totalRecords); Assert.AreEqual(1, coll.Count); List&lt;string&gt; usernames = new List&lt;string&gt;(); foreach (MembershipUser user in coll) { usernames.Add(user.UserName); } Assert.IsNotNull(usernames); //Assert.IsTrue(usernames.Contains("john")); //Deletes Users prov.DeleteUser("johnUser1", true); prov.DeleteUser("johnUser2", true); //Tries to get users again user1 = prov.GetUser("johnUser1", false); user2 = prov.GetUser("johnUser2", false); //test that no users are returned Assert.AreEqual(null, user1); Assert.AreEqual(null, user2); } catch (Exception ex) { LogMessage(ex); Assert.Fail(ex.Message); } } // MembershipProvider.FindUsersByName public override MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords) { MembershipUserCollection users = new MembershipUserCollection(); try { Profile.MembershipMapper memberMapper = new MembershipMapper(); List&lt;Profile.Membership&gt; recs = (List&lt;Profile.Membership&gt;)memberMapper.GetMembershipsByUsername(_memberUtil.GetApplicationId(), usernameToMatch, pageIndex, pageSize, out totalRecords); foreach (Profile.Membership rec in recs) { users.Add(GetUserFromModel(rec, usernameToMatch)); } } catch (Exception ex) { Exception e = CheckEventLog(ex, "FindUsersByName"); throw e; } return users; } private MembershipUser GetUserFromModel(Profile.Membership membership, string username) { MembershipUser u = new MembershipUser(this.Name, username, membership.userId, membership.email, "", "", true, false, this.GetDate(membership.createDate), this.GetDate(membership.lastLoginDate), this.GetDate(null), this.GetDate(membership.lastPasswordChangedDate), this.GetDate(null)); return u; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload