0
    [HttpPost]
    public ActionResult Save(Master model, FormCollection form)
    {
        if (form != null)
        {
            if (int.Parse(form["btnFlag"]) == 2)
            {
                Process(model);
            }
            else if (int.Parse(form["btnFlag"]) == 3)
            {
                Reject(model);
            }
        }
        return RedirectToAction("Index");

    }

This is the method I am testing. I would like to know if the Process() method is called or the Reject() is called?

pso
  • 819
  • 12
  • 25

1 Answers1

0

Right now the logic is too internal to the class to fully test it. I would suggest another approach where you instead define another class to contain the logic and put the Process/Reject methods on it.

The new class should implement an interface and you could set it as a property/constructor param on the controller. You can then use a mocking framework like MOQ to mock the methods and verify that they were called. Here's a primer on MOQ https://code.google.com/p/moq/wiki/QuickStart

Another approach is to use protected virtual methods and override them in the tests to check that the methods were at least called. It would be a variation on the following http://www.unit-testing.net/CurrentArticle/How-To-Remove-Data-Dependencies-In-Unit-Tests.html

TGH
  • 38,769
  • 12
  • 102
  • 135
  • Thanks for the quick response TGH. Since this code is from a project which has already been completed and released, I do not think I can use any of your options right now. I will use your suggestions for future purpose though! – pso Nov 18 '13 at 05:52