Beispiel #1
0
        /// <summary>
        /// Adds the FollowingMovie specified in the argument to the database.
        /// Returns true iff successful.
        /// Returns false if the username or movieid referenced in the FollowingMovie object
        /// do not already exist in their respective database tables.
        /// </summary>
        /// <param name="followingMovie"></param>
        /// <returns></returns>
        public async Task <bool> FollowMovie(FollowingMovie followingMovie)
        {
            var userExists = UserExists(followingMovie.Username);

            if (!userExists)
            {
                Console.WriteLine("RepoLogic.FollowMovie() was called for a user that doesn't exist.");
                return(false);
            }
            var movieExists = MovieExists(followingMovie.MovieId);

            if (!movieExists)
            {
                Console.WriteLine("RepoLogic.FollowMovie() was called for a movie that doesn't exist.");
                return(false);
            }
            // Ensure the User is not already Following this Movie
            if ((await _dbContext.FollowingMovies.Where(fm =>
                                                        fm.Username == followingMovie.Username &&
                                                        fm.MovieId == followingMovie.MovieId
                                                        ).FirstOrDefaultAsync <FollowingMovie>()) != null)
            {
                Console.WriteLine("RepoLogic.FollowMovie() was called for a movie that the user is " +
                                  "already following.");
                return(false);
            }

            await _dbContext.FollowingMovies.AddAsync(followingMovie);

            await _dbContext.SaveChangesAsync();

            return(true);
        }
        public async Task RecommendedMoviesByUserIdTest()
        {
            MovieDTO inputMovie = TestingHelper.GetRandomMovie();

            inputMovie.ImdbId = "tt4154796";
            string          userId = Guid.NewGuid().ToString();
            List <MovieDTO> results;

            // Seed the test database
            using (var context = new Cinephiliacs_MovieContext(dbOptions))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                TestingHelper.AddMovieDTOToDatabase(context, inputMovie);

                var followingMovie = new FollowingMovie();
                followingMovie.ImdbId = inputMovie.ImdbId;
                followingMovie.UserId = userId;
                context.FollowingMovies.Add(followingMovie);
                context.SaveChanges();
            }

            using (var context = new Cinephiliacs_MovieContext(dbOptions))
            {
                RepoLogic  repoLogic  = new RepoLogic(context);
                MovieLogic movieLogic = new MovieLogic(repoLogic);
                // Test RecommendedMoviesByUserId()
                results = await movieLogic.RecommendedMoviesByUserId(userId);
            }

            Assert.True(results.Count > 0);
        }
Beispiel #3
0
        /// <summary>
        /// Adds the movie specified in the argument to the user
        /// specified in the argument's following movie list.
        /// </summary>
        /// <param name="movieId"></param>
        /// <param name="userId"></param>
        public void AddFollowingMovie(string movieId, string userId)
        {
            if (FollowingMovieExists(movieId, userId))
            {
                return;
            }
            var followingMovie = new FollowingMovie();

            followingMovie.ImdbId = movieId;
            followingMovie.UserId = userId;
            _dbContext.FollowingMovies.Add(followingMovie);
            _dbContext.SaveChanges();
        }