public CommentValidatorTests()
        {
            _workItemRepository = Substitute.For <IWorkItemRepository>();

            _workItemRepository.GetById(1).Returns(new WorkItem());
            _workItemRepository.GetById(0).Returns <WorkItem>(value => null);

            _validator = new CommentValidator(_workItemRepository);
        }
예제 #2
0
 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");
 }
예제 #3
0
        public WorkItem Get(int id)
        {
            var workItem = _repository.GetById(id);

            if (workItem == null)
            {
                throw new PmsException(string.Format(Resources.WorkItemNotFound, id));
            }
            return(workItem);
        }
예제 #4
0
        public async Task <WorkItemDto> GetById(int workItemId)
        {
            var workItem = await _workItemRepository.GetById(workItemId);

            return(_mapper.Map <WorkItem, WorkItemDto>(workItem));
        }