У меня ниже класса, и я пытаюсь проверить его метод SaveEmployee.
public class EmployeeService : IEmployeeService
{
private readonly IRepository _repository;
private readonly ISomeOtherService _someOtherService;
public EmployeeService(IRepository repository, ISomeOtherService someOtherService)
{
_repository = repository;
_someOtherService = someOtherService;
}
public EmployeeResult SaveEmployee(EmployeeAssociation employeeAssoc)
{
Employee newEmp = new Employee()
{
Id = Guid.NewGuid(),
Age = employeeAssoc.Age,
Name = employeeAssoc.Name,
Adress = employeeAssoc.Address
}
int saveReturnValue = _repository.Insert<Employee>(newEmp);
if (saveReturnValue == 1)
{
// Do something here
}
else
{
// message, save not successful
}
}
}
Ниже приведен класс модульного теста, который я создал
[TestClass]
public class EmployeeCreateTest
{
Mock<IRepository> _repository;
Mock<ISomeOtherService> _someOtherService
IEmployeeService _employeeService
[TestMethod]
public void SaveEmployee_ExecutesSuccessfully()
{
_repository = new Mock<IRepository>();
_someOtherService = new Mock<ISomeOtherService>();
_employeeService = new EmployeeService(_repository.Object, _someOtherService.Object);
Employee emp = new Employee();
_repository.Setup(x => x.Insert<Employee>(emp)).Returns(1);
_employeeService.SaveEmployee(new EmployeeAssociation());
_repository.Verify(x => x.Insert<Employee>(emp), Times.Once);
}
}
Это всегда дает мне ошибку ниже, Ожидаемый вызов на макет один раз, но был 0 раз ...
Есть идеи, что я не так делаю?