public void IndexShouldReturnViewWithOneMovie() { // arrange var mockRepo = new Mock <IMovieRepo>(); mockRepo.Setup(x => x.GetMovies()).Returns(new List <Movie> { new Movie { Id = 1, Title = "" } }); //mockRepo.Setup(x => x.GetMovie(It.IsAny<int>())).Returns(null); //var controller = new MovieController(new FakeMovieRepo()); var controller = new MovieController(mockRepo.Object); // act IActionResult result = controller.Index(); // assert ViewResult viewResult = Assert.IsAssignableFrom <ViewResult>(result); //Assert.Equal("Movie/Home", viewResult.ViewName); var movies = Assert.IsAssignableFrom <IEnumerable <MovieViewModel> >(viewResult.Model); Assert.Single(movies); MovieViewModel theMovie = movies.First(); Assert.NotNull(theMovie); Assert.Equal(1, theMovie.Id); }
public MoviePage(Movie movie, MovieController movieController) { this._movieController = movieController; viewModel = new MovieViewModel(this.Navigation, movie, _movieController); this.BindingContext = viewModel; InitializeComponent(); }
public void GetTagsTest() { MovieDTO inputMovie = TestingHelper.GetRandomMovie(0, 0, 0, 0, 3); List <string> results; // Seed the test database using (var context = new Cinephiliacs_MovieContext(dbOptions)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); TestingHelper.AddMovieDTOToDatabase(context, inputMovie); } using (var context = new Cinephiliacs_MovieContext(dbOptions)) { RepoLogic repoLogic = new RepoLogic(context); IMovieLogic movieLogic = new MovieLogic(repoLogic); MovieController movieController = new MovieController(movieLogic); // Test GetAllTags() results = movieController.GetAllTags().Value; } Assert.Contains(inputMovie.MovieTags[0], results); Assert.Contains(inputMovie.MovieTags[1], results); Assert.Contains(inputMovie.MovieTags[2], results); }
public MovieModule(OrmLiteConnectionFactory db) : base("/movies") { Get["/"] = _ => { var movies = new MovieController(db); return movies.ListAll(); }; Get["/{movie}"] = req => { var movies = new MovieController(db); var movie = movies.Lookup(req.movie); if (movie == null) return 404; return View["MovieDetail", movie]; }; Get["/create"] = _ => { return View["NewMovie"]; }; Post["/create"] = _ => { var movie = this.Bind<Movie>(); // Binds the POST result to movie variable (as a movie object) var movieController = new MovieController(db); movieController.Add(movie); return Response.AsRedirect(ModulePath + "/" + movie.GetPrettyTitleLink()); }; Post["/update/{id}"] = _ => { return 500; }; }
public ViewMovie() { InitializeComponent(); movieController = new MovieController(); DataContext = App.MovieViewModel; this.Loaded += new RoutedEventHandler(ViewMovie_Loaded); }
public void Setup() { var client = new MongoClient(Constants.MongoDbConnectionUri()); var movieRepository = new MoviesRepository(client); _movieController = new MovieController(movieRepository); }
public async Task CallMovieServiceOnce_OnGet() { // Arrange var movieServiceMock = new Mock <IMovieService>(); var genreServiceMock = new Mock <IGenreService>(); string movieName = "Spiderman"; int rating = 10; var rateModel = new RateMovieViewModel() { Name = movieName, Rating = rating }; movieServiceMock .Setup(g => g.RateMovieAsync(movieName, rating)) .ReturnsAsync(new MovieViewModel()); var sut = new MovieController(movieServiceMock.Object, genreServiceMock.Object); // Act await sut.Rate(rateModel); // Assert movieServiceMock.Verify(m => m.RateMovieAsync(movieName, rating), Times.Once); }
public void TestGet() { var controller = new MovieController(new TestMovieModelContext()); var result = controller.Get(); Assert.AreEqual(1, 1); }
public void GetAllTest() { var controller = new MovieController(); var result = controller.Get(); Assert.Equal(3, result.Count()); }
public void TestPostMovieOk() { MovieModel movieModel = new MovieModel() { Name = "Enola Holmes", AgeAllowed = 12, CategoryId = 1, Description = "La herama de Sherlock y Mycroft Holmes", Duration = 2.1, Image = "Mi directorio", }; Movie movieToReturn = new Movie() { Id = 1, Name = "Enola Holmes", AgeAllowed = 12, CategoryId = 1, Description = "La herama de Sherlock y Mycroft Holmes", Duration = 2.1, Image = "Mi directorio", Rank = 0 }; var mock = new Mock <IMovieLogic>(); mock.Setup(m => m.Add(It.IsAny <Movie>())).Returns(movieToReturn); var controller = new MovieController(mock.Object); var result = controller.Post(movieModel); var status = result as CreatedAtRouteResult; var content = status.Value as MovieDetailInfoModel; mock.VerifyAll(); Assert.AreEqual(content, new MovieDetailInfoModel(movieToReturn)); }
public void view_details_OK() { //Arrange var controller = new MovieController(new MovieBLL(new MovieRepositoryStub())); var expected_result = new Movie() { Id = 1, ImageAddress = "movieImageAddress.jpg", Title = "Title", Description = "Blockbaster", Price = 12, Genre = "Fantasy" }; //Act var actionResult = (ViewResult)controller.Details(1); var result = (Movie)actionResult.Model; //Assert Assert.AreEqual(actionResult.ViewName, ""); Assert.AreEqual(expected_result.Id, result.Id); Assert.AreEqual(expected_result.ImageAddress, result.ImageAddress); Assert.AreEqual(expected_result.Title, result.Title); Assert.AreEqual(expected_result.Description, result.Description); Assert.AreEqual(expected_result.Price, result.Price); Assert.AreEqual(expected_result.Genre, result.Genre); }
public async Task GetMovieTest() { MovieDTO inputMovie = TestingHelper.GetRandomMovie(); MovieDTO outputMovie; // Seed the test database using (var context = new Cinephiliacs_MovieContext(dbOptions)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); TestingHelper.AddMovieDTOToDatabase(context, inputMovie); } using (var context = new Cinephiliacs_MovieContext(dbOptions)) { RepoLogic repoLogic = new RepoLogic(context); IMovieLogic movieLogic = new MovieLogic(repoLogic); MovieController movieController = new MovieController(movieLogic); // Test GetMovie() outputMovie = (await movieController.GetMovie(inputMovie.ImdbId)).Value; } Assert.Equal(inputMovie.ImdbId, outputMovie.ImdbId); }
public void SearchRatingTest() { MovieDTO inputMovie = TestingHelper.GetRandomMovie(0, 0, 0, 0, 0); List <string> searchResults; var filters = new Dictionary <string, string[]>(); Console.WriteLine(inputMovie); filters.Add("Rating", new string[] { inputMovie.RatingName }); // Seed the test database using (var context = new Cinephiliacs_MovieContext(dbOptions)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); TestingHelper.AddMovieDTOToDatabase(context, inputMovie); TestingHelper.AddMovieDTOToDatabase(context, TestingHelper.GetRandomMovie(0, 0, 0, 0, 0)); } using (var context = new Cinephiliacs_MovieContext(dbOptions)) { RepoLogic repoLogic = new RepoLogic(context); IMovieLogic movieLogic = new MovieLogic(repoLogic); MovieController movieController = new MovieController(movieLogic); // Test SearchMovies() searchResults = movieController.SearchMovies(filters).Value; } Assert.Equal(inputMovie.ImdbId, searchResults[0]); }
public async Task GetMoviesTest() { List <MovieDetail> movies = new List <MovieDetail>() { new MovieDetail() { Title = "test_1", Id = "cm1" }, new MovieDetail() { Title = "test_2", Id = "cm1" }, new MovieDetail() { Title = "test_1", Id = "fm1" }, new MovieDetail() { Title = "test_2", Id = "fm1" }, }; var movieService = new Mock <IMovieService>(); movieService.Setup(s => s.GetMoviesByComparingPrice()).Returns(() => Task.FromResult(movies)); MovieController movieController = new MovieController(movieService.Object); IActionResult actionResult = await movieController.GetMoviesAsync(); OkObjectResult okResult = actionResult as OkObjectResult; Assert.IsNotNull(okResult); Assert.AreEqual(200, okResult.StatusCode); Assert.IsInstanceOfType(actionResult, typeof(OkObjectResult)); }
public void DeleteMovieTest() { MovieDTO inputMovie = TestingHelper.GetRandomMovie(); Movie outputMovie; using (var context = new Cinephiliacs_MovieContext(dbOptions)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); TestingHelper.AddMovieDTOToDatabase(context, inputMovie); RepoLogic repoLogic = new RepoLogic(context); IMovieLogic movieLogic = new MovieLogic(repoLogic); MovieController movieController = new MovieController(movieLogic); // Test DeleteMovie() movieController.DeleteMovie(inputMovie.ImdbId); } using (var context = new Cinephiliacs_MovieContext(dbOptions)) { outputMovie = context.Movies.FirstOrDefault(m => m.ImdbId == inputMovie.ImdbId); } Assert.Null(outputMovie); }
public void Get_toplist_returns_expected_error() { var controller = new MovieController(new ListSourceMock(null)); var actual = controller.Toplist(); Assert.AreEqual("Could not retrieve movies from source", actual.First()); }
public async Task GetMovies_CorrectViewReturned() { var pagedMovies = new PagedResult <MovieDto> { AllRows = 24, PageNumber = 1, PagesCount = 2, PageSize = 20, Results = new List <MovieDto>() }; var fakeMovieService = new Mock <IMovieService>(); fakeMovieService.Setup( s => s.ListMoviesAsync(It.IsAny <MovieCriteria>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>())) .ReturnsAsync(pagedMovies); var controller = new MovieController(fakeMovieService.Object, Mapper); var res = (PartialViewResult)await controller.GetMovies(new MovieCriteria()); var model = (MovieListPagedViewModel)res.Model; Assert.Equal(1, model.PageNumber); Assert.Equal(2, model.PagesCount); Assert.Equal(24, model.RowsCount); Assert.Equal(20, model.PageSize); Assert.NotNull(model.Movies); }
public async Task ReturnCorrectViewModel_OnGet() { // Arrange var movieServiceMock = new Mock <IMovieService>(); var genreServiceMock = new Mock <IGenreService>(); string movieName = "Spiderman"; int rating = 10; var rateModel = new RateMovieViewModel() { Name = movieName, Rating = rating }; movieServiceMock .Setup(g => g.RateMovieAsync(movieName, rating)) .ReturnsAsync(new MovieViewModel()); var sut = new MovieController(movieServiceMock.Object, genreServiceMock.Object); // Act var result = await sut.Rate(rateModel) as JsonResult; // Assert Assert.IsInstanceOfType(result.Value, typeof(MovieViewModel)); }
public MovieControllerTests() { _movieApi = new Mock <IMovieApi>(); _movieMetaData = new Mock <IMovieMetaData>(); _logger = new Mock <ILogger <MovieController> >(); _movieControllerTests = new MovieController(_logger.Object, _movieApi.Object, _movieMetaData.Object); }
public void SearchActorTagTest() { MovieDTO inputMovie = TestingHelper.GetRandomMovie(1, 1, 1, 1, 1); MovieDTO unmatchedMovie = TestingHelper.GetRandomMovie(1, 1, 1, 1, 1); unmatchedMovie.MovieActors[0] = inputMovie.MovieActors[0]; List <string> searchResults; var filters = new Dictionary <string, string[]>(); filters.Add("Actor", new string[] { inputMovie.MovieActors[0] }); filters.Add("Tag", new string[] { inputMovie.MovieTags[0] }); // Seed the test database using (var context = new Cinephiliacs_MovieContext(dbOptions)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); TestingHelper.AddMovieDTOToDatabase(context, inputMovie); TestingHelper.AddMovieDTOToDatabase(context, unmatchedMovie); } using (var context = new Cinephiliacs_MovieContext(dbOptions)) { RepoLogic repoLogic = new RepoLogic(context); IMovieLogic movieLogic = new MovieLogic(repoLogic); MovieController movieController = new MovieController(movieLogic); // Test SearchMovies() searchResults = movieController.SearchMovies(filters).Value; } Assert.Equal(inputMovie.ImdbId, searchResults[0]); }
public void TestGetAllMoviesOk() { List <Movie> moviesToReturn = new List <Movie>() { new Movie() { Id = 1, Name = "Iron man 3", Description = "I'm Iron man", AgeAllowed = 16, Duration = 1.5 }, new Movie() { Id = 2, Name = "Iron man 2", Description = "I'm Iron man", AgeAllowed = 16, Duration = 1.5 } }; var mock = new Mock <IMovieLogic>(MockBehavior.Strict); mock.Setup(m => m.GetAll()).Returns(moviesToReturn); var controller = new MovieController(mock.Object); var result = controller.Get(); var okResult = result as OkObjectResult; var movies = okResult.Value as IEnumerable <MovieBasicInfoModel>; mock.VerifyAll(); Assert.IsTrue(moviesToReturn.Select(m => new MovieBasicInfoModel(m)).SequenceEqual(movies)); }
public async Task PostTagTest() { var inputMovie = TestingHelper.GetRandomMovie(); var inputTag = TestingHelper.GetRandomTaggingDTO(inputMovie.ImdbId); MovieTagUser movieTagUser; // Seed the test database using (var context = new Cinephiliacs_MovieContext(dbOptions)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); TestingHelper.AddMovieDTOToDatabase(context, inputMovie); RepoLogic repoLogic = new RepoLogic(context); IMovieLogic movieLogic = new MovieLogic(repoLogic); MovieController movieController = new MovieController(movieLogic); // Test TagMovie() await movieController.TagMovie(inputTag); } using (var context = new Cinephiliacs_MovieContext(dbOptions)) { movieTagUser = context.MovieTagUsers.FirstOrDefault(m => m.ImdbId == inputTag.MovieId); } Assert.Equal(inputTag.MovieId, movieTagUser.ImdbId); Assert.Equal(inputTag.TagName, movieTagUser.TagName); Assert.Equal(inputTag.UserId, movieTagUser.UserId); }
private async void ViewTrending_Loaded(object sender, RoutedEventArgs e) { LayoutRoot.Opacity = 1; if (App.TrendingViewModel.TrendingItems.Count == 0) { indicator = App.ShowLoading(this); movieController = new MovieController(); TraktMovie[] movies = await movieController.GetTrendingMovies(); App.TrendingViewModel.ClearTrendingItems(); foreach (TraktMovie movie in movies) { if (App.TrendingViewModel.TrendingItems.Count <= 80) { App.TrendingViewModel.TrendingItems.Add(new ViewModels.TrendingListItemViewModel() { Imdb = movie.imdb_id, Name = movie.Title, Year = movie.year, ImageSource = movie.Images.Poster }); } } App.TrendingViewModel.NotifyPropertyChanged("TrendingItems"); indicator.IsVisible = false; } }
public void UnbanTagTest() { var inputMovie = TestingHelper.GetRandomMovie(); var inputTag = TestingHelper.GetRandomTaggingDTO(inputMovie.ImdbId); bool inputBanState = true; Tag tag; // Seed the test database using (var context = new Cinephiliacs_MovieContext(dbOptions)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); TestingHelper.AddMovieDTOToDatabase(context, inputMovie); TestingHelper.AddTagToDatabase(context, inputTag, inputBanState); RepoLogic repoLogic = new RepoLogic(context); IMovieLogic movieLogic = new MovieLogic(repoLogic); MovieController movieController = new MovieController(movieLogic); // Test UnbanTag() movieController.UnbanTag(inputTag.TagName); } using (var context = new Cinephiliacs_MovieContext(dbOptions)) { tag = context.Tags.FirstOrDefault(t => t.TagName == inputTag.TagName); } Assert.False(tag.IsBanned); }
public App() { MovieController movieController = new MovieController(); // The root page of your application var titleSearchPage = new TitleSearchPage(movieController, new TitleSearchViewModel(movieController)); var titleNavigationPage = new NavigationPage(titleSearchPage) { Title = "Search" }; var topRatedPage = new CustomListPage(movieController, new TopRatedViewModel(movieController)); var topRatedNavigationPage = new NavigationPage(topRatedPage) { Title = "Top Rated" }; var popularPage = new CustomListPage(movieController, new PopularViewModel(movieController)); var PopularNavigationPage = new NavigationPage(popularPage) { Title = "Popular" }; var tabbedPage = new TabbedPageInitializer(); tabbedPage.Children.Add(titleNavigationPage); tabbedPage.Children.Add(topRatedNavigationPage); tabbedPage.Children.Add(PopularNavigationPage); this.MainPage = tabbedPage; }
public MovieControllerTests() { _collections = new List <Collection> { new Collection { Id = "id1", Name = "collection1", PrimaryImage = "image1", Type = CollectionType.Movies }, new Collection { Id = "id2", Name = "collection2", PrimaryImage = "image2", Type = CollectionType.Movies } }; _movieStats = new MovieStats { LongestMovie = new Poster { Name = "The lord of the rings" } }; _movieServiceMock = new Mock <IMovieService>(); _movieServiceMock.Setup(x => x.GetMovieCollections()).Returns(_collections); _movieServiceMock.Setup(x => x.GetGeneralStatsForCollections(It.IsAny <List <string> >())) .Returns(_movieStats); _subject = new MovieController(_movieServiceMock.Object); }
public TitleSearchViewModel(MovieController movieController) { _movieController = movieController; TitleSearchCommand = new Command(async() => { if (this.searchTitle != null && this.SearchTitle != "") { // Activate loading Icon Loading = true; // Search movies by title NoResult = false; await GetMoviesAsync(); if (this.Movies.Count != 0) { SomeResult = true; NoResult = false; } else { SomeResult = false; NoResult = true; } // Deactivate loading icon Loading = false; GetCast(Movies); } }); }
public void FollowMovieTest() { MovieDTO inputMovie = TestingHelper.GetRandomMovie(); string userId = Guid.NewGuid().ToString(); List <string> followedMovies; // Seed the test database using (var context = new Cinephiliacs_MovieContext(dbOptions)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); TestingHelper.AddMovieDTOToDatabase(context, inputMovie); RepoLogic repoLogic = new RepoLogic(context); IMovieLogic movieLogic = new MovieLogic(repoLogic); // Test FollowMovie() movieLogic.FollowMovie(inputMovie.ImdbId, userId); } using (var context = new Cinephiliacs_MovieContext(dbOptions)) { RepoLogic repoLogic = new RepoLogic(context); IMovieLogic movieLogic = new MovieLogic(repoLogic); MovieController movieController = new MovieController(movieLogic); // Test FollowMovie() followedMovies = movieController.GetFollowingMovies(userId).Value; } Assert.Contains(inputMovie.ImdbId, followedMovies); }
public async Task MovieTest() { string inputMovieId = "ab10101010"; string outputMovieId; // Seed the test database using (var context = new Repository.Models.Cinephiliacs_DbContext(dbOptions)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); RepoLogic repoLogic = new RepoLogic(context); // Test CreateMovie() IMovieLogic movieLogic = new MovieLogic(repoLogic); MovieController movieController = new MovieController(movieLogic); await movieController.CreateMovie(inputMovieId); } using (var context = new Repository.Models.Cinephiliacs_DbContext(dbOptions)) { var gmMovie = context.Movies.FirstOrDefault <Repository.Models.Movie>(m => m.MovieId == inputMovieId); outputMovieId = gmMovie.MovieId; } Assert.Equal(inputMovieId, outputMovieId); }
public async Task PatchExistingMovieTest() { MovieDTO inputMovie = TestingHelper.GetRandomMovie(); Movie outputMovie; // Seed the test database using (var context = new Cinephiliacs_MovieContext(dbOptions)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); TestingHelper.AddMovieDTOToDatabase(context, inputMovie); RepoLogic repoLogic = new RepoLogic(context); IMovieLogic movieLogic = new MovieLogic(repoLogic); MovieController movieController = new MovieController(movieLogic); // Test AppendMovie() await movieController.AppendMovie(inputMovie.ImdbId, TestingHelper.GetRandomMovie()); } using (var context = new Cinephiliacs_MovieContext(dbOptions)) { outputMovie = context.Movies.FirstOrDefault(m => m.ImdbId == inputMovie.ImdbId); } Assert.NotEqual(inputMovie.Title, outputMovie.Title); }
public void ReturnImage_WhenFoundImageIsNotNull() { // Arrange var movieServiceMock = new Mock <IMovieService>(); var movieRoleServiceMock = new Mock <IMovieRoleService>(); var fileConverterMock = new Mock <IFileConverter>(); var mapperMock = new Mock <IMapper>(); var image = new byte[128]; var movieId = 1; movieServiceMock.Setup(ms => ms.GetMovieImage(movieId)).Returns(image); var movieController = new MovieController( movieServiceMock.Object, movieRoleServiceMock.Object, fileConverterMock.Object, mapperMock.Object); // Act movieController.MovieImage(movieId); // Assert fileConverterMock.Verify(fcm => fcm.GetDefaultPicture(), Times.Never); }
public ShowingModule(OrmLiteConnectionFactory db) : base("/showings") { Get["/"] = _ => { var showings = new ShowingsController(db); return View["ShowingList", showings.ListAll()]; }; Get["/{showing}"] = req => { var showings = new ShowingsController(db); var showing = showings.Get(req.showing); if (showing == null) return 404; return View["ShowingDetail", showing]; }; Get["/create"] = _ => { var movieController = new MovieController(db); ViewBag["Movies"] = movieController.ListAll().GetSelectList(); return View["NewShowing", new Showing()]; }; Post["/create"] = _ => { var showing = this.Bind<Showing>(); LogTo.Debug("Adding showing: {0}", showing); var showingsController = new ShowingsController(db); var showingId = showingsController.Add(showing); return Response.AsRedirect(ModulePath + "/" + showingId); }; Get["{showing}/edit"] = req => { // Look up the showing with given ID var showings = new ShowingsController(db); var showing = showings.Get(req.showing); if (showing == null) return 404; // Tell the view where to POST to ViewBag["action"] = ModulePath + $"/{req.showing}/edit"; // Do usual showing view stuff (see the create view) - it would be great if we could consolodate the the two into one function var movieController = new MovieController(db); ViewBag["Movies"] = movieController.ListAll().GetSelectList(); return View["NewShowing", showing]; }; Post["{showing}/edit"] = req => { int showingID; if (!int.TryParse(req.showing, out showingID)) return 404; // User tried to edit a showing with an invalid (non-numeric) ID var editedShowing = this.Bind<Showing>(); var showings = new ShowingsController(db); var oldshowing = showings.Get(showingID); if(oldshowing == null) return 404; // User tried to edit a nonexistent showing var filledSeats = oldshowing.TotalSeats - oldshowing.AvailableSeats; editedShowing.AvailableSeats = editedShowing.TotalSeats - filledSeats; //if(editedShowing.AvailableSeats < 0) // return "Error: negative seats available"; // is this really an error condition? Maybe they're okay with making an overbooked show.. editedShowing.ShowingId = showingID; showings.Update(editedShowing); return Response.AsRedirect(ModulePath + "/" + showingID); }; Post["{showing}/delete"] = req => { // Again, this code duplication is pretty nasty int showingID; if (!int.TryParse(req.showing, out showingID)) return 500; // User tried to edit a showing with an invalid (non-numeric) ID var showings = new ShowingsController(db); if (showings.Get(showingID) == null) return 404; // User tried to edit a nonexistent showing showings.Delete(showingID); return Response.AsRedirect(ModulePath + "/"); }; }