public void GetTop5OfUser1Movies() { // Arrange ApiCController controller = new ApiCController(); controller.Request = new HttpRequestMessage(); controller.Configuration = new HttpConfiguration(); IUserMovieRepository rep = new UserMovieRepository(); // Act var response = controller.Get(1, 5).ExecuteAsync(new System.Threading.CancellationToken()); response.Wait(); DbResult <List <UserMovie> > res = rep.GetAllByMasterId(1); UserMovie[] orderedList = null; if (res.IsSuccess) { orderedList = res.Result.OrderByDescending(t => t.UserRating).ThenBy(t => t.Movie.Title).Take(5).ToArray(); } // Assert Assert.IsNotNull(response.Result); Assert.AreEqual(true, response.Result.IsSuccessStatusCode); Assert.AreEqual(HttpStatusCode.OK, response.Result.StatusCode); Assert.AreEqual(5, response.Result.Content.ReadAsAsync <IEnumerable <MovieApiModel> >().Result.Count()); Assert.AreEqual(orderedList[0].MovieId, response.Result.Content.ReadAsAsync <IEnumerable <MovieApiModel> >().Result.ToArray()[0].id); Assert.AreEqual(orderedList[4].MovieId, response.Result.Content.ReadAsAsync <IEnumerable <MovieApiModel> >().Result.ToArray()[4].id); }
public IEnumerable <UserMovie> GetUserMovies() { var repo = new UserMovieRepository(); var userMovies = _repo.GetAllUserMovies(); return(userMovies); }
public IEnumerable <UserMovieWithMovieData> GetAllUserMoviesWithMovieDataByUser(int userId) { var repo = new UserMovieRepository(); var userMovies = _repo.GetAllUserMoviesWithMovieDataByUser(userId); return(userMovies); }
public void Put() { // Arrange var mockDbTransMovie = new Mock <DbTransaction <Movie> >(); var mockDbTransUserMovie = new Mock <DbTransaction <UserMovie> >(); var dbContext = DbConnection.GetSQLConnection(); mockDbTransMovie.Setup(t => t.SaveChanges(dbContext)).Callback(() => { }).Returns(new DbResult <int> { IsSuccess = true, Message = "Mock Success", Result = 1 }); mockDbTransUserMovie.Setup(t => t.SaveChanges(dbContext)).Callback(() => { }).Returns(new DbResult <int> { IsSuccess = true, Message = "Mock Success", Result = 1 }); IMovieRepository repMov = new MovieRepository(mockDbTransMovie.Object); IUserMovieRepository repUserMov = new UserMovieRepository(mockDbTransUserMovie.Object); ApiDController controller = new ApiDController(repMov, repUserMov); controller.Request = new HttpRequestMessage(); controller.Configuration = new HttpConfiguration(); //Act IHttpActionResult actionResult = controller.Put(new UserMovieModel { MovieId = 1, UserId = 1, UserRating = 4 }); var response = actionResult.ExecuteAsync(new System.Threading.CancellationToken()); response.Wait(); //Assert Assert.IsInstanceOfType(actionResult, typeof(OkNegotiatedContentResult <MovieApiModel>)); Assert.AreEqual(1, response.Result.Content.ReadAsAsync <MovieApiModel>().Result.id); Assert.AreEqual((decimal)3.5, response.Result.Content.ReadAsAsync <MovieApiModel>().Result.averageRating); }