Exemple #1
0
        public async Task TestGetComments()
        {
            TestingContext testingContext = new TestingContext();

            SetUpTestingContext(testingContext);

            ApplicationDbContext appDbContext    = testingContext.GetSimple <ApplicationDbContext>();
            ICommentsService     commentsService = testingContext.GetService <CommentsService>();

            Question question = appDbContext.Questions.First();

            for (int i = 0; i < 20; i++)
            {
                CommentDto commentDto = new CommentDto()
                {
                    IdQuestion  = question.Id,
                    CommentText = "Hello Comment",
                };
                await commentsService.AddCommentAsync(commentDto);
            }
            GetCommentsDto getCommentsDto = new GetCommentsDto
            {
                IdQuestion = question.Id,
                Page       = 0,
            };

            //Act
            PagedResultDto <CommentDto> comments = await commentsService.GetCommentssAsync(getCommentsDto);

            //Assert
            Assert.Equal(5, comments.Data.Count);
            Assert.Equal(4, comments.Numpages);
            Assert.Equal(20, comments.Count);
        }
        private async Task AddComment()
        {
            try
            {
                IsBusy = true;
                await _commentsService.AddCommentAsync(_commentParam.ParentId, CommentText,
                                                       _commentParam.ParentIsArticle);

                await CoreMethods.PopPageModel();
            }
            catch (ServiceAuthenticationException e)
            {
                await _userDialogs.AlertAsync(title : "Ошибка авторизации",
                                              message : $"{e.Content}", okText : "Ok");
            }
            catch (HttpRequestExceptionEx e)
            {
                await _userDialogs.AlertAsync(title : "Ошибка доступа к серверу",
                                              message : $"HttpCode: {e.HttpCode} Message: {e.Message}", okText : "Ok");
            }
            catch (Exception e)
            {
                await _userDialogs.AlertAsync(title : "Ошибка",
                                              message : $"{e.Message}", okText : "Ok");
            }
            finally
            {
                IsBusy = false;
            }
        }
Exemple #3
0
        public async Task <ActionResult> AddCommentAsync([FromBody] AddComment comment)
        {
            var commentDto = Mapper.Map <AddComment, AddCommentDTO>(comment);

            commentDto.UserId = HttpContext.GetCurrentUserId();
            var addedComment = await _commentsService.AddCommentAsync(commentDto);

            await _commentsHub.Clients.All.SendAsync("commentRecieved", addedComment);

            return(Ok());
        }
        public async Task <IActionResult> Create([FromBody] UpdateCommentRequest updateComment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            string userId = HttpContext.User.Claims.First().Value;

            updateComment.UserId = userId;

            Comment comment = await _commentsService.AddCommentAsync(updateComment);

            string location = $"api/[controller]/{comment.Id}";

            return(Created(location, comment));
        }
        public async Task <IActionResult> AddComment([FromRoute] long id, [FromBody] CommentRequest request)
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            if (user == null)
            {
                return(NotFound());
            }

            var result = await _commentsService.AddCommentAsync(id, user, request.Body);

            if (result)
            {
                return(NoContent());
            }

            return(BadRequest());
        }
Exemple #6
0
        public async Task TestAddComment()
        {
            TestingContext testingContext = new TestingContext();

            SetUpTestingContext(testingContext);

            ApplicationDbContext appDbContext    = testingContext.GetSimple <ApplicationDbContext>();
            ICommentsService     commentsService = testingContext.GetService <CommentsService>();

            Question   question   = appDbContext.Questions.First();
            CommentDto commentDto = new CommentDto()
            {
                IdQuestion  = question.Id,
                CommentText = "Hello Comment",
            };

            //Act
            int newId = await commentsService.AddCommentAsync(commentDto);

            Assert.True(newId > 0);
        }
Exemple #7
0
 public async Task <int> AddComment([FromBody] CommentDto vm)
 {
     return(await _commentsService.AddCommentAsync(vm));
 }