public async Task GetAsync_GetAllNews_ReturnAllNews() { // Arrange var expectedNewsCollection = new NewsCollection().Data; Use <INewsRepository>() .Setup(s => s.QueryAsync(It.IsAny <NewsSpecifications>())) .ReturnsAsync(expectedNewsCollection); // Act var actualResult = await Sub.GetAsync(); // Assert CollectionAssert.AreEqual(expectedNewsCollection, actualResult); }
public async Task GetAsync_FindAllCommentsByNewsId_ReturnCommentsForNews(int newsId) { // Arrange var expectedCommentsCollection = new NewsCollection().Data .First(w => w.Id == newsId) .Comments; Use <ICommentsRepository>() .Setup(s => s.QueryAsync(It.IsAny <CommentSpecifications>())) .ReturnsAsync(expectedCommentsCollection); // Act var actualResult = await Sub.GetAsync(newsId); // Assert CollectionAssert.AreEqual(expectedCommentsCollection, actualResult); }
public async Task GetAsync_FindNonExistentNews_ReturnNotFound(int newsId) { // Arrange var expectedNewsQuery = new NewsCollection().Data .Where(w => w.Id == newsId) .ToList(); Use <INewsRepository>() .Setup(s => s.QueryAsync(It.IsAny <NewsSpecifications>())) .ReturnsAsync(expectedNewsQuery); // Act var actualResult = await Sub.GetAsync(newsId); // Assert Assert.IsInstanceOf <NotFoundResult>(actualResult); }
public async Task GetAsync_FindNonExistentComment_ReturnNotFound(int newsId, int commentId) { // Arrange var expectedCommentQuery = new NewsCollection().Data .FirstOrDefault(w => w.Id == newsId) ?.Comments.Where(w => w.Id == commentId) .ToList() ?? new List <Comment>(); Use <ICommentsRepository>() .Setup(s => s.QueryAsync(It.IsAny <CommentSpecifications>())) .ReturnsAsync(expectedCommentQuery); // Act var actualResult = await Sub.GetAsync(newsId, commentId); // Assert Assert.IsInstanceOf <NotFoundResult>(actualResult); }
public async Task GetAsync_FindNewsById_ReturnNews(int newsId) { // Arrange var expectedNewsQuery = new NewsCollection().Data .Where(w => w.Id == newsId) .ToList(); var expectedNews = expectedNewsQuery.First(); Use <INewsRepository>() .Setup(s => s.QueryAsync(It.IsAny <NewsSpecifications>())) .ReturnsAsync(expectedNewsQuery); // Act var actualResult = await Sub.GetAsync(newsId); // Assert Assert.IsInstanceOf <ObjectResult>(actualResult); var newsFromResponse = (News)((ObjectResult)actualResult).Value; Assert.AreEqual(expectedNews, newsFromResponse); }
public async Task GetAsync_FindCommentById_ReturnComment(int newsId, int commentId) { // Arrange var expectedCommentQuery = new NewsCollection().Data .First(w => w.Id == newsId) .Comments.Where(w => w.Id == commentId) .ToList(); var expectedComment = expectedCommentQuery.First(); Use <ICommentsRepository>() .Setup(s => s.QueryAsync(It.IsAny <CommentSpecifications>())) .ReturnsAsync(expectedCommentQuery); // Act var actualResult = await Sub.GetAsync(newsId, commentId); // Assert Assert.IsInstanceOf <ObjectResult>(actualResult); var commentFromResponse = (Comment)((ObjectResult)actualResult).Value; Assert.AreEqual(expectedComment, commentFromResponse); }