public async void GetAll_Success() { // Arrange var dbContext = _fixture.Context; var mapper = MapperMock.Get(); var user = NewDatas.NewUser(); var product = NewDatas.NewProduct(); var rating = NewDatas.NewRating(); rating.User = user; rating.Product = product; dbContext.Products.Add(product); await dbContext.SaveChangesAsync(); dbContext.Users.Add(user); await dbContext.SaveChangesAsync(); dbContext.Ratings.Add(rating); await dbContext.SaveChangesAsync(); var ratingsService = new RatingService(dbContext); var ratingsController = new RatingsController(ratingsService, mapper); // Act var result = await ratingsController.GetRatings(); // Assert var ratingResult = Assert.IsType <OkObjectResult>(result.Result); Assert.NotEmpty(ratingResult.Value as IEnumerable <Rating>); }
public void GetRatings_GetRatingsByMovieId() { //Arrange Mock <IRepository <Movie> > mockIRepository = new Mock <IRepository <Movie> >(); Mock <IRatingRepository> mockRatingRepository = new Mock <IRatingRepository>(); mockRatingRepository.Setup(r => r.GetRatings(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>())) .Returns((int id, int page, int pageSize) => ratings.Where(x => x.movieId == id)); var controller = new RatingsController(mockRatingRepository.Object, mockIRepository.Object); //Act List <Rating> allRatings = (List <Rating>)controller.GetRatings(1, 1, 1).Value; //Assert Assert.AreEqual(3, allRatings.Count()); Assert.AreEqual(ratings.Where(rat => rat.movieId == 1), allRatings); }
public void GetRatings_ReturnNotFoundWhenMovieHasNoRatings() { //Arrange Mock <IRepository <Movie> > mockIRepository = new Mock <IRepository <Movie> >(); Mock <IRatingRepository> mockRatingRepository = new Mock <IRatingRepository>(); mockRatingRepository.Setup(r => r.GetRatings(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>())) .Returns((int id, int page, int pageSize) => ratings.Where(x => x.movieId == id)); var controller = new RatingsController(mockRatingRepository.Object, mockIRepository.Object); //Act var result = controller.GetRatings(5, 1, 1).Result; //Assert Assert.IsInstanceOf <NotFoundResult>(result); }
public void TestMethodGetList() { var context = new TestBankDBContext(); context.Ratings.Add(new Rating { Id = 1, BranchId = 1, Value = 1, Description = "Bad Service", UserId = 1 }); context.Ratings.Add(new Rating { Id = 2, BranchId = 1, Value = 5, Description = "Great Service", UserId = 1 }); context.Ratings.Add(new Rating { Id = 3, BranchId = 2, Value = 4, Description = "Good Service", UserId = 1 }); var controller = new RatingsController(context); var result = controller.GetRatings() as TestRatingDbSet; Assert.IsNotNull(result); Assert.AreEqual(3, result.Local.Count); }