Ejemplo n.º 1
0
        public void GetAllPlaylist()
        {
            var options = new DbContextOptionsBuilder <FlixContext>()
                          .UseInMemoryDatabase(databaseName: "FlixUsersDatabase")
                          .Options;

            // Insert seed data into the database using one instance of the context
            using (var context = new FlixContext(options))
            {
                context.Playlists.Add(new Playlist {
                    Id = 1, Title = "Mafia", UserId = 1
                });
                context.Playlists.Add(new Playlist {
                    Id = 2, Title = "Comedy", UserId = 1
                });
                context.Playlists.Add(new Playlist {
                    Id = 3, Title = "Action", UserId = 1
                });
                context.Playlists.Add(new Playlist {
                    Id = 4, Title = "Action", UserId = 2
                });
                context.SaveChanges();
            }

            // Use a clean instance of the context to run the test
            using (var context = new FlixContext(options))
            {
                PlaylistRepository playlistRepo = new PlaylistRepository(context);
                var playlists = playlistRepo.GetAllPlaylists();

                Assert.AreEqual(4, playlists.Count);

                context.Dispose();
            }
        }
Ejemplo n.º 2
0
        public void DeleteByPlaylistId()
        {
            var options = new DbContextOptionsBuilder <FlixContext>()
                          .UseInMemoryDatabase(databaseName: "FlixUsersDatabase")
                          .Options;

            // Use a clean instance of the context to run the test
            using (var context = new FlixContext(options))
            {
                PlaylistRepository playlistRepo = new PlaylistRepository(context);
                var playlist       = playlistRepo.DeletePlayListById(1);
                var getAllPlaylist = playlistRepo.GetAllPlaylists();

                Assert.AreEqual(4, getAllPlaylist.Count);

                context.Dispose();
            }
        }