How to approach unit testing of private methods?
I have a class that loads Employee data into a database. Here is an example:
<P →
public class EmployeeFacade { public Employees EmployeeRepository = new Employees(); public TaxDatas TaxRepository = new TaxDatas(); public Accounts AccountRepository = new Accounts();
I am writing an application to create serialized objects (e.g. Employee above) and load data into a database.
I have a few design questions that I would like to express my views on:
A - I call this class "EmployeeFacade" because I (try?) To use a facade template. Is it good to use a template for the class name?
B - Is it good to name the specific objects of my DAL layer classes "Storage", for example. "EmployeeRepository"?
C - Is using repositories this way reasonable or should I create a method in the repository itself to take, say, Employee and then load the data from there, for example. EmployeeRepository.LoadAllEmployeeData (employee employee)? I am aiming for a cohesive class, but it will make the repository have knowledge about the Employee object, which may not be the best?
D - Is there a good way to avoid having to check if an object is null at the beginning of each method?
E - I have an EmployeeRepository, TaxRepository, AccountRepository declared as open for unit testing purposes. These are really private topics, but I should be able to replace them with stubs, so as not to write to my database (I overload the save () method to do nothing). Anyway, around this or should I expose them?
F - How can I test private methods - or is it done (something tells me about it)?
G- "emps.Name = employee.EmployeeDetails.PersonalDetails.Active.Names.FirstName;" this violates the Law of Demeter, but how can I adapt my objects to comply with the law?
design c #
guazz
source share