I'm reading Uncle Bob Martin's Clean Code and now I have a question about the code I wrote. Is using a method as an assertion method a good or bad practice for clean code? Example
// Simple example
public class EmployeeGateway
{
private readonly IWebService _service;
public EmployeeGateway(IWebService service)
{
_service = service
}
public Employee Login(string username, string password)
{
var myEmployee = _service.Find(username);
// DoStuff...
ThrowIfNotEnabled(myEmployee.isEnabled);
//...
}
// Assert Method
private void ThrowIfNotEnabled(bool isEnabled)
{
if(!isEnabled)
throw new MyCustomException(State.EmployIsNotEnabled)
}
}
PS: In Resharper there is an attribute [AssertionMethod].