Using Moq and the native VS test framework. I'm trying to test a recursive function where values passed in:
public bool AuthenticateByDomain(string domainName, string password, string username, string email)
{
are used to find an entity:
// look for an existent domain name.
var matchFound = this.FindDomainPasswordMatch(domainName, password);
If found, look for existent UserName (the account already exists):
if (matchFound)
{
var account = this.GetByEmail(null, email);
if (account != null)
{
If not found, create the account based on the email and username provided:
var uAccount = this.CreateAccount(username, password, email, domainName);
and then recursively call itself where (presumably) the call to GetByEmail()
is satisfied and the authenticating branch is invoked.
I've found a couple examples of Moq interacting with repository but haven't been able to see exactly how to approach my specific problem - testing that the repository gets updated and the recursion succeeds. I _am able to unit get each of the methods found in the top-level - do I declare that good enough and move on? Is this a persistence test?
having troubles testing something easily might be an indicator for poor design decisions. make yourself clear if you really NEED that recursion.
Wouldn't it be easier to split these two calls to CreateAccount
and FindDomainPasswordMatch
and separate them design-wise. maybe I don't see your point fully, but the recursion itself seems to have no real "recursive" use. its just a "lazy" call with duplicate code. i would recommend you to separate these mechanics from themselves. this makes testing therefore much easier too and you should not have any problems testing these methods.
hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With