public NewsCommentServiceTests() { _testDb = GetTestData().ToList(); var repoMock = new Mock <IRepository <NewsComment> >(); repoMock.Setup(r => r.GetAll()).Returns(_testDb.AsQueryable().BuildMock().Object); repoMock.Setup(r => r.Get(It.IsAny <Expression <Func <NewsComment, bool> > >())) .ReturnsAsync((Expression <Func <NewsComment, bool> > predicate) => _testDb .AsQueryable() .Where(predicate) .FirstOrDefault()); repoMock.Setup(r => r.Add(It.IsAny <NewsComment>())) .Callback((NewsComment comment) => { comment.Id = _testDb.Count; _testDb.Add(comment); }); _unitOfWorkMock = new Mock <IUnitOfWork>(); _unitOfWorkMock.Setup(u => u.Repository <NewsComment>()).Returns(repoMock.Object); _unitOfWorkMock.Setup(u => u.SaveChangesAsync()).Verifiable(); var _authService = new Mock <IAuthenticateService>(); _authService.Setup(a => a.GetAuthUser()).ReturnsAsync(DefaultValues.AuthUser); _commentsService = new NewsCommentService(_unitOfWorkMock.Object, _authService.Object); }
public NewsController(NewsService newsService, UserService userService, NewsCommentService newsCommentService, IOptions <WebStaticConfig> options) { this._newsService = newsService; this._userService = userService; this._newsCommentService = newsCommentService; this._webStaticConfig = options.Value; }
public NewsCommentController(NewsCommentService newsCommentService) { _newsCommentService = newsCommentService; }