Esempio n. 1
0
        public UnitTest1()
        {
            var options = new DbContextOptionsBuilder <MovieDataContext>().UseInMemoryDatabase(databaseName: "movie_tests").Options;

            //db = MovieRepository();
            db = new MovieDataContext(options);

            db.Movies.AddRange(
                new Movie
            {
                Title    = "The Dark Knight",
                DateSeen = new DateTime(2020, 5, 20),
                Genre    = "Action",
                Rating   = 9
            },
                new Movie
            {
                Title    = "Dude Where's My Car",
                DateSeen = new DateTime(2005, 4, 16),
                Genre    = "Comedy",
                Rating   = 8
            }
                );

            db.SaveChanges();
        }
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new MovieDataContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <MovieDataContext> >()))
            {
                // Look for any movies.
                if (context.Movie.Any())
                {
                    return;   // DB has been seeded
                }

                context.Movie.AddRange(
                    new Movie
                {
                    Name        = "When Harry Met Sally",
                    ReleaseYear = 1989,
                    Description = "Romantic Comedy"
                },

                    new Movie
                {
                    Name        = "Ghostbusters ",
                    ReleaseYear = 1984,
                    Description = "Comedy"
                },

                    new Movie
                {
                    Name        = "Ghostbusters 2",
                    ReleaseYear = 1986,
                    Description = "Comedy"
                },

                    new Movie
                {
                    Name        = "Rio Bravo",
                    ReleaseYear = 1959,
                    Description = "Western"
                }
                    );
                context.SaveChanges();
            }
        }