4

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?

2
  • 3
    Which method (behavior) you are testing? Which dependencies you are mocking? Commented Mar 1, 2013 at 11:33
  • There is nothing in code you have showed that can be tested using Moq. We need whole code. Commented Mar 1, 2013 at 19:49

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.