I'm newbee in Unit Testing and i want to ask how i can test Insert Method from Generic repo and service i have this generic repo
IEnumerable<TEntity> Get(
Expression<Func<TEntity, bool>> filter = null,
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null,
string includeProperties = "");
TEntity GetById(object id);
IEnumerable<TEntity> GetAll();
void Insert(TEntity entity);
void Delete(object id);
void Delete(TEntity entityToDelete);
void Update(TEntity entityToUpdate);
this unit of work:
IGenericRepository<Department> DepartmentRepository { get; }
and this service
public void Insert(string depName, List<Post> posts = null)
{
try
{
var department = new Department(depName, posts);
unitOfWork.DepartmentRepository.Insert(department);
unitOfWork.Save();
}
catch (Exception ex)
{
ErrorSignal.FromCurrentContext().Raise(ex);
return;
}
}
and i'm want to test this service method with Rhino.Mock
var mocks = new MockRepository();
IUnitOfWork unitOfWork = mocks.Stub<IUnitOfWork>();
var dep = new Department("TestDep2");
var deps = new List<Department>
{
new Department("TestDep"),
new Department("FizMat"),
new Department("MainTest"),
};
unitOfWork.Stub(svc => svc.DepartmentRepository.GetAll()).Return(deps);
DepartmentService depService = new DepartmentService(unitOfWork);
// Act
mocks.ReplayAll();
depService.Insert(dep.Name);
var result = depService.GetAll();
//Assert
And always i got errors can any help me?
Aucun commentaire:
Enregistrer un commentaire