3 ms·
Looking at your code, I don't think you still need the UserRepository class. From the 2 sample methods you provided, notice that "Store" and "Encryption" can be
by jister 16y ago
Looking at your code, I don't think you still need the UserRepository class. From the 2 sample methods you provided, notice that "Store" and "Encryption" can be standalone so leaves the UserRepository class only as a wrapper which complicates your unit tests.
Of course I might be wrong since I haven't seen the rest of the code in UserRepository.
Also, you can also design your FindByCredentials method as:
public bool FindByCredentials(string userName, string password, out User user) {}
- latch 16y agoThe entire example is contrived to talk about testing. Not much about UserRepository is ideal. I think out and ref are pretty horrible. I understand that the pattern is convenient for the BLC *.TryParse methods, but it should really stick there. Your signature tells me that you'd likely return false rather than throw an exception. I'd agree that returning null isn't the best, but I'd favor returning a NullObject that true/false with a out parameter.
- MartinCron 16y agoI think out and ref are pretty horrible. I agree wholeheartedly, though I'm not sure why. I often find myself creating small "data bunch" types with names like ValidationResult that consist of a bool & a set of messages to use as responses to the question "is this input OK, and if not, why not?"