public CommentValidatorTests() { _workItemRepository = Substitute.For <IWorkItemRepository>(); _workItemRepository.GetById(1).Returns(new WorkItem()); _workItemRepository.GetById(0).Returns <WorkItem>(value => null); _validator = new CommentValidator(_workItemRepository); }
public CommentValidator(IWorkItemRepository workItemRepository) { RuleFor(x => x.Body).NotEmpty().Length(1, 200); RuleFor(x => x.WorkItemId).NotEmpty() .Must(workItemId => workItemRepository.GetById(workItemId).Result != null) .WithMessage("Foreign key constraint failure"); }
public WorkItem Get(int id) { var workItem = _repository.GetById(id); if (workItem == null) { throw new PmsException(string.Format(Resources.WorkItemNotFound, id)); } return(workItem); }
public async Task <WorkItemDto> GetById(int workItemId) { var workItem = await _workItemRepository.GetById(workItemId); return(_mapper.Map <WorkItem, WorkItemDto>(workItem)); }