public void WhenUserIsNotOwnerOfTheSuggestionComment_ShouldThrowAUnauthorizedException() =>
        ShouldThrowDuringTheValidation <UnauthorizedException>(() =>
        {
            AddTheValidSuggestion();

            var suggestion = _dbContext.Suggestions.First();
            var comment    = suggestion.Comments.First();
            var newComment = new SuggestionComment
            {
                Id        = comment.Id,
                CreatedBy = "other user id"
            };

            _repository.RemoveUserComment(suggestion.Id, comment.Id, comment.CreatedBy);
            _repository.AddComment(suggestion.Id, newComment);
            _dbContext.SaveChanges();
        });
Exemplo n.º 2
0
        public async Task <Suggestion> Handle(CommentASuggestionCommand commentASuggestion, CancellationToken cancellationToken = default)
        {
            var validationContext = new CommentASuggestionValidationContext(commentASuggestion, _repository);

            _commentValidator.Validate(validationContext);

            var suggestionComment = _mapper.Map <SuggestionComment>(commentASuggestion);
            var suggestion        = _repository.AddComment(commentASuggestion.SuggestionId, suggestionComment);

            suggestionComment.Suggestion = suggestion;

            await _dbContext.SaveChangesAsync();

            var createANotificationCommand = _mapper.Map <CreateANotificationCommand>(suggestionComment);

            createANotificationCommand.ConcernedUserIds = new[] { suggestion.CreatedBy };

            await _mediator.Send(createANotificationCommand);

            return(suggestion);
        }