Unit Testing Membership Provider

I was working on my demo application when I needed to test a Custom Membership Provider. Here is a small piece of code that tests whether the user got created or not.

[TestFixture]

public class UserTestFixture

{

[Test]

[RollBack]

public void CanAddUser()

{

string userName = "JohnDoetest";

string password = "something123$";

string email = "johndoetest@gmail.com";

BolayToMembershipProvider provider = new BolayToMembershipProvider();

NameValueCollection config = new NameValueCollection();

config.Add("applicationName", "BolayTo");

config.Add("name", "BolayToMembershipProvider");

config.Add("connectionStringName", "BolayToConnectionString");

config.Add("requiresQuestionAndAnswer", "false");

provider.Initialize(config["name"], config);

MembershipCreateStatus membershipStatus = new MembershipCreateStatus();

provider.CreateUser(userName, password, email, null,null, true, null, out membershipStatus);

Assert.AreEqual(MembershipCreateStatus.Success, membershipStatus,"User not inserted");

}

}

The NameValueCollection variable "config" sets up the configuration settings for the Membership Provider. You can improve this by adding the Membership Provider settings in App.config and then reading the config block at runtime.

Print | posted @ Tuesday, October 30, 2007 9:28 AM

Twitter