예제 #1
0
        public async Task DeleteShouldDeleteComment()
        {
            // Arrange
            var db = this.GetDatabase();

            var comment = new Comment()
            {
                Title = "asdfgw56y345h",
                Text  = "dfgsdfgsdfgf"
            };


            db.AddRange(comment);

            await db.SaveChangesAsync();

            var commentsService = new CommentsService(db);

            // Act
            var result = await commentsService.Delete(comment);

            // Assert
            result.Succeeded
            .Should()
            .Be(true);

            db.Comments
            .Should()
            .BeEmpty();
        }
예제 #2
0
        public async Task DeleteCommentDeletesOneComment()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

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

            var bookId = 3;

            var comment1 = new Comment
            {
                UserId  = "gudId1",
                BookId  = bookId,
                Content = "content of the comment1.",
            };

            var comment2 = new Comment
            {
                UserId  = "gudId2",
                BookId  = bookId,
                Content = "content of the comment2.",
            };

            await repository.AddAsync(comment1);

            await repository.AddAsync(comment2);

            await repository.SaveChangesAsync();

            await service.Delete(comment1.Id);

            Assert.Equal(1, repository.All().Count());
        }
예제 #3
0
        public void DeleteShouldDeleteAGivenComment()
        {
            var options = new DbContextOptionsBuilder <TasksDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(DeleteShouldDeleteAGivenComment))
                          .Options;

            using (var context = new TasksDbContext(options))
            {
                var commentsService = new CommentsService(context);
                var toAdd           = new CommentPostDTO()

                {
                    Important = true,
                    Text      = "A nice task...",
                };


                var actual               = commentsService.Create(toAdd, null);
                var afterDelete          = commentsService.Delete(actual.Id);
                int numberOfCommentsInDb = context.Comments.CountAsync().Result;
                var resultComment        = context.Comments.Find(actual.Id);


                Assert.IsNotNull(afterDelete);
                Assert.IsNull(resultComment);
                Assert.AreEqual(0, numberOfCommentsInDb);
            }
        }
예제 #4
0
        public ICollection <int> Delete(int id)
        {
            var ids = _service.Delete(id);

            _unitOfWork.Save();
            return(ids);
        }
예제 #5
0
        public async void Delete_ShouldThrowKeyNotFoundException_IfInvalidIdIsGiven()
        {
            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);

            var  expected = typeof(KeyNotFoundException);
            Type actual   = null;

            try
            {
                //do
                await service.Delete(3);
            }
            catch (KeyNotFoundException e)
            {
                actual = e.GetType();
            }

            //assert
            Assert.Equal(expected, actual);
        }
예제 #6
0
        // GET: Product/Delete/5
        public ActionResult Delete(int id)
        {
            Comment p;

            p = Cs.GetById(id);
            Cs.Delete(p);
            Cs.Commit();
            return(RedirectToAction("Indexx"));
        }
예제 #7
0
        public async Task <ActionResult <Comments> > Delete(int id)
        {
            var entity = await _service.Delete(id);

            if (entity == null)
            {
                return(NotFound());
            }
            return(Ok(entity));
        }
예제 #8
0
 [HttpDelete("{id}")] //Delort
 public ActionResult <string> DeleteComments(string id)
 {
     try
     {
         return(Ok(_service.Delete(id)));
     }
     catch (System.Exception err)
     {
         return(BadRequest(err.Message));
     }
 }
예제 #9
0
 public ActionResult <string> Delete(int id)
 {
     try
     {
         return(Ok(_cs.Delete(id)));
     }
     catch (System.Exception error)
     {
         return(BadRequest(error.Message));
     }
 }
예제 #10
0
 public async Task<ActionResult<Comment>> DeleteAsync(int id)
 {
     try
     {
         Profile userInfo = await HttpContext.GetUserInfoAsync<Profile>();
         return Ok(_cservice.Delete(id, userInfo.Id));
     }
     catch (System.Exception e)
     {
         return BadRequest(e.Message);
     }
 }
예제 #11
0
        public async Task <ActionResult <string> > Delete(int id)
        {
            try
            {
                Profile userInfo = await HttpContext.GetUserInfoAsync <Profile>();

                return(Ok(_cs.Delete(id, userInfo.Id)));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
예제 #12
0
 public ActionResult <Comment> Delete(int id)
 {
     try
     {
         string userId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
         // NOTE DONT TRUST THE USER TO TELL YOU WHO THEY ARE!!!!
         return(Ok(_service.Delete(id, userId)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
예제 #13
0
        public async Task <ActionResult <Comment> > Delete(int id)
        {
            try
            {
                Account userInfo = await HttpContext.GetUserInfoAsync <Account>();

                _cService.Delete(id, userInfo.Id);
                return(Ok("Successfully Deleted"));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
예제 #14
0
        public async Task Delete_WithIncorrectId_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 model = new CommentEditModel();

            model.Id = id;

            await Assert.ThrowsAsync <NullReferenceException>(() => service.Delete(model));
        }
예제 #15
0
        public async Task <ActionResult <Comment> > Delete(int id)
        {
            try
            {
                // TODO[epic=Auth] Get the user info to set the creatorID
                Account userInfo = await HttpContext.GetUserInfoAsync <Account>();

                // safety to make sure an account exists for that user before DELETE-ing stuff.
                _service.Delete(id, userInfo.Id);
                return(Ok("Successfulyl Deleted!"));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
예제 #16
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <ICommentsRepository>();
            var model = new ApiCommentsRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new CommentsService(mock.LoggerMock.Object,
                                              mock.RepositoryMock.Object,
                                              mock.ModelValidatorMockFactory.CommentsModelValidatorMock.Object,
                                              mock.BOLMapperMockFactory.BOLCommentsMapperMock,
                                              mock.DALMapperMockFactory.DALCommentsMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.CommentsModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
예제 #17
0
        public async void TestDelete()
        {
            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);

            await commentsService.Create(1, userId, "testContent2", 1);

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

            await commentsService.Delete(1, 1);

            var commentsCount = commentsService.GetByUserId <MyTestComment>(userId).Count();

            Assert.Equal(0, commentsCount);
        }
예제 #18
0
        public async Task Delete_WithCorrectId_ShouldRemoveComment()
        {
            MapperInitializer.InitializeMapper();
            var dbContext = ApplicationDbContextCreatorInMemory.InitializeContext();

            await this.CreateTestComments(dbContext);

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

            var model = new CommentEditModel();

            model.Id = 1;

            await service.Delete(model);

            var result = repository.AllWithDeleted().Where(p => p.Id == 1).FirstOrDefault().IsDeleted;

            Assert.True(result);
        }
        public async Task DeleteShouldBeSuccessfull()
        {
            var options = new DbContextOptionsBuilder <SportsNewsContext>()
                          .UseInMemoryDatabase(databaseName: "CommentsTests")
                          .Options;

            var dbContext = new SportsNewsContext(options);

            var repository      = new DbRepository <Comment>(dbContext);
            var commentsService = new CommentsService(repository);

            await commentsService.Create(1, "1", "dasasd");

            await commentsService.Create(1, "2", "dasasd");

            var id = repository.All().FirstOrDefault().Id;
            await commentsService.Delete(id);

            var count = repository.All().Count();

            Assert.Equal(2, count);
        }
 public void DeleteCommentTest()
 {
     _commentsService.Delete(1);
     _mock.Verify(item => item.Delete(1), Times.Once());
 }