public void TestRatingsOnBreadInDetailsView() { //Arrange IBreadRepository breadRepository = new MockBreadRepository(); IProductRepository productRepository = new MockProductRepository(); IRatingRepository ratingRepository = new MockRatingRepository(); var controller = new BreadController(breadRepository, productRepository, ratingRepository); // Act var result = controller.BreadView(1); // Assert Assert.IsType <ViewResult>(result); }
public void TestRateBread() { //Arrange IBreadRepository breadRepository = new MockBreadRepository(); IRatingRepository ratingRepository = new MockRatingRepository(); var controller = new RatingController(ratingRepository, breadRepository); Rating testRating = new Rating(); // Act var result = controller.RateBread(testRating, 1); // Assert Assert.IsType <RedirectToActionResult>(result); }
public void TestsTheBreadView() { //Arrange IBreadRepository breadRepository = new MockBreadRepository(); IProductRepository productRepository = new MockProductRepository(); IRatingRepository ratingRepository = new MockRatingRepository(); var controller = new BreadController(breadRepository, productRepository, ratingRepository); // Act var result = controller.BreadList(); // Assert Assert.NotNull(result); Assert.IsType <ViewResult>(result); }
public void TestsTheMockRatingRepository() { //Arrange IRatingRepository ratingRepository = new MockRatingRepository(); //Act IEnumerable <Rating> mockRatings = ratingRepository.GetAllRatings(1); //GetAllRatings fetches all the ratings for bread where breadId == 1 int countRatings = 0; foreach (var rating in mockRatings) { countRatings++; } //Assert Assert.NotEqual(0, countRatings); }
public void WhenCalling_SaveRating_WithValidMovieRating_RepositoryMethodCalled(int movieId, int userId, byte rating) { //arrange var movieRating = new MovieRating { MovieId = movieId, UserId = userId, Rating = rating }; MockMovieService.Setup(s => s.MovieExistsAsync(movieId)).Returns(Task.FromResult(true)); MockUserService.Setup(s => s.UserExistsAsync(userId)).Returns(Task.FromResult(true)); //act var result = GetService().SaveRatingAsync(movieRating); //assert MockRatingRepository.Verify(s => s.SaveRatingAsync(It.Is <MovieRating>(p => p.MovieId == movieId && p.UserId == userId && p.Rating == rating)), Times.Once); }