示例#1
0
        public async Task ThrowEntityAlreadyExistsExceptionWhenParamsAreValid()
        {
            // Arrange
            contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>()
                             .UseInMemoryDatabase(databaseName: "ThrowEntityAlreadyExistsExceptionWhenParamsAreValid")
                             .Options;

            var userId       = "userId";
            var projectionId = 5;

            watchedMovie = new WatchedMovie()
            {
                UserId       = userId,
                ProjectionId = projectionId
            };

            using (var actContext = new AlphaCinemaContext(contextOptions))
            {
                await actContext.WatchedMovies.AddAsync(watchedMovie);

                await actContext.SaveChangesAsync();
            }

            // Act && Assert
            using (var assertContext = new AlphaCinemaContext(contextOptions))
            {
                var watchedMoviesService = new WatchedMoviesService(assertContext);
                await Assert.ThrowsExceptionAsync <EntityAlreadyExistsException>(() =>
                                                                                 watchedMoviesService.AddNewWatchedMovie(userId, projectionId));
            }
        }
示例#2
0
        public static WatchedMovieModel Map(MovieJMDBApi movie)
        {
            var watchedMovie = new WatchedMovie();

            foreach (var movieIter in movie.WatchedUsers)
            {
                if (movieIter.MovieJMDBApiId == movie.Id)
                {
                    watchedMovie = movieIter;
                }
            }
            return(new WatchedMovieModel
            {
                Id = movie.Id,
                Name = movie.Name,
                Actors = movie.MovieDetailsJMDBApi.Actors,
                Year = movie.MovieDetailsJMDBApi.Year,
                Director = movie.MovieDetailsJMDBApi.Director,
                Duration = movie.MovieDetailsJMDBApi.Duration,
                Genre = movie.MovieDetailsJMDBApi.Genre,
                Country = movie.MovieDetailsJMDBApi.Country,
                Poster = movie.Poster,
                Rate = watchedMovie.Rating,
                Comment = watchedMovie.Comment,
                DateTimeWatched = watchedMovie.WatchingDate,
                DateTimeAdded = watchedMovie.DateTimeAdded,
                UserId = watchedMovie.UserId,
                User = AutoMap <User, UserModel>(watchedMovie.User)
            });
        }
示例#3
0
 public void TestInitialize()
 {
     deletedReservation = new WatchedMovie()
     {
         UserId       = firstUserId,
         ProjectionId = firstProjectionId,
         IsDeleted    = true,
         Date         = new DateTime(currentYear, currentMonth, currentDay)
     };
     validReservation = new WatchedMovie()
     {
         UserId       = firstUserId,
         ProjectionId = firstProjectionId,
         IsDeleted    = false,
         Date         = new DateTime(currentYear, currentMonth, currentDay)
     };
     projection = new Projection()
     {
         Id         = firstProjectionId,
         CityId     = cityId,
         MovieId    = movieId,
         OpenHourId = openHourId,
         Seats      = projectionSeats,
         Day        = (int)currentDayOfWeek
     };
     openHour = new OpenHour()
     {
         Id = openHourId, Hours = currentHour, Minutes = currentMinute
     };
     movie = new Movie()
     {
         Id = movieId
     };
 }
        public async Task <WatchedMovie> AddReservation(string userId, int projectionId)
        {
            try
            {
                var reservation = CheckIfReservationExist(userId, projectionId);

                if (reservation == null)
                {
                    reservation = new WatchedMovie()
                    {
                        UserId       = userId,
                        ProjectionId = projectionId,
                        Date         = DateTime.Now
                    };
                    this.context.Add(reservation);
                }
                else
                {
                    reservation.Date      = DateTime.Now;
                    reservation.IsDeleted = false;
                    reservation.DeletedOn = null;
                    this.context.Update(reservation);
                }

                await this.context.SaveChangesAsync();

                return(reservation);
            }
            catch (Exception ex)
            {//Това изключение ще бъде хвърлено когато Foreign-Key Constraint бъде нарушен
                throw new EntityDoesntExistException("Reservation with that UserId and ProjectionId cannot be booked", ex);
            }
        }
示例#5
0
        public async Task ReturnWatchedMovieWhenParamsAreInDatabase()
        {
            // Arrange
            contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>()
                             .UseInMemoryDatabase(databaseName: "ReturnWatchedMovieWhenParamsAreInDatabase")
                             .Options;

            var userId       = "userId";
            var projectionId = 5;

            watchedMovie = new WatchedMovie()
            {
                UserId       = userId,
                ProjectionId = projectionId
            };

            using (var actContext = new AlphaCinemaContext(contextOptions))
            {
                await actContext.WatchedMovies.AddAsync(watchedMovie);

                await actContext.SaveChangesAsync();
            }

            // Act && Assert
            using (var assertContext = new AlphaCinemaContext(contextOptions))
            {
                var watchedMoviesService = new WatchedMoviesService(assertContext);
                var result = await watchedMoviesService.GetWatchedMovie(userId, projectionId);

                Assert.IsNotNull(result);
                Assert.AreEqual(result.ProjectionId, projectionId);
                Assert.AreEqual(result.UserId, userId);
            }
        }
示例#6
0
        public async Task ReturnNullWhenUserIsNotFound()
        {
            // Arrange
            contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>()
                             .UseInMemoryDatabase(databaseName: "ReturnNullWhenUserIsNotFound")
                             .Options;

            var userId       = "userId";
            var projectionId = 5;

            // Assert && Act
            watchedMovie = new WatchedMovie()
            {
                UserId       = userId,
                ProjectionId = projectionId
            };

            using (var actContext = new AlphaCinemaContext(contextOptions))
            {
                await actContext.WatchedMovies.AddAsync(watchedMovie);

                await actContext.SaveChangesAsync();
            }
            var serviceProviderMock = new Mock <IServiceProvider>();

            // Act && Assert
            using (var assertContext = new AlphaCinemaContext(contextOptions))
            {
                var watchedMoviesService = new WatchedMoviesService(assertContext);
                var result = await watchedMoviesService.GetWatchedMovie("no user id", projectionId);

                Assert.IsNull(result);
            }
        }
示例#7
0
        public List <WatchedMovie> LoadWatchedMovies(int userID)
        {
            try
            {
                SqlConnection conn = OpenConnection();
                SqlCommand    cmd  = new SqlCommand("SELECT Movie.MovieID, Movie.Name, WatchedMovie.UserRating, WatchedMovie.WatchedDate " +
                                                    "FROM Movie, WatchedMovie WHERE WatchedMovie.UserID = @userID AND Movie.MovieID = WatchedMovie.MovieID;SELECT Movie.Name, " +
                                                    "Movie.Director, WatchedMovie.UserRating, WatchedMovie.WatchedDate FROM Movie, WatchedMovie WHERE WatchedMovie.UserID = 3 " +
                                                    "AND Movie.MovieID = WatchedMovie.MovieID; ", conn);
                cmd.Parameters.Add(new SqlParameter("userID", userID));
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable      dt = new DataTable();
                da.Fill(dt);

                List <WatchedMovie> lm = new List <WatchedMovie>();

                foreach (DataRow dr in dt.Rows)
                {
                    WatchedMovie movie = new WatchedMovie
                    {
                        MovieID = int.Parse(dr["MovieID"].ToString()),
                        Name    = dr["Name"].ToString(),
                        //Director = dr["Director"].ToString(),
                        WatchedDate = DateTime.Parse(dr["WatchedDate"].ToString()),
                        UserRating  = int.Parse(dr["UserRating"].ToString())
                    };

                    //if (dr["UserRating"] == DBNull.Value)
                    //{
                    //    ((PeliculaVista)pelicula).UsuarioCalificacion = 1;
                    //}
                    //else
                    //{
                    //    ((PeliculaVista)pelicula).UsuarioCalificacion = int.Parse(dr["UsuarioCalificacion"].ToString());
                    //}

                    lm.Add(movie);
                }
                return(lm);
            }
            catch (SqlException Sqle)
            {
                Console.WriteLine("Problema al cargar usuario");
                Console.WriteLine(Sqle.Message);
                return(null);
                //throw;
            }
            catch (Exception e)
            {
                Console.WriteLine("Problema no relacionado a Sql 2");
                Console.WriteLine(e.Message);
                return(null);
                //throw;
            }
            finally
            {
                CloseConnection();
            }
        }
示例#8
0
 public static CommentRateModel Map(WatchedMovie movie)
 {
     return(new CommentRateModel
     {
         Rate = movie.Rating,
         Comment = movie.Comment,
         DateTimeWatched = movie.WatchingDate
     });
 }
示例#9
0
        public void Run()
        {
            bool running = true;

            while (running)
            {
                DisplayMenu();
                Write("Wybierz opcję: ");

                switch (Console.ReadLine())
                {
                case "1":
                {
                    Write();
                    Comment($"zanotowano: {_notebook.CountEntries()}");
                    foreach (INotebookEntry item in _notebook.GetAll())
                    {
                        Write(item.GetSlug());
                    }
                    break;
                }

                case "2":
                {
                    Write("Podaj tytuł filmu: ");
                    string       title = Console.ReadLine();
                    WatchedMovie movie = new WatchedMovie(title);
                    _notebook.Save(movie);
                    break;
                }

                case "3":
                {
                    Write("Podaj nazwę piwa: ");
                    string name = Console.ReadLine();
                    Write("Podaj nazwę browaru: ");
                    string    brewery = Console.ReadLine();
                    DrankBeer beer    = new(name, brewery);
                    _notebook.Save(beer);
                    break;
                }

                case "x":
                {
                    running = false;
                    break;
                }

                default:
                {
                    break;
                }
                }
            }
        }
 public void TestInitialize()
 {
     //Arrange
     deletedReservation = new WatchedMovie()
     {
         UserId       = testUserId,
         ProjectionId = testProjectionId,
         IsDeleted    = true,
         Date         = new DateTime(currentYear, currentMonth, currentDay)
     };
 }
        public MovieJMDBApi Add(MovieDetailsJMDBApi movie, long userId, string comment, int rate, string date, string poster, string movieAPIid)
        {
            var user = _uow.Users.FirstOrDefault(a => a.Id == userId, "");

            ValidationHelper.ValidateNotNull(user);

            var watchedMovie = _uow.WatchedMovies.FirstOrDefault(f => f.UserId == userId && f.MovieJMDBApiId == movieAPIid, "MovieJMDBApi");

            ValidationHelper.ValidateEntityExists(watchedMovie);

            var movieAPI = _uow.MoviesJMDBApi.FirstOrDefault(a => a.Id == movieAPIid, "");

            if (movieAPI == null)
            {
                MovieJMDBApi add = new MovieJMDBApi
                {
                    Id     = movieAPIid,
                    Name   = movie.Name,
                    Poster = poster,
                    MovieDetailsJMDBApi = movie
                };
                _uow.MoviesJMDBApi.Add(add);
                _uow.Save();
            }

            WatchedMovie watchedMoive = new WatchedMovie
            {
                UserId         = userId,
                MovieJMDBApiId = movieAPIid,
                Comment        = comment,
                Rating         = rate,
                WatchingDate   = date,
                DateTimeAdded  = DateTime.Now
            };

            var watchedMovieAdded = _uow.WatchedMovies.Add(watchedMoive, "");

            _uow.Save();

            var savedMovie = _uow.SavedMovies.FirstOrDefault(m => m.MovieJMDBApiId == movieAPIid && m.UserId == userId);

            if (savedMovie != null)
            {
                _uow.SavedMovies.Delete(savedMovie);
                _uow.Save();
            }
            ;
            return(watchedMovieAdded.MovieJMDBApi);
        }
 public void AddNewWatchedMovie(int userID, int resevationID)
 {
     watchedMovie = IfExist(userID, resevationID);
     if (watchedMovie != null)
     {
         throw new EntityAlreadyExistsException("You have already booked this projection");
     }
     else
     {
         watchedMovie = new WatchedMovie()
         {
             UserId       = userID,
             ProjectionId = resevationID
         };
         this.unitOfWork.WatchedMovies.Add(watchedMovie);
         this.unitOfWork.SaveChanges();
     }
 }
示例#13
0
        public HttpResponseMessage PostFilm([FromUri] int id, [FromBody] WatchedMovieModel movie)
        {
            var allProfiles = _pathToRepository.GetAllEntities();
            var movieToAdd  = new WatchedMovie(new Movie(movie.Movie.Title, movie.Movie.Director, movie.Movie.Genre), movie.Date, movie.Rating);

            for (int i = 0; i < allProfiles.Length; i++)
            {
                if (allProfiles[i].Id == id)
                {
                    allProfiles[i].AddWatchedMovie(movieToAdd);
                    break;
                }
            }
            File.WriteAllText(ConfigurationManager.AppSettings["PathToRepository"], JsonConvert.SerializeObject(allProfiles.ToArray()));
            return(Request.CreateResponse
                       (System.Net.HttpStatusCode.Created,
                       string.Format("Film {0} was sucessfully added to collection of user with id {1}", movie.Movie.Title, id)));
        }
示例#14
0
        public async Task AddNewWatchedMovie(string userId, int resevationId)
        {
            watchedMovie = await GetWatchedMovie(userId, resevationId);

            if (watchedMovie != null)
            {
                throw new EntityAlreadyExistsException("You have already booked this projection");
            }
            else
            {
                watchedMovie = new WatchedMovie()
                {
                    UserId       = userId,
                    ProjectionId = resevationId
                };
                await this.context.WatchedMovies.AddAsync(watchedMovie);

                await this.context.SaveChangesAsync();
            }
        }
        public void AddWatchedMovie()
        {
            var watchedMovie = WatchedMoviesList.FirstOrDefault(w => w.UserId == LoggedInUser.UserId && w.MovieId == SelectedMovie.Id);

            if (watchedMovie == null)
            {
                var newWatchedMovie = new WatchedMovie()
                {
                    UserId     = LoggedInUser.UserId,
                    MovieId    = SelectedMovie.Id,
                    MovieTitle = SelectedMovie.Title
                };

                var jsonWatchedSerialized = JsonConvert.SerializeObject(newWatchedMovie, new JsonSerializerSettings {
                    TypeNameHandling = TypeNameHandling.Objects
                });

                SocketHelper.ExecuteRequest("addWatchedMovie;" + jsonWatchedSerialized);
            }
        }
示例#16
0
 public static WatchedMovieModel MapFriend(MovieJMDBApi movie, WatchedMovie watchedMovie)
 {
     return(new WatchedMovieModel
     {
         Id = movie.Id,
         Name = movie.Name,
         Actors = movie.MovieDetailsJMDBApi.Actors,
         Year = movie.MovieDetailsJMDBApi.Year,
         Director = movie.MovieDetailsJMDBApi.Director,
         Duration = movie.MovieDetailsJMDBApi.Duration,
         Genre = movie.MovieDetailsJMDBApi.Genre,
         Country = movie.MovieDetailsJMDBApi.Country,
         Poster = movie.Poster,
         Rate = watchedMovie.Rating,
         Comment = watchedMovie.Comment,
         DateTimeWatched = watchedMovie.WatchingDate,
         DateTimeAdded = watchedMovie.DateTimeAdded,
         UserId = watchedMovie.UserId,
         User = AutoMap <User, UserModel>(watchedMovie.User)
     });
 }
示例#17
0
        public async Task <IActionResult> AddWatchedMovie(int id)
        {
            if (!_context.Movies.Any(m => m.Id == id))
            {
                return(NotFound());
            }
            User user = await _userManager.FindByNameAsync(User.Identity.Name);

            Movie movie = _context.Movies.Include(w => w.UserWatchedMovie)
                          .Include(f => f.Favorites).First(m => m.Id == id);

            WatchedMovie watchedMovie = new WatchedMovie
            {
                UserId  = user.Id,
                User    = user,
                MovieId = id,
                Movie   = movie
            };

            if (!_context.WatchedMovies.Any(w => w.MovieId == id))
            {
                _context.WatchedMovies.Add(watchedMovie);

                user.WatchedMovies ??= new List <WatchedMovie>();
                user.WatchedMovies.Add(watchedMovie);

                movie.UserWatchedMovie ??= new List <WatchedMovie>();
                movie.UserWatchedMovie.Add(watchedMovie);

                await _userManager.UpdateAsync(user);

                _context.SaveChanges();

                return(Created("test", user.WatchedMovies.Select(w => w.MovieId)));
            }
            else
            {
                return(Created("test", "The movie is already in watched list"));
            }
        }
示例#18
0
        public static IEnumerable <WatchedMovieModel> MapEnumerableWatchedMovies(PagedList <MovieJMDBApi> movies, long currentUserId)
        {
            List <WatchedMovieModel> moviesToReturn = new List <WatchedMovieModel>();

            foreach (var movie in movies)
            {
                var watchedMovie = new WatchedMovie();
                foreach (var movieIter in movie.WatchedUsers)
                {
                    if (movieIter.MovieJMDBApiId == movie.Id)
                    {
                        watchedMovie = movieIter;
                    }
                }
                var movieToadd = new WatchedMovieModel
                {
                    Id              = movie.Id,
                    Name            = movie.Name,
                    Actors          = movie.MovieDetailsJMDBApi.Actors,
                    Year            = movie.MovieDetailsJMDBApi.Year,
                    Director        = movie.MovieDetailsJMDBApi.Director,
                    Duration        = movie.MovieDetailsJMDBApi.Duration,
                    Genre           = movie.MovieDetailsJMDBApi.Genre,
                    Country         = movie.MovieDetailsJMDBApi.Country,
                    Poster          = movie.Poster,
                    Rate            = watchedMovie.Rating,
                    Comment         = watchedMovie.Comment,
                    DateTimeWatched = watchedMovie.WatchingDate,
                    DateTimeAdded   = watchedMovie.DateTimeAdded,
                    UserId          = watchedMovie.UserId,
                    User            = AutoMap <User, UserModel>(watchedMovie.User)
                };
                moviesToReturn.Add(movieToadd);
            }

            return(moviesToReturn);
        }
        public MovieJMDBApi Update(WatchedMovie movie, string movieId, long userId)
        {
            var userExists = _uow.Users.GetById(userId);

            ValidationHelper.ValidateNotNull(userExists);

            var movieExists = _uow.MoviesJMDBApi.GetById(movieId);

            ValidationHelper.ValidateNotNull(movieExists);

            // da li je taj user pogledao taj film:
            var watchedMovie = _uow.WatchedMovies.FirstOrDefault(m => m.MovieJMDBApiId == movieId && m.UserId == userId, "");

            ValidationHelper.ValidateNotNull(watchedMovie);


            if (!string.IsNullOrEmpty(movie.Comment))
            {
                watchedMovie.Comment = movie.Comment;
            }

            if (movie.Rating != 0)
            {
                watchedMovie.Rating = movie.Rating;
            }

            if (!string.IsNullOrEmpty(movie.WatchingDate))
            {
                watchedMovie.WatchingDate = movie.WatchingDate;
            }

            _uow.WatchedMovies.Update(watchedMovie, userId, watchedMovie.MovieJMDBApiId);
            _uow.Save();

            return(movieExists);
        }
示例#20
0
        public User watchedMovie(int uId, int mId, int scr)
        {
            User  usr = Users.Where(u => u.Id == uId).FirstOrDefault();
            Movie mvi = Movies.Where(m => m.Id == mId).FirstOrDefault();

            if (usr.WatchedMovies == null)
            {
                usr.WatchedMovies = new List <WatchedMovie>();
            }

            WatchedMovie wmvi = new WatchedMovie(mvi, scr);

            WatchedMovies.Add(wmvi);
            this.SaveChanges();


            System.Console.WriteLine(wmvi);

            usr.WatchedMovies.Add(wmvi);

            this.SaveChanges();

            return(usr);
        }
示例#21
0
 public void AddWatched(WatchedMovie watched)
 {
     _watchedRepository.AddWatched(watched);
 }
        public void AddWatched(WatchedMovie newWatchedMovie)
        {
            _context.WatchedMovies.Add(newWatchedMovie);

            _context.SaveChanges();
        }
        public void Setup()
        {
            _uowMock             = new Mock <IUnitOfWork>();
            _propertyMappingMock = new Mock <IPropertyMappingService>();
            _propertyCheckerMock = new Mock <IPropertyCheckerService>();
            _manager             = new WatchedMoviesManager(_propertyMappingMock.Object, _propertyCheckerMock.Object, _uowMock.Object);

            fakeWatchedMoive = new WatchedMovie
            {
                UserId         = 1,
                MovieJMDBApiId = "tt123",
                Comment        = "comment",
                Rating         = 5,
                WatchingDate   = "22.02.2020.",
                DateTimeAdded  = DateTime.Now,
                MovieJMDBApi   = new MovieJMDBApi
                {
                    Id = "tt123",
                    MovieDetailsJMDBApi = new MovieDetailsJMDBApi
                    {
                        Actors   = "Actors1",
                        Country  = "SRB",
                        Director = "Director1",
                        Duration = 98,
                        Genre    = "Action1",
                        Name     = "Movie 123",
                        Year     = 2021
                    },
                    Name         = "Movie 123",
                    Poster       = "poster 9",
                    SavedUsers   = null,
                    WatchedUsers = null
                },
                User = fakeUser
            };
            fakeUser = new User
            {
                Id       = 1,
                Name     = "user",
                Surname  = "user",
                Password = "******",
                Picture  = "picture",
                Email    = "email",
                NotificationsReceived = null,
                NotificationsSent     = null,
                FriendsReceived       = null,
                FriendsSent           = null,
                SavedMovies           = null,
                WatchedMovies         = null
            };

            fakeWatchedMovies = new List <WatchedMovie>
            {
                fakeWatchedMoive,
                new WatchedMovie
                {
                    UserId         = 1,
                    MovieJMDBApiId = "tt999",
                    DateTimeAdded  = new DateTime(2020, 6, 6),
                    User           = fakeUser,
                    MovieJMDBApi   = new MovieJMDBApi
                    {
                        Id = "tt999",
                        MovieDetailsJMDBApi = new MovieDetailsJMDBApi
                        {
                            Actors   = "Actors",
                            Country  = "USA",
                            Director = "Director",
                            Duration = 111,
                            Genre    = "Action",
                            Name     = "Movie 99",
                            Year     = 2020
                        },
                        Name         = "Movie 99",
                        Poster       = "poster 9",
                        SavedUsers   = null,
                        WatchedUsers = null
                    },
                    WatchingDate = "12.11.2020.",
                    Rating       = 4,
                    Comment      = "comment"
                }
            };

            fakeUserFriend = new User
            {
                Id       = 2,
                Name     = "user2",
                Surname  = "user2",
                Password = "******",
                Picture  = "picture2",
                Email    = "email2",
                NotificationsReceived = null,
                NotificationsSent     = null,
                FriendsReceived       = null,
                FriendsSent           = null,
                SavedMovies           = null,
                WatchedMovies         = null
            };

            fakeUserFriendTwo = new User
            {
                Id       = 3,
                Name     = "user3",
                Surname  = "user3",
                Password = "******",
                Picture  = "picture3",
                Email    = "email3",
                NotificationsReceived = null,
                NotificationsSent     = null,
                FriendsReceived       = null,
                FriendsSent           = null,
                SavedMovies           = null,
                WatchedMovies         = null
            };

            fakeListResult = new List <User>
            {
                new User
                {
                    Id       = 1,
                    Name     = "user",
                    Surname  = "user",
                    Password = "******",
                    Picture  = "picture",
                    Email    = "email",
                    NotificationsReceived = null,
                    NotificationsSent     = null,
                    FriendsReceived       = null,
                    FriendsSent           = null,
                    SavedMovies           = null,
                    WatchedMovies         = null
                },
                new User
                {
                    Id       = 2,
                    Name     = "user2",
                    Surname  = "user2",
                    Password = "******",
                    Picture  = "picture2",
                    Email    = "email2",
                    NotificationsReceived = null,
                    NotificationsSent     = null,
                    FriendsReceived       = null,
                    FriendsSent           = null,
                    SavedMovies           = null,
                    WatchedMovies         = null
                }
            };
        }
        public void UpdateMovie()
        {
            WatchedMovie watchedMoiveForUpdate = new WatchedMovie
            {
                //user can update comment, rate OR date waching, only one, two, or all of them
                Comment = "Updated comment",
                Rating  = 2
            };

            var movieAPI = new MovieJMDBApi
            {
                Id = "tt123",
                MovieDetailsJMDBApi = new MovieDetailsJMDBApi
                {
                    Actors   = "Actors",
                    Country  = "USA",
                    Director = "Director",
                    Duration = 111,
                    Genre    = "Action",
                    Name     = "Movie 99",
                    Year     = 2020
                },
                Name         = "Movie 99",
                Poster       = "poster 9",
                SavedUsers   = null,
                WatchedUsers = null
            };

            WatchedMovie watchedMoive = new WatchedMovie
            {
                UserId         = 1,
                MovieJMDBApiId = "tt123",
                Comment        = "comment",
                Rating         = 5,
                WatchingDate   = "22.02.2020.",
                DateTimeAdded  = DateTime.Now,
                MovieJMDBApi   = movieAPI,
                User           = fakeUser
            };

            string movieId       = "tt123";
            long   currentUserId = 1;

            _uowMock.Setup(uow => uow.Users.GetById(currentUserId)).Returns(fakeUser);
            _uowMock.Setup(uow => uow.MoviesJMDBApi.GetById(movieId)).Returns(movieAPI);
            _uowMock.Setup(uow => uow.WatchedMovies.FirstOrDefault(f => f.MovieJMDBApiId == movieId && f.UserId == currentUserId, ""))
            .Returns(watchedMoive);

            _uowMock.Setup(uow => uow.WatchedMovies.Update(watchedMoive, currentUserId, watchedMoive.MovieJMDBApiId))
            .Returns(watchedMoive);
            _uowMock.Setup(uow => uow.Save()).Callback(() => {
                watchedMoive.Comment = "Updated comment";
                watchedMoive.Rating  = 2;
            });

            var result = _manager.Update(watchedMoive, movieId, currentUserId);

            _uowMock.Verify(uow => uow.WatchedMovies.Update(watchedMoive, currentUserId, watchedMoive.MovieJMDBApiId), Times.Once());
            _uowMock.Verify(uow => uow.Save(), Times.Once());

            Assert.IsNotNull(result);
        }
        public void AddMovie()
        {
            var movieToAdd = new MovieDetailsJMDBApi()
            {
                Actors   = "Actors",
                Country  = "USA",
                Director = "Director",
                Duration = 111,
                Genre    = "Action",
                Name     = "Movie 99",
                Year     = 2020
            };

            var movieAPI = new MovieJMDBApi
            {
                Id = "tt123",
                MovieDetailsJMDBApi = new MovieDetailsJMDBApi
                {
                    Actors   = "Actors",
                    Country  = "USA",
                    Director = "Director",
                    Duration = 111,
                    Genre    = "Action",
                    Name     = "Movie 99",
                    Year     = 2020
                },
                Name         = "Movie 99",
                Poster       = "poster 9",
                SavedUsers   = null,
                WatchedUsers = null
            };

            long   currentUserId = 1;
            string comment       = "comment";
            int    rate          = 5;
            string date          = "22.02.2020.";
            string movieId       = "tt123";
            string poster        = "poster";

            WatchedMovie watchedMoive = new WatchedMovie
            {
                UserId         = 1,
                MovieJMDBApiId = "tt123",
                Comment        = "comment",
                Rating         = 5,
                WatchingDate   = "22.02.2020.",
                DateTimeAdded  = DateTime.Now,
                MovieJMDBApi   = movieAPI,
                User           = fakeUser
            };

            _uowMock.Setup(uow => uow.Users.FirstOrDefault(a => a.Id == currentUserId, "")).Returns(fakeUser);

            _uowMock.Setup(uow => uow.WatchedMovies.FirstOrDefault(f => f.UserId == currentUserId && f.MovieJMDBApiId == movieId, "MovieJMDBApi"))
            .Returns((WatchedMovie)null);

            _uowMock.Setup(uow => uow.MoviesJMDBApi.FirstOrDefault(a => a.Id == movieId, "")).Returns(movieAPI);

            _uowMock.Setup(uow => uow.SavedMovies.FirstOrDefault(a => a.MovieJMDBApiId == movieId && a.UserId == currentUserId, ""))
            .Returns((SavedMovie)null);

            _uowMock.Setup(uow => uow.WatchedMovies.Add(It.Is <WatchedMovie>(m => m.UserId == 1), "")).Returns(watchedMoive);

            var result = _manager.Add(movieToAdd, currentUserId, comment, rate, date, poster, movieId);

            _uowMock.Verify(uow => uow.WatchedMovies.Add(It.Is <WatchedMovie>(m => m.UserId == 1), ""), Times.Once());
            _uowMock.Verify(uow => uow.Save(), Times.Once());
            Assert.NotNull(result);
            Assert.AreEqual(movieAPI, result);
        }