/// <summary>
        /// Retrieves a collection of user-movie objects for a user.
        /// </summary>
        /// <param name="user">The user for which user-movie objects should be retrieved.</param>
        /// <returns>The collection of user-movie objects.</returns>
        public IEnumerable<UserMovie> GetForUser(User user)
        {
            if (user == null)
                throw new ArgumentNullException("user");

            return CurrentSession.Query<UserMovie>().Where(x => x.User == user);
        }
        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);
        }
        /// <summary>
        /// Fired at the authorization phase. Retrieves user identity information from the request, which is used to
        /// determine which user is making the request.
        /// </summary>
        protected override void OnAuthorization(AuthorizationContext filterContext)
        {
            var cookie = filterContext.HttpContext.Request.Cookies["identity"];
            if (cookie == null)
            {
                User = DR.Get<IUserRepository>().Authenticate("blah");
                return;
            }

            var identity = cookie.Value;
            if (string.IsNullOrEmpty(identity))
                return;

            User = DR.Get<IUserRepository>().Authenticate(identity);

            base.OnAuthorization(filterContext);
        }
        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);
        }
예제 #6
0
        public void Reset()
        {
            _random = new Random();

            Configuration configuration = null;
            var session = Fluently
                .Configure()
                .ExposeConfiguration(x => configuration = x)
                .Database(MsSqlConfiguration.MsSql2008.ConnectionString(x => x.FromConnectionStringWithKey("Database")))
                .Mappings(x => x.FluentMappings.AddFromAssemblyOf<UserMap>())
                .BuildSessionFactory()
                .OpenSession();

            SessionProvider.CurrentSession = session;

            new SchemaExport(configuration).Execute(false, true, false);

            var user = new User { EmailAddress = "*****@*****.**", FirstName = "Chris", Identity = "blah", LastName = "Harrington", Password = "******" };
            using (var transaction = session.BeginTransaction())
            {
                session.Save(user);
                transaction.Commit();
            }

            using (var transaction = session.BeginTransaction())
            {
                var repository = new UncategorizedMovieRepository();
                repository.Insert(new UncategorizedMovie { OriginalFile = "file1.avi", EncodedFile = "encoded1.mp4" });
                repository.Insert(new UncategorizedMovie { OriginalFile = "file2.avi", EncodedFile = "encoded1.mp4" });
                repository.Insert(new UncategorizedMovie { OriginalFile = "file3.avi", EncodedFile = "encoded1.mp4" });
                repository.Insert(new UncategorizedMovie { OriginalFile = "file4.avi", EncodedFile = "encoded1.mp4" });
                repository.Insert(new UncategorizedMovie { OriginalFile = "file5.avi", EncodedFile = "encoded1.mp4" });
                repository.Insert(new UncategorizedMovie { OriginalFile = "file6.avi", EncodedFile = "encoded1.mp4" });
                repository.Insert(new UncategorizedMovie { OriginalFile = "file7.avi", EncodedFile = "encoded1.mp4" });
                repository.Insert(new UncategorizedMovie { OriginalFile = "file8.avi", EncodedFile = "encoded1.mp4" });
                transaction.Commit();
            }

            var genres = new List<Genre>();
            using (var transaction = session.BeginTransaction())
            {
                var repository = new GenreRepository();
                genres.Add(new Genre { Name = "Action" });
                genres.Add(new Genre { Name = "Comedy" });
                genres.Add(new Genre { Name = "Romance" });
                genres.Add(new Genre { Name = "Drama" });
                genres.Add(new Genre { Name = "Thriller" });
                genres.Add(new Genre { Name = "Pron" });
                foreach (var genre in genres)
                    repository.Insert(genre);
                transaction.Commit();
            }

            var people = new List<Person>();
            using (var transaction = session.BeginTransaction())
            {
                var repository = new PersonRepository();
                people.Add(new Person { FirstName = "Brad", LastName = "Pitt" });
                people.Add(new Person { FirstName = "Steve", LastName = "Buscemi" });
                people.Add(new Person { FirstName = "Nicole", LastName = "Kidman" });
                people.Add(new Person { FirstName = "Gwyneth", LastName = "Paltrow" });
                people.Add(new Person { FirstName = "Harrison", LastName = "Ford" });
                people.Add(new Person { FirstName = "Val", LastName = "Kilmer" });
                people.Add(new Person { FirstName = "George", LastName = "Clooney" });
                foreach (var person in people)
                    repository.SaveOrUpdate(person);
                transaction.Commit();
            }

            using (var transaction = session.BeginTransaction())
            {
                var repository = new MovieRepository();
                repository.Insert(new Movie { Name = "Moneyball", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/17e/4e4306015e73d6408900017e/moneyball-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), Producers = GenerateRandomPeople(people), Director = GenerateRandomPeople(people).First(), DateAdded = GenerateRandomDate(), FileLocation = "blah"});
                repository.Insert(new Movie { Name = "Abduction", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/37c/4db301ed5e73d67a8100037c/abduction-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Transformers - Dark of the Moon", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/1ed/4e6fab557b9aa1182c0001ed/transformers-dark-of-the-moon-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "X-Men First Class", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/422/4e5ea6a45e73d6072900c422/x-men-first-class-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Horrible Bosses", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/0f0/4e7e24207b9aa15eb80000f0/horrible-bosses-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Drive", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/017/4e827acd5e73d67843000017/drive-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Thor", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/61f/4e8057b65e73d6709300061f/thor-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Star Wars: Episode IV - A New Hope", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/0ae/4bc90145017a3c57fe0000ae/star-wars-episode-iv-a-new-hope-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Pirates of the Caribbean: On Stranger Tides", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/970/4e5e9a1b5e73d60b31006970/pirates-of-the-caribbean-on-stranger-tides-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Moneyball", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/17e/4e4306015e73d6408900017e/moneyball-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Abduction", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/37c/4db301ed5e73d67a8100037c/abduction-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Transformers - Dark of the Moon", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/1ed/4e6fab557b9aa1182c0001ed/transformers-dark-of-the-moon-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "X-Men First Class", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/422/4e5ea6a45e73d6072900c422/x-men-first-class-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Horrible Bosses", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/0f0/4e7e24207b9aa15eb80000f0/horrible-bosses-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Drive", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/017/4e827acd5e73d67843000017/drive-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Thor", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/61f/4e8057b65e73d6709300061f/thor-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Star Wars: Episode IV - A New Hope", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/0ae/4bc90145017a3c57fe0000ae/star-wars-episode-iv-a-new-hope-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Pirates of the Caribbean: On Stranger Tides", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/970/4e5e9a1b5e73d60b31006970/pirates-of-the-caribbean-on-stranger-tides-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Moneyball", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/17e/4e4306015e73d6408900017e/moneyball-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Abduction", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/37c/4db301ed5e73d67a8100037c/abduction-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Transformers - Dark of the Moon", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/1ed/4e6fab557b9aa1182c0001ed/transformers-dark-of-the-moon-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "X-Men First Class", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/422/4e5ea6a45e73d6072900c422/x-men-first-class-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Horrible Bosses", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/0f0/4e7e24207b9aa15eb80000f0/horrible-bosses-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Drive", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/017/4e827acd5e73d67843000017/drive-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Thor", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/61f/4e8057b65e73d6709300061f/thor-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Star Wars: Episode IV - A New Hope", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/0ae/4bc90145017a3c57fe0000ae/star-wars-episode-iv-a-new-hope-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Pirates of the Caribbean: On Stranger Tides", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/970/4e5e9a1b5e73d60b31006970/pirates-of-the-caribbean-on-stranger-tides-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Moneyball", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/17e/4e4306015e73d6408900017e/moneyball-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Abduction", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/37c/4db301ed5e73d67a8100037c/abduction-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Transformers - Dark of the Moon", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/1ed/4e6fab557b9aa1182c0001ed/transformers-dark-of-the-moon-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "X-Men First Class", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/422/4e5ea6a45e73d6072900c422/x-men-first-class-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Horrible Bosses", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/0f0/4e7e24207b9aa15eb80000f0/horrible-bosses-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Drive", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/017/4e827acd5e73d67843000017/drive-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Thor", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/61f/4e8057b65e73d6709300061f/thor-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Star Wars: Episode IV - A New Hope", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/0ae/4bc90145017a3c57fe0000ae/star-wars-episode-iv-a-new-hope-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Pirates of the Caribbean: On Stranger Tides", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/970/4e5e9a1b5e73d60b31006970/pirates-of-the-caribbean-on-stranger-tides-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Moneyball", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/17e/4e4306015e73d6408900017e/moneyball-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Abduction", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/37c/4db301ed5e73d67a8100037c/abduction-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Transformers - Dark of the Moon", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/1ed/4e6fab557b9aa1182c0001ed/transformers-dark-of-the-moon-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "X-Men First Class", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/422/4e5ea6a45e73d6072900c422/x-men-first-class-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Horrible Bosses", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/0f0/4e7e24207b9aa15eb80000f0/horrible-bosses-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Drive", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/017/4e827acd5e73d67843000017/drive-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Thor", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/61f/4e8057b65e73d6709300061f/thor-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Star Wars: Episode IV - A New Hope", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/0ae/4bc90145017a3c57fe0000ae/star-wars-episode-iv-a-new-hope-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Pirates of the Caribbean: On Stranger Tides", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/970/4e5e9a1b5e73d60b31006970/pirates-of-the-caribbean-on-stranger-tides-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Moneyball", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/17e/4e4306015e73d6408900017e/moneyball-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Abduction", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/37c/4db301ed5e73d67a8100037c/abduction-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Transformers - Dark of the Moon", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/1ed/4e6fab557b9aa1182c0001ed/transformers-dark-of-the-moon-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "X-Men First Class", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/422/4e5ea6a45e73d6072900c422/x-men-first-class-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Horrible Bosses", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/0f0/4e7e24207b9aa15eb80000f0/horrible-bosses-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Drive", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/017/4e827acd5e73d67843000017/drive-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Thor", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/61f/4e8057b65e73d6709300061f/thor-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Star Wars: Episode IV - A New Hope", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/0ae/4bc90145017a3c57fe0000ae/star-wars-episode-iv-a-new-hope-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Pirates of the Caribbean: On Stranger Tides", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/970/4e5e9a1b5e73d60b31006970/pirates-of-the-caribbean-on-stranger-tides-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Moneyball", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/17e/4e4306015e73d6408900017e/moneyball-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Abduction", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/37c/4db301ed5e73d67a8100037c/abduction-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Transformers - Dark of the Moon", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/1ed/4e6fab557b9aa1182c0001ed/transformers-dark-of-the-moon-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "X-Men First Class", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/422/4e5ea6a45e73d6072900c422/x-men-first-class-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Horrible Bosses", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/0f0/4e7e24207b9aa15eb80000f0/horrible-bosses-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Drive", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/017/4e827acd5e73d67843000017/drive-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Thor", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/61f/4e8057b65e73d6709300061f/thor-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Star Wars: Episode IV - A New Hope", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/0ae/4bc90145017a3c57fe0000ae/star-wars-episode-iv-a-new-hope-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                repository.Insert(new Movie { Name = "Pirates of the Caribbean: On Stranger Tides", Description = "blah", Year = DateTime.Now.AddYears(-10), PosterLocation = "http://cf1.imgobject.com/posters/970/4e5e9a1b5e73d60b31006970/pirates-of-the-caribbean-on-stranger-tides-original.jpg", Genres = GenerateRandomGenres(genres), Actors = GenerateRandomPeople(people), DateAdded = GenerateRandomDate(), FileLocation = "blah" });
                transaction.Commit();
            }

            using (var transaction = session.BeginTransaction())
            {
                var userMovieRepository = new UserMovieRepository();
                var movieRepository = new MovieRepository();
                foreach (var movie in movieRepository.GetAll())
                    userMovieRepository.Insert(new UserMovie {User = user, Movie = movie});
                transaction.Commit();
            }

            session.Close();
        }
예제 #7
0
        public void ResetEmpty()
        {
            Configuration configuration = null;
            var session = Fluently
                .Configure()
                .ExposeConfiguration(x => configuration = x)
                .Database(MsSqlConfiguration.MsSql2008.ConnectionString(x => x.FromConnectionStringWithKey("Database")))
                .Mappings(x => x.FluentMappings.AddFromAssemblyOf<UserMap>())
                .BuildSessionFactory()
                .OpenSession();

            SessionProvider.CurrentSession = session;

            new SchemaExport(configuration).Execute(false, true, false);

            var user = new User { EmailAddress = "*****@*****.**", FirstName = "Chris", Identity = "blah", LastName = "Harrington", Password = "******" };
            using (var transaction = session.BeginTransaction())
            {
                session.Save(user);
                transaction.Commit();
            }

            session.Close();
        }