/// <summary>
        /// Inserts a movie into the repository.
        /// </summary>
        /// <param name="movie">The movie to insert.</param>
        public void Insert(Movie movie)
        {
            if (movie == null)
                throw new ArgumentNullException("movie");

            CurrentSession.Save(movie);
        }
        public void ShouldInsertMovie()
        {
            var movie = new Movie {Name = "testmovie", Description = "testdescription", Year = DateTime.Now.AddYears(-10), FileLocation = "file", PosterLocation = "poster"};
            _sut.Insert(movie);

            var retrieved = InMemorySession.Query<Movie>().First();
            Assert.AreEqual(retrieved.Name, movie.Name);
        }
        public void ShouldRetrieveInsertedUserMovieAfterInsert()
        {
            var user = new User {FirstName = "blah", LastName = "lastname", EmailAddress = "email", Identity = "identity", Password = "******"};
            var movie = new Movie {Name = "boo", Year = DateTime.Now, DateAdded = DateTime.Now, FileLocation = "file", Description = "description"};
            var userMovie = new UserMovie {User = user, Movie = movie, IsFavorite = false};

            _sut.Insert(userMovie);

            var retrieved = InMemorySession.Query<UserMovie>().ToArray();
            Assert.AreEqual(retrieved.Length, 1);
            Assert.AreEqual(retrieved.First().User.FirstName, user.FirstName);
            Assert.AreEqual(retrieved.First().Movie.Name, movie.Name);
        }
        public void ShouldRetrieveNothingOnGetForUserWithDifferentUser()
        {
            var first = new User { FirstName = "first", LastName = "lastname", EmailAddress = "email", Identity = "identity", Password = "******" };
            var second = new User { FirstName = "second", LastName = "lastname", EmailAddress = "email", Identity = "identity", Password = "******" };
            var movie = new Movie {Name = "boo", Year = DateTime.Now, DateAdded = DateTime.Now, FileLocation = "file", Description = "description"};
            var userMovie = new UserMovie { User = first, Movie = movie };
            using (var transaction = InMemorySession.BeginTransaction())
            {
                InMemorySession.Save(userMovie);
                transaction.Commit();
            }

            var retrieved = _sut.GetForUser(second).ToArray();
            Assert.AreEqual(retrieved.Length, 0);
        }
        public void ShouldRetrievePreviouslyInsertedUserMoviesOnGetAll()
        {
            var user = new User { FirstName = "blah", LastName = "lastname", EmailAddress = "email", Identity = "identity", Password = "******" };
            var movie = new Movie {Name = "boo", Year = DateTime.Now, DateAdded = DateTime.Now, FileLocation = "file", Description = "description"};
            var userMovie = new UserMovie {User = user, Movie = movie, IsFavorite = false};
            using (var transaction = InMemorySession.BeginTransaction())
            {
                InMemorySession.Save(userMovie);
                transaction.Commit();
            }

            var retrieved = _sut.GetForUser(user).ToArray();
            Assert.AreEqual(retrieved.Length, 1);
            Assert.AreEqual(retrieved.First().User.FirstName, user.FirstName);
            Assert.AreEqual(retrieved.First().Movie.Name, movie.Name);
        }
        /// <summary>
        /// Adapts retrieved detailed movie information into a useable movie object.
        /// </summary>
        /// <param name="info">The retrieved information.</param>
        /// <returns>The adapted information.</returns>
        private Movie AdaptDetails(dynamic info)
        {
            var data = info[0];
            var year = new DateTime(Convert.ToInt32(data["released"].Substring(0, 4)), 1, 1);
            var movie = new Movie
            {
                DateAdded = DateTime.Now,
                Description = data["overview"],
                Name = data["name"],
                PosterLocation = DerivePoster(data),
                Genres = DeriveGenres(data),
                Year = year
            };

            var cast = data["cast"];
            var actors = new List<Person>();
            var producers = new List<Person>();
            foreach (IDictionary<string, object> member in cast)
            {
                var person = _personRepository.GetByName(member["name"] as string);
                if (person == null)
                {
                    person = new Person {FirstName = ((string) member["name"]).Split(' ')[0], LastName = ((string) member["name"]).Split(' ')[1]};
                    _personRepository.SaveOrUpdate(person);
                }

                switch ((string)member["job"])
                {
                    case "Director":
                        movie.Director = person;
                        break;
                    case "Producer":
                        producers.Add(person);
                        break;
                    case "Actor":
                        actors.Add(person);
                        break;
                }
            }

            movie.Producers = producers;
            movie.Actors = actors;

            return movie;
        }