public async void GetReviewTest() { mockIRepo.Setup(x => x.GetReviewAsync(-1)).Verifiable(); var nullReview = await reviewsController.GetReview(-1); nullReview.Result.Should().BeOfType <NotFoundResult>(); }
public void GetReviewByIdWhenFoundReviewNull() { // ARRANGE - make actual list of reviews var dummyReviews = GenerateReviews(); var _reviewSet = MockingHelper.Create(dummyReviews); _db.Setup(x => x.Reviews).Returns(_reviewSet.Object); var dummyId = 3; // ACT var result = _controller.GetReview(dummyId); // ASSERT - if the review cannot be found, the return result type is NotFoundResult Assert.AreEqual(typeof(NotFoundResult), result.GetType()); }
public async Task GetReview_ReturnsNotFound_GivenInvalidId() { // arrange var controller = new ReviewsController(_context); // act var result = await controller.GetReview(90); // assert Assert.IsType <NotFoundResult>(result); }
public async Task GetReview_ReturnsReview_GivenValidId() { // arrange var controller = new ReviewsController(_context); // act var result = await controller.GetReview(1); // assert var objectResult = Assert.IsType <OkObjectResult>(result); var review = Assert.IsAssignableFrom <Review>(objectResult.Value); Assert.Equal("Test1", review.Description); }
public async Task GetReview_NonexistentZeroId_NotFoundResult() { // Arrange const int reviewId = 0; InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList()); // Act using (var context = new GameReviewsContext(options)) { ReviewsController reviewsController = new ReviewsController(context); var result = (await reviewsController.GetReview(reviewId)).Result; // Assert Assert.IsType <NotFoundResult>(result); } }
public async Task GetReview_ExistingId_TaskActionResultContainsReview() { // Arrange const int reviewId = 3; Review expectedReview = GetFakeList().Where(d => d.ID == reviewId).FirstOrDefault(); InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList()); // Act using (var context = new GameReviewsContext(options)) { ReviewsController reviewsController = new ReviewsController(context); var actionResult = await reviewsController.GetReview(reviewId); Review review = actionResult.Value; ActionResult result = actionResult.Result; // Assert Assert.True(AreEqual(expectedReview, review)); Assert.IsNotType <NotFoundResult>(result); } }