You can change the ShouldSendLogic()
to accept status as parameter bool ShouldSendLogic(bool status)
. In this way, ShouldSendLogic
can be tested for positive and negative cases.
Another approach is to have IsSuccess()
part of an interface and inject the dependency to the class that has ShouldSendLogic()
. The IsSuccess()
result can be modified by mockup classes in unit test environment and ShouldSendLogic()
can be tested for different status values.
class MyClass
{
ISomeInterface _interfaceObj;
public MyClass(ISomeInterface interfaceObj)
{
_interfaceObj = interfaceObj;
}
public bool ShouldSendLogic()
{
var status = _interfaceObj.IsSuccess();
if (status)
{
SendInvoice();
// do some operation
}
return status;
}
}
Edit
By separating the code that checks for success to an interface, you can now create a "mock" object in your unit tests, where YOU can decide what the value of IsSuccess() should be.
e.g.
public class MockSuccessClass : ISomeInterface
{
public bool IsSuccess { return true; }
}
And then in your "Arrange" section of your unit test, you can create an instance of the MockSuccessClass and pass it to the SUT.
You don't have to use Moq, but it would save time if you let Moq create your Mock classes for you.