public async Task GetCommentByIdShouldReturnComment() { // Arrange var db = this.GetDatabase(); var comment = new Comment { Id = "slihdbflisdbnfawef", MovieId = "lihsbdfjsndfsf", UserId = "s;lkdf;sldfkg" }; db.AddRange(comment); await db.SaveChangesAsync(); var commentsService = new CommentsService(db); // Act var result = commentsService.GetCommentById(comment.Id); // Assert result .Should() .Be(comment); }
public IActionResult GetCommentById(int commentId) { try { var comment = _commentsService.GetCommentById(commentId); return(Ok(comment)); } catch (Exception) { return(NotFound()); } }
public void GetCommentByIdShouldReturnComment() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "GetCommentId_Roads_Comments_Database") .Options; var dbContext = new ApplicationDbContext(options); var roadsService = new RoadsService(dbContext, null, null, null, null, null); var commentsService = new CommentsService(roadsService, dbContext); var road = new Road { Id = "Road1", RoadName = "Lorem", Comments = new List <Comment> { new Comment { Id = "commentId1", Content = "comment1" }, new Comment { Id = "commentId2", Content = "comment2" } } }; dbContext.Roads.Add(road); dbContext.SaveChanges(); var comment = commentsService.GetCommentById("commentId1"); Assert.Equal("comment1", comment.Content); Assert.NotNull(comment); }
// GET: Comments/Details/5 public IActionResult Details(Guid id) { var comment = _service.GetCommentById(id); return(View(comment)); }