I am unit testing this role provider. I have a few asserts in the code for my test. I am sure there are more test I could preform. Does anyone have any suggestions for more test for this role of the membership provider?
[TestMethod]
public void TestDeleteUserAccess()
{
try
{
string sRoleName = "TestRole";
string sUsername = "test.user";
// Use a known user for relationships
AsaMembershipProvider prov = this.GetMembershipProvider();
MembershipUser user = prov.GetUser(sUsername, false);
// Create a new role
AsaRoleProvider roleProv = this.GetRoleProvider();
roleProv.CreateRole(sRoleName);
// Verify that role exists
bool bRoleExists = roleProv.RoleExists(sRoleName);
Assert.IsTrue(bRoleExists);
// Add users to that role
string[] usernames = new string[] { sUsername };
string[] roleNames = new string[] { sRoleName };
roleProv.AddUsersToRoles(usernames, roleNames);
// Verify that user is in role
bool bRelationExists = roleProv.IsUserInRole(sUsername, sRoleName);
Assert.IsTrue(bRelationExists);
// Check various methods for finding role information
string[] matchUsernames = roleProv.FindUsersInRole(sRoleName, "userx");// find constant
foreach (string matchUsername in matchUsernames)//if match.length = 0 then roles were returned
{
Trace.WriteLine("Found in role " + sRoleName + ", user " + matchUsername + ". ");//check something instead of trace
}
string[] matchRoleNames = roleProv.GetRolesForUser(sUsername);
foreach (string matchRoleName in matchRoleNames)
{
Trace.WriteLine("Found for user " + sUsername + ", role " + matchRoleName + ". ");
}
// Remove user from the role
roleProv.RemoveUsersFromRoles(usernames, roleNames);
// Verify that user is no longer in the role
bRelationExists = roleProv.IsUserInRole(sUsername, sRoleName);
Assert.IsFalse(bRelationExists);
// Delete the role
roleProv.DeleteRole(sRoleName, true);
// Verify that no longer exists
bRoleExists = roleProv.RoleExists(sRoleName);
Assert.IsFalse(bRoleExists);
}
catch (Exception ex)
{
LogMessage(ex);
Assert.Fail(ex.Message);
}
}
AsaMembershipProvider
implementsMembershipProvider
correctly? In any case you are asserting too much for one test. \$\endgroup\$DbUnit
for populating the data source for each test. I strongly suggest you clean up your data source, such that it is empty for the start of each test and any change to the data source is visible to the reader of the test without reading an external xml file hundreds of lines long. \$\endgroup\$