Welcome to AspAdvice Sign in | Join | Help

AzamSharp

Some day I will know everything I hope that day never comes

Syndication

Tags

Navigation

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.

Sponsor

Published Tuesday, October 30, 2007 5:28 PM by azamsharp

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
required 
(required) 
Enter the code you see below