Method refactoring

1.Simplify the following method

public int AMethod(bool first, bool second, bool third)
{
if (!first)
{
if (second)
{
if (third)
{
return OptionOne;
}
else if (!second)
{
return OptionTwo;
}
else
{
return OptionOne;
}
}
else
{
return OptionOne;
}
}
else if (!third)
{
if (!second)
{
return OptionTwo;
}
}
else if (!second)
{
return OptionTwo;
}
if (!(third || !second))
{
return OptionTwo;
}
return OptionOne;
}

2.Show how you validated the correctness of your revised AMethod method.

Unit testing

You are working on a legacy bank system that is converted to be unit testable. The requirements for the unit tests is that they have to:

  • Execute quickly (have to take less than 10 seconds)
  • Be runnable on each commit and part of nightly builds on servers with no external connections such as database, network shares etc.

You are assigned the task of implementing unit tests for the attached code snippet and are allowed to refactor the code provided you maintain the existing functionality.

1.Create unit tests for all public methods of AccountBl class that will satisfy aforementioned unit test requirements.

2.If possible create unit tests for DataStore class. Do you see any limitations in unit testing this class?

3.Refactor AccountBl method signature given that the only usage of AccountBl class is from a method similar to Program.Main

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.