public void ReturnGetRating_WhenRatingExists_OnCallToGetRating() { var id = 1; var ratingRepository = A.Fake <IRatingRepository>(); A.CallTo(() => ratingRepository.RatingExists(id)).Returns(true); var controller = new RatingsController(ratingRepository, null, null, null); var response = controller.GetRating(id); A.CallTo(() => ratingRepository.GetRating(id)).MustHaveHappened(); }
public void TestMethodGet() { var context = new TestBankDBContext(); context.Ratings.Add(GetSingleItem()); var controller = new RatingsController(context); var result = controller.GetRating(1) as OkNegotiatedContentResult <Rating>; Assert.IsNotNull(result); Assert.AreEqual(1, result.Content.Id); }
public void ReturnBadRequest_WhenRatingDoesNotExist_OnCallToGetRating() { var id = 1; var ratingRepository = A.Fake <IRatingRepository>(); A.CallTo(() => ratingRepository.RatingExists(id)).Returns(false); var controller = new RatingsController(ratingRepository, null, null, null); var response = controller.GetRating(id); Assert.AreEqual((int)HttpStatusCode.BadRequest, ((BadRequestObjectResult)response.Result).StatusCode); Assert.AreEqual($"Rating with Id {id} does not exist.", ((BadRequestObjectResult)response.Result).Value); }
public void GetRating_ReturnNotFoundIfRatingIsNone() { //Arrange Mock <IRepository <Movie> > mockIRepository = new Mock <IRepository <Movie> >(); Mock <IRatingRepository> mockRatingRepository = new Mock <IRatingRepository>(); mockRatingRepository.Setup(r => r.GetRating(It.IsAny <int>(), It.IsAny <int>())) .Returns((int userId, int movieId) => ratings.Where(x => x.movieId == movieId && x.userId == userId).SingleOrDefault()); var controller = new RatingsController(mockRatingRepository.Object, mockIRepository.Object); //Act var result = controller.GetRating(23, 1).Result; //Assert Assert.IsInstanceOf <NotFoundResult>(result); }
public void GetRating_GetRatingByUserIdAndMovieId() { //Arrange Mock <IRepository <Movie> > mockIRepository = new Mock <IRepository <Movie> >(); Mock <IRatingRepository> mockRatingRepository = new Mock <IRatingRepository>(); mockRatingRepository.Setup(r => r.GetRating(It.IsAny <int>(), It.IsAny <int>())) .Returns((int userId, int movieId) => ratings.Where(x => x.movieId == movieId && x.userId == userId).SingleOrDefault()); var controller = new RatingsController(mockRatingRepository.Object, mockIRepository.Object); //Act Rating rating = (Rating)controller.GetRating(1, 1).Value; //Assert Assert.AreEqual(ratings[0], rating); }
public void GetExistingRating_ReturnRatingScore() { int expectedScore = 4; var options = new DbContextOptionsBuilder <DataContext>() .UseInMemoryDatabase(databaseName: "GetRatingsDataBase") .Options; var context = new DataContext(options); RatingsController ratingsController = new RatingsController(context); context.Add(new Rating() { MovieId = 1, UserId = 1, Score = 4 }); context.SaveChanges(); string jwt = UserManagementMicroservice.JWT.CreateJWT(1, 1); var score = ratingsController.GetRating(1, jwt).Value; Assert.Equal(expectedScore, score); }