on one of my model class I have the property:
public virtual bool OkToChangeApprovedForPayment
{
get
{
return ExportedDateTime == null && PMApproved == true && HttpContext.Current.User.IsInRole(Resources.Roles.VectorOpsAdmin);
}
}
As you can see one of the conditions is testing the role the user is in. Is it ok to be accessing the HttpContext in the model like this? If not what is a better way to do it?
If it is ok, how would you unit test it? How would you replace the call to the HttpContext?
This is safe (if your model executes in the context of a running request, of course).
It will be hard to test, though. You could inject an instance of HttpContextBase into the model which is more suitable for testing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With