I have a method I am trying to test and need to test if an error is thrown. If the employee repository throws an error, I want to make sure I get the EmployeeServiceError back. I am using the FakeItEasy mock framework.
Here is the FakeItEasy code:
// Arrange
var service = new EmployeeService(mockEmployeeRepository, mockCryptographer, mockApplicationUserRepository, mockEmployeeAddressRepository);
IEnumerable<EmployeeDTO> employeeDTOs;
// Act
employeeDTOs = service.GetEmployees();
// Assert
// How do I check the EmployeeServiceException thrown?
A.CallTo(() => mockEmployeeRepository.GetAllForUi())
.Throws(new NullReferenceException());
Here is the method I am testing:
public IEnumerable<EmployeeDTO> GetEmployees()
{
IEnumerable<EmployeeDTO> employeeDTOs = null;
try
{
var employees = _employeeRepository.GetAllForUi();
employeeDTOs = Mapper.Map(employees, employeeDTOs);
}
catch (Exception exception)
{
throw new EmployeeServiceException(exception);
}
return employeeDTOs;
}