示例#1
0
 [HttpPut("{commentssId}")] //EDIT
 public ActionResult <Comment> editComments(string commentId, Comment editComments)
 {
     try
     {
         editComments.CommentId = commentId;
         return(Ok(_service.Edit(editComments)));
     }
     catch (System.Exception err)
     {
         return(BadRequest(err.Message));
     }
 }
示例#2
0
 public ActionResult <Comment> Edit(int id, [FromBody] Comment updatedComment)
 {
     try
     {
         string userId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
         // NOTE DONT TRUST THE USER TO TELL YOU WHO THEY ARE!!!!
         updatedComment.AuthorId = userId;
         updatedComment.Id       = id;
         return(Ok(_service.Edit(updatedComment)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
示例#3
0
 public async Task<ActionResult<Comment>> EditAsync([FromBody] Comment editData, int id)
 {
     try
     {
         Profile userInfo = await HttpContext.GetUserInfoAsync<Profile>();
         editData.Id = id;
         editData.CreatorId = userInfo.Id;
         Comment editedComment = _cservice.Edit(editData);
         return Ok(editedComment);
     }
     catch (System.Exception e)
     {
         return BadRequest(e.Message);
     }
 }
示例#4
0
        public async Task <ActionResult <Comment> > Edit([FromBody] Comment updated, int id)
        {
            try
            {
                Profile userInfo = await HttpContext.GetUserInfoAsync <Profile>();

                updated.Id      = id;
                updated.Creator = userInfo;
                return(Ok(_cs.Edit(updated, userInfo.Id)));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
示例#5
0
        public async void TestEdit()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var repository      = new EfDeletableEntityRepository <Comment>(new ApplicationDbContext(options.Options));
            var commentsService = new CommentsService(repository);
            var userId          = Guid.NewGuid().ToString();
            await commentsService.Create(1, userId, "testContent", 0);

            AutoMapperConfig.RegisterMappings(typeof(MyTestComment).Assembly);

            await commentsService.Edit(1, "editedContent");

            var editedComment = commentsService.GetByUserId <MyTestComment>(userId).FirstOrDefault();

            Assert.Equal("editedContent", editedComment.Content);
        }
        public async Task Edit_WithInvalidId_ShouldThrowException(int id)
        {
            MapperInitializer.InitializeMapper();
            var dbContext = ApplicationDbContextCreatorInMemory.InitializeContext();

            await this.CreateTestComments(dbContext);

            var repository = new EfDeletableEntityRepository <Comment>(dbContext);
            var service    = new CommentsService(repository);

            var viewModel = new CommentEditModel()
            {
                Id = id,
            };

            await Assert.ThrowsAsync <NullReferenceException>(() => service.Edit(viewModel));
        }
        public async Task Edit_WithValidInput_ShouldChangeContent()
        {
            MapperInitializer.InitializeMapper();
            var dbContext = ApplicationDbContextCreatorInMemory.InitializeContext();

            await this.CreateTestComments(dbContext);

            var repository = new EfDeletableEntityRepository <Comment>(dbContext);
            var service    = new CommentsService(repository);

            var viewModel = new CommentEditModel()
            {
                Id      = 1,
                Content = "Edited",
            };

            await service.Edit(viewModel);

            var comment = service.GetById <CommentEditModel>(1);

            Assert.Equal("Edited", comment.Content);
        }
示例#8
0
        public void Edit_ShouldEditCommentAndReturnId()
        {
            Mapper.Initialize(x => x.AddProfile <MapperConfiguration>());
            var repo     = new Mock <IRepository <Comment> >();
            var comments = GetTestData().AsQueryable();

            repo.Setup(r => r.All()).Returns(comments);
            var service = new CommentsService(repo.Object);

            //do
            var model = new CommentViewModel
            {
                Id        = 1,
                Content   = "sssjjjsss",
                ProductId = 1,
                UserId    = "asd"
            };
            var result = service.Edit(model);

            //assert
            result.Should().NotBeNull().And.BeOfType <Task <int> >();
            //TODO: check if its updated
        }