public void GetByIdTest() { //Arange Mock <IUnitOfWork> unitOfWorkMock = new Mock <IUnitOfWork>(); Mock <IRepository <CustomTask> > repositoryMock = new Mock <IRepository <CustomTask> >(); repositoryMock.Setup(repo => repo.Get(It.IsAny <Expression <Func <CustomTask, bool> > >())) .Returns <Expression <Func <CustomTask, bool> > >(predicate => _customTasks.Where(predicate.Compile()).AsQueryable()); unitOfWorkMock.Setup(getRepo => getRepo.GetRepository <CustomTask>()).Returns(repositoryMock.Object); CustomTaskService customTaskService = new CustomTaskService(unitOfWorkMock.Object); //Act CustomTaskDto customTaskDto = customTaskService.Get("1"); //Assert Assert.NotNull(customTaskDto); Assert.Equal("CT1", customTaskDto.Name); }
public void GetByFilterTest() { //Arange Mock <IUnitOfWork> unitOfWorkMock = new Mock <IUnitOfWork>(); Mock <IRepository <CustomTask> > repositoryMock = new Mock <IRepository <CustomTask> >(); repositoryMock.Setup(repo => repo.Get(It.IsAny <Expression <Func <CustomTask, bool> > >())).Returns(_customTasks.AsQueryable); unitOfWorkMock.Setup(getRepo => getRepo.GetRepository <CustomTask>()).Returns(repositoryMock.Object); CustomTaskService customTaskService = new CustomTaskService(unitOfWorkMock.Object); CustomTaskFilter customTaskFilter = new CustomTaskFilter(); //Act IEnumerable <CustomTaskDto> customTasksDto = customTaskService.Get(customTaskFilter); //Assert Assert.NotNull(customTasksDto); Assert.NotEmpty(customTasksDto); Assert.Equal(3, customTasksDto.Count()); }