public async Task Delete_ValidId_RemoveWasCalled() { await _service.Delete(1); _mockSet.Verify(m => m.Remove(It.IsAny <Comment>()), Times.Once()); _mockContext.Verify(m => m.SaveChangesAsync(), Times.Once()); }
public void Delete_Comment_With_Wrong_Id() { // Arrange const int WrongId = 234; // Act _commentService.Delete(WrongId); }
public void DeleteComment_ExistedCommentId_UpdateCalled() { _uow.Setup(uow => uow.Comments.GetById(_fakeCommentId)).Returns(_fakeComment); _uow.Setup(uow => uow.Comments.GetAll()).Returns(_fakeComments); _sut.Delete(_fakeCommentId); _uow.Verify(uow => uow.Comments.Update(_fakeComment), Times.Once); }
public void Delete_Existing_returnTrue() { mockUnitOfWork.Setup(u => u.CommentsRepository.Get(new Guid("93f0c600-9c1b-48b4-9606-08d7141a36bb"))).Returns(new Comments() { Id = new Guid("93f0c600-9c1b-48b4-9606-08d7141a36bb"), Text = "Text", EventId = new Guid("d3994f53-1e0d-4eda-d0e8-08d70c4f9464"), UserId = new Guid("19824dd6-67bf-4a52-24a7-08d705fcf8d4"), Date = new DateTime(2019, 08, 08) }); var rez = service.Delete(new Guid("93f0c600-9c1b-48b4-9606-08d7141a36bb")); Assert.IsTrue(rez.Result.Successed); }
public void DeleteShouldDeleteAGivenComment() { var options = new DbContextOptionsBuilder <ExpensesDbContext>() .UseInMemoryDatabase(databaseName: nameof(DeleteShouldDeleteAGivenComment)) .Options; using (var context = new ExpensesDbContext(options)) { var commentsService = new CommentService(context); var toAdd = new CommentPostModel() { Important = true, Text = "An important expense", }; 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); } }
public void ShouldBeErrorIfNoKeyDelete() { string encryptionKey = null; DBResult <UserProfile> profileDBResult = new DBResult <UserProfile> { Payload = new UserProfile() { EncryptionKey = encryptionKey } }; Mock <IUserProfileDelegate> profileDelegateMock = new Mock <IUserProfileDelegate>(); profileDelegateMock.Setup(s => s.GetUserProfile(hdid)).Returns(profileDBResult); UserComment userComment = new UserComment() { UserProfileId = hdid, ParentEntryId = parentEntryId, Text = "Deleted Comment", EntryTypeCode = Database.Constants.CommentEntryType.Medication, CreatedDateTime = new DateTime(2020, 1, 1) }; ICommentService service = new CommentService( new Mock <ILogger <CommentService> >().Object, new Mock <ICommentDelegate>().Object, profileDelegateMock.Object, new Mock <ICryptoDelegate>().Object ); RequestResult <UserComment> actualResult = service.Delete(userComment); Assert.Equal(ResultType.Error, actualResult.ResultStatus); }
public async Task DeleteTest() { var fakeRepository = Mock.Of <ICommentRepository>(); var CommentService = new CommentService(fakeRepository); int CommentId = 1; await CommentService.Delete(CommentId); }
public override void ExtraDelete(Project project) { TaskService TaskService = new TaskService(); List <Task> tasks = TaskService.GetAll(t => t.ProjectId == project.Id).ToList(); foreach (var item in tasks) { CommentService CommentService = new CommentService(); List <Comment> comments = CommentService.GetAll(c => c.TaskId == item.Id).ToList(); foreach (var coment in comments) { CommentService.Delete(coment); } TaskService.Delete(item); } Project_ReportService Project_ReportService = new Project_ReportService(); List <Project_Report> Project_Reports = Project_ReportService.GetAll(r => r.ProjectId == project.Id).ToList(); foreach (var Project_Report in Project_Reports) { Project_ReportService.Delete(Project_Report); } }
public ActionResult DeleteCommentConfirmed(int id) { Comment post = CommentService.Get(id); CommentService.Delete(id); return(RedirectToAction("Index")); }
public void DeleteTest() { var options = new DbContextOptionsBuilder <MoviesDbContext>() .UseInMemoryDatabase(databaseName: nameof(DeleteTest)) .Options; using (var context = new MoviesDbContext(options)) { var commentService = new CommentService(context); var movieService = new MovieService(context); var addedMovie = movieService.Create(new Lab3Movie.ViewModels.MoviePostModel { Title = "movie 1", Description = "agfas", Genre = "comedy", DurationInMinutes = 100, YearOfRelease = 2019, Director = "director1", Rating = 10, Watched = "yes", DateAdded = new DateTime(), Comments = new List <Comment>() { new Comment { Text = "text", Important = true, Owner = null } }, }, null); var addedComment = commentService.Create(new Lab3Movie.ViewModels.CommentPostModel { Important = true, Text = "fdlkflsdkm", }, addedMovie.Id); var comment = commentService.Delete(addedComment.Id); var commentNull = commentService.Delete(17); Assert.IsNull(commentNull); Assert.NotNull(comment); } }
public ActionResult Delete(int id, comment comment) { comment c2 = c.FindById(id); c.Delete(c2); c.Commit(); return(RedirectToAction("DetailPost", "Post", new { id = c2.idPost })); }
public override void ExtraDelete(Task task) { CommentService CommentService = new CommentService(); List <Comment> comments = CommentService.GetAll(c => c.TaskId == task.Id).ToList(); foreach (var coment in comments) { CommentService.Delete(coment); } }
public void DeleteTest() { var options = new DbContextOptionsBuilder <TasksDbContext>() .UseInMemoryDatabase(databaseName: nameof(DeleteTest)) .Options; using (var context = new TasksDbContext(options)) { var commentService = new CommentService(context); var taskService = new TaskService(context); var addedTask = taskService.Create(new TaskAgendaProj.ViewModels.TaskPostModel { Title = "task de test 1", Description = "agfas", DateTimeAdded = new DateTime(), Deadline = new DateTime(), Importance = "high", Status = "in_progress", DateTimeClosedAt = new DateTime(), Comments = new List <Comment>() { new Comment { Important = true, Text = "asd", Owner = null } }, }, null); var addedComment = commentService.Create(new TaskAgendaProj.ViewModels.CommentPostModel { Important = true, Text = "fdlkflsdkm", }, addedTask.Id); var comment = commentService.Delete(addedComment.Id); var commentNull = commentService.Delete(17); Assert.IsNull(commentNull); Assert.NotNull(comment); } }
public void DeleteTest() { var options = new DbContextOptionsBuilder <ExpensesDbContext>() .UseInMemoryDatabase(databaseName: nameof(DeleteTest)) .Options; using (var context = new ExpensesDbContext(options)) { var commentService = new CommentService(context); var expenseService = new ExpenseService(context); var addedExpense = expenseService.Create(new Lab2Expense.ViewModels.ExpensePostModel { Description = "jshdkhsakjd", Sum = 1.23, Location = "jsfkdsf", Date = new DateTime(), Currency = "euro", ExpenseType = "food", Comments = new List <Comment>() { new Comment { Important = true, Text = "asd", Owner = null } }, }, null); var addedComment = commentService.Create(new Lab2Expense.ViewModels.CommentPostModel { Important = true, Text = "fdlkflsdkm", }, addedExpense.Id); var comment = commentService.Delete(addedComment.Id); var commentNull = commentService.Delete(17); Assert.IsNull(commentNull); Assert.NotNull(comment); } }
// GET: Comment/Delete/5 public ActionResult Delete(int id) { CommentService commserv = new CommentService(); comment c = new comment(); c = commserv.GetById(id); commserv.Delete(c); commserv.Commit(); return(RedirectToAction("report")); }
public void DeleteComment(int Id, string CommentText, int UsernameId, int NewsId) { Comment comment = new Comment() { Id = Id, Comment_Text = CommentText, UsernameId = UsernameId, NewsId = NewsId }; commentService.Delete(comment); }
public void TestDelete() { string id = "5d027ea59b358d247cd219a0"; mockCommentRepository.Setup(x => x.GetById(It.IsAny <string>())).Returns(cmt); mockCommentRepository.Setup(x => x.Delete(It.IsAny <string>())).Returns(true); mockPostRepository.Setup(x => x.DecreaseCommentCount(It.IsAny <string>())).Returns(true); var testService = new CommentService(mockCommentRepository.Object, mockPostRepository.Object, Options.Create(_setting)); bool result = testService.Delete(id); Assert.IsTrue(result); }
public void Delete_WhenDeleteComment_ThenInvokeDeleteByRepository() { // Arrange var commentId = Guid.NewGuid(); var service = new CommentService(_unitOfWorkFake, _mapper, _validator); service.Delete(commentId); // Act - Assert A.CallTo(() => _unitOfWorkFake.CommentRepository.Delete(commentId)).MustHaveHappened(); }
public ActionResult DeleteComment(int user, int post, int comment) { TempData["user"] = user; TempData["post"] = post; var currentComment = commentService.GetAll().Where(x => x.Id == comment).FirstOrDefault(); if (currentComment.AuthorId == user) { commentService.Delete(comment); } return(RedirectToAction("GetPost", "Post", new { user = TempData["user"], post = TempData["post"] })); }
public void Delete_WithNotExistingCommentId_ShouldReturnFalse() { // Arrange StarStuffDbContext db = this.Database; CommentService commentService = new CommentService(db); // Act bool result = commentService.Delete(1); // Assert Assert.False(result); }
public void ShouldDeleteComment() { string encryptionKey = "abc"; DBResult <UserProfile> profileDBResult = new DBResult <UserProfile> { Payload = new UserProfile() { EncryptionKey = encryptionKey } }; Mock <IUserProfileDelegate> profileDelegateMock = new Mock <IUserProfileDelegate>(); profileDelegateMock.Setup(s => s.GetUserProfile(hdid)).Returns(profileDBResult); Mock <ICryptoDelegate> cryptoDelegateMock = new Mock <ICryptoDelegate>(); cryptoDelegateMock.Setup(s => s.Encrypt(It.IsAny <string>(), It.IsAny <string>())).Returns((string key, string text) => text + key); cryptoDelegateMock.Setup(s => s.Decrypt(It.IsAny <string>(), It.IsAny <string>())).Returns((string key, string text) => text.Remove(text.Length - key.Length)); UserComment userComment = new UserComment() { UserProfileId = hdid, ParentEntryId = parentEntryId, Text = "Deleted Comment", EntryTypeCode = CommentEntryType.Medication, CreatedDateTime = new DateTime(2020, 1, 1) }; Comment comment = userComment.ToDbModel(cryptoDelegateMock.Object, encryptionKey); DBResult <Comment> deleteResult = new DBResult <Comment> { Payload = comment, Status = DBStatusCode.Deleted }; Mock <ICommentDelegate> commentDelegateMock = new Mock <ICommentDelegate>(); commentDelegateMock.Setup(s => s.Delete(It.Is <Comment>(x => x.Text == comment.Text), true)).Returns(deleteResult); ICommentService service = new CommentService( new Mock <ILogger <CommentService> >().Object, commentDelegateMock.Object, profileDelegateMock.Object, cryptoDelegateMock.Object ); RequestResult <UserComment> actualResult = service.Delete(userComment); Assert.Equal(Common.Constants.ResultType.Success, actualResult.ResultStatus); Assert.True(actualResult.ResourcePayload.IsDeepEqual(userComment)); }
public IActionResult Delete(string id) { var Comment = _CommentService.Get(id); if (Comment == null) { return(NotFound()); } _CommentService.Delete(Comment.Id); return(NoContent()); }
private Tuple <RequestResult <UserComment>, UserComment> ExecuteDeleteComment(Database.Constants.DBStatusCode dBStatusCode = Database.Constants.DBStatusCode.Deleted) { string encryptionKey = "abc"; DBResult <UserProfile> profileDBResult = new DBResult <UserProfile> { Payload = new UserProfile() { EncryptionKey = encryptionKey } }; Mock <IUserProfileDelegate> profileDelegateMock = new Mock <IUserProfileDelegate>(); profileDelegateMock.Setup(s => s.GetUserProfile(hdid)).Returns(profileDBResult); Mock <ICryptoDelegate> cryptoDelegateMock = new Mock <ICryptoDelegate>(); cryptoDelegateMock.Setup(s => s.Encrypt(It.IsAny <string>(), It.IsAny <string>())).Returns((string key, string text) => text + key); cryptoDelegateMock.Setup(s => s.Decrypt(It.IsAny <string>(), It.IsAny <string>())).Returns((string key, string text) => text.Remove(text.Length - key.Length)); UserComment userComment = new UserComment() { UserProfileId = hdid, ParentEntryId = parentEntryId, Text = "Deleted Comment", EntryTypeCode = CommentEntryType.Medication, CreatedDateTime = new DateTime(2020, 1, 1) }; Comment comment = userComment.ToDbModel(cryptoDelegateMock.Object, encryptionKey); DBResult <Comment> deleteResult = new DBResult <Comment> { Payload = comment, Status = dBStatusCode }; Mock <ICommentDelegate> commentDelegateMock = new Mock <ICommentDelegate>(); commentDelegateMock.Setup(s => s.Delete(It.Is <Comment>(x => x.Text == comment.Text), true)).Returns(deleteResult); ICommentService service = new CommentService( new Mock <ILogger <CommentService> >().Object, commentDelegateMock.Object, profileDelegateMock.Object, cryptoDelegateMock.Object ); RequestResult <UserComment> actualResult = service.Delete(userComment); return(new Tuple <RequestResult <UserComment>, UserComment>(actualResult, userComment)); }
public ActionResult <Comment> Delete(int Id) { try { string email = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; return(Ok(_service.Delete(Id, email))); } catch (UnauthorizedAccessException e) { return(Unauthorized(e.Message)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public void Delete_WithExistingCommentId_ShouldDeleteComment() { // Arrange StarStuffDbContext db = this.Database; CommentService commentService = new CommentService(db); this.SeedCommanets(db); const int commentId = 1; // Act commentService.Delete(commentId); // Assert Assert.False(db.Comments.Any(c => c.Id == commentId)); }
public override void ExtraDelete(Employee employee) { TaskService TaskService = new TaskService(); List <Task> tasks = TaskService.GetAll(t => t.AssignetId == employee.Id && t.Status != "Resolved").ToList(); foreach (var item in tasks) { TaskService.Delete(item); } CommentService CommentService = new CommentService(); List <Comment> comments = CommentService.GetAll(c => c.CreatorId == employee.Id).ToList(); foreach (var item in comments) { CommentService.Delete(item); } }
public async void Delete() { var mock = new ServiceMockFacade <ICommentRepository>(); var model = new ApiCommentRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new CommentService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.CommentModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLCommentMapperMock, mock.DALMapperMockFactory.DALCommentMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.CommentModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public BaseResponse <bool> DeleteComment(int commentID, string token) { try { var user = UserService.GetUser(token); if (user != null) { var comment = CommentService.GetComment(commentID); if (comment != null && comment.UserID == user.UserID) { CommentService.Delete(new Models.Comment() { CommentID = commentID }); return(new BaseResponse <bool>() { Data = true, Message = "OK", Success = true }); } else { return new BaseResponse <bool>() { Data = false, Message = "User not found!", Success = false } }; } else { return(new BaseResponse <bool>() { Data = false, Message = "User not found!", Success = false }); } } catch (Exception ex) { return(new BaseResponse <bool>() { Data = false, Message = "Operation fail, try again!<!--" + ex.Message + "-->", Success = false }); } }
public ActionResult Delete(int id, FormCollection collection) { try { // TODO: Add delete logic here CommentService commserv = new CommentService(); comment c = new comment(); c = commserv.GetById(id); commserv.Delete(c); commserv.Commit(); return(RedirectToAction("report")); } catch { return(View()); } }
public void ProcessRequest(HttpContext context) { CommentService commentService = new CommentService(); context.Response.ContentType = "text/plain"; if (context.Request["CommentId"] != null) { int comid = Int32.Parse(context.Request["CommentId"]); bool b = commentService.Delete(comid); context.Response.Write(b); context.Response.End(); } else { string cids = context.Request["cids"]; bool b1 = commentService.DeleteList(cids); context.Response.Write(b1); context.Response.End(); } }