Note that there are some explanatory texts on larger screens.

plurals
  1. PO2 problems with testing asp.net membership provider
    text
    copied!<p>I have created a unit test to search for users by name. I have 2 problems I cant figure out.</p> <ol> <li><p><code>Assert.IsTrue(coll.Count == 2)</code> doesnt count the users as it should. There should be 2 users and it only counts 1.</p></li> <li><p><code>Assert.IsTrue(usernames.Contains("testUser"));</code> doesn't find the partial username string as it should. Can someone tell me what I'm doing wrong?</p></li> </ol> <p>Here is my code:</p> <pre><code>[TestMethod] public void TestFindUsersByName() { //set test to crate user AsaMembershipProvider prov = this.GetMembershipProvider(); MembershipCreateStatus status; //creates users MembershipUser user1 = prov.CreateUser("testUser1", "12345", "test.User1@abc.com", "", "", true, null, out status); MembershipUser user2 = prov.CreateUser("testUser2", "12345", "test.User2@abc.com", "", "", true, null, out status); //gets users user1 = prov.GetUser("testUser1", false); //not checking if user is online. Argument should be false. Not yet implemented user2 = prov.GetUser("testUser2", false); int pageSize = 5; int pageIndex = 0; int totalRecords = 2; MembershipUserCollection coll = prov.FindUsersByName("testUser1", pageIndex, pageSize, out totalRecords); Assert.IsTrue(coll.Count == 2); List&lt;string&gt; usernames = new List&lt;string&gt;(); foreach (MembershipUser user in coll) { usernames.Add(user.UserName); } Assert.AreNotEqual(usernames, null); Assert.IsTrue(usernames.Contains("testUser")); //Deletes Users prov.DeleteUser("testUser1", true); prov.DeleteUser("testUser2", true); //Tries to get users again user1 = prov.GetUser("testUser1", false); user2 = prov.GetUser("testUser2", false); //test that no users are returned Assert.AreEqual(null, user1); Assert.AreEqual(null, user2); } </code></pre>
 

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