Unit testing my custom membership provider
I have a custom membership provider which connects to a user repository
like this:
public class MyMembershipProvider : MembershipProvider {
[Inject]
public IUserRepository UserRepository { get; set; }
...
//Required membership methods
}
I am using ninject for my DI. Now I would like to test the provider, and
have a mock user repository injected to allow me to do this. So something
like:
...
IList<User> users = new List<User> {
new User { Email="matt@test.com",
UserName="matt@test.com",
Password="test"
}
};
var mock = new Mock<IUserRepository>();
mock.Setup(mr => mr.FindByUsername(
It.IsAny<string>())).Returns((string s) => users.Where(
x =>
x.UserName.Equals(s,StringComparison.OrdinalIgnoreCase)).Single());
...
And here is where I am not certain how to proceed, how do I get my mocked
repository injected into my provider so that when a unit test that makes
calls to the provider uses this mock repository?
Am I asking the right questions here?
No comments:
Post a Comment