public async Task EditAsync_WithCorrectData_ShouldSuccessfullyEdit() { var testContent = "TestContent"; // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var replyRepository = new EfDeletableEntityRepository <Reply>(context); var repliesService = new RepliesService(replyRepository); var inputModel = new CreateReplyInputModel() { Content = testContent, }; await repliesService.CreateAsync(inputModel); var reply = replyRepository.All().FirstOrDefault(c => c.Content == testContent); // Act var expectedReplyContent = "Edited_TestContent"; await repliesService.EditAsync(reply.Id, expectedReplyContent); var actualReplyContent = reply.Content; // Assert reply = await replyRepository.GetByIdWithDeletedAsync(reply.Id); Assert.Equal(expectedReplyContent, actualReplyContent); }
public async Task Create(CreateReplyInputModel input) { Reply reply = new Reply { Content = input.Content, CommentId = input.CommentId, AuthorId = input.AuthorId, }; await this.repliesRepository.AddAsync(reply); await this.repliesRepository.SaveChangesAsync(); }
public async Task CreateAsync(CreateReplyInputModel input) { var comment = new Reply() { Content = input.Content, AuthorId = input.AuthorId, TopicId = input.TopicId, RootCommentId = input.RootCommentId, }; await this.replyRepository.AddAsync(comment); await this.replyRepository.SaveChangesAsync(); }
public async Task <IActionResult> Create(string id, CreateReplyInputModel input) { if (!this.ModelState.IsValid) { return(this.Redirect($"/Replies/Create/{id}")); } ApplicationUser user = await this.userManager.GetUserAsync(this.User); input.CommentId = id; input.AuthorId = user.Id; await this.repliesService.Create(input); return(this.Redirect("/")); }
public async Task <IActionResult> Create(CreateReplyInputModel input) { if (this.User.IsInRole(GlobalConstants.BannedRoleName)) { return(this.View("Banned")); } if (!this.ModelState.IsValid) { return(this.Redirect($"/Topics/Details?topicId={input.TopicId}")); } var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); input.AuthorId = userId; await this.repliesService.CreateAsync(input); return(this.Redirect($"/Topics/Details?topicId={input.TopicId}")); }
public async Task CreateAsync_ShouldSuccessfullyCreate() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var replyRepository = new EfDeletableEntityRepository <Reply>(context); var repliesService = new RepliesService(replyRepository); var inputModel = new CreateReplyInputModel() { Content = "TestContent", }; // Act var expectedRepliesCount = 1; await repliesService.CreateAsync(inputModel); var actualRepliesCount = replyRepository.All().Count(); // Assert Assert.Equal(expectedRepliesCount, actualRepliesCount); }