InCode
InCode

Reputation: 503

How can this Service Method be Unit Tested

I'm diving into Unit Testing...etc.. I'm stuck trying to test this particular service. I've seen examples but I can't seem to understand what proper steps are to unit test this simple method: GetEmployeeProductivity()

public class EmployeeService
{
    private IRepository<Employee> _employeeInfoRespository;
    private IEmployeeData_Repository _EmployeeDataRespository;

public Employee GetEmployeeProductivity(Employee employee,String Date1, String Date2)
    {
        Employee newEmp = new Employee();
        newEmp = _EmployeeDataRespository.GetEmployeeDataUsingDates(employee,Date1,Date2);
        return newEmp;
    }

}

If it's not testable how can this be rewritten to be testable? Please provide an example.

Upvotes: 1

Views: 55

Answers (1)

Alex Siepman
Alex Siepman

Reputation: 2608

The problem is the _EmployeeDataRespository.GetEmployeeDataUsingDatesthat goes to the database. You should mock this method.

The method probably need a redesign to. The = new Employee(); is not needed ad all.

The method is now not much more then a wrapper for an other method. I does not do much on his own.

Upvotes: 2

Related Questions