public static void DeletePlaylistAsync_PlaylistOwnedByUser_DeletesPlaylist(bool playlistIsPublic)
            {
                var dbConnection = OpenSqliteDatabase();

                var dbContextOptionsBuilder = new DbContextOptionsBuilder <MediaInfoContext>()
                                              .DisableClientSideEvaluation()
                                              .UseSqlite(dbConnection);

                using (var dbContext = new MediaInfoContext(dbContextOptionsBuilder.Options))
                {
                    var random        = new RandomPopulator(dbContext);
                    var user          = random.AddUser();
                    var library       = random.AddLibrary();
                    var directory     = random.AddDirectory(library);
                    var file          = random.AddFile(directory);
                    var artist        = random.AddArtist();
                    var album         = random.AddAlbum(artist);
                    var track         = random.AddTrack(file, artist, album);
                    var playlist      = random.AddPlaylist(user, playlistIsPublic);
                    var playlistTrack = random.AddPlaylistTrack(playlist, track, 0);
                    dbContext.SaveChanges();

                    bool canDeleteAllPublicPlaylists = true;
                    RestApiQueries.DeletePlaylistAsync(dbContext, user.UserId, canDeleteAllPublicPlaylists, playlist.PlaylistId, CancellationToken.None).GetAwaiter().GetResult();
                    dbContext.SaveChanges();

                    Assert.False(dbContext.Playlists.Any(p => p.PlaylistId == playlist.PlaylistId));
                }
            }
            public static void DeletePlaylistAsync_PlaylistDoesNotExist_ThrowsDataNotFoundError(bool canDeleteAllPublicPlaylists)
            {
                var dbConnection = OpenSqliteDatabase();

                var dbContextOptionsBuilder = new DbContextOptionsBuilder <MediaInfoContext>()
                                              .DisableClientSideEvaluation()
                                              .UseSqlite(dbConnection);

                using (var dbContext = new MediaInfoContext(dbContextOptionsBuilder.Options))
                {
                    var random   = new RandomPopulator(dbContext);
                    var user     = random.AddUser();
                    var playlist = random.AddPlaylist(user);
                    dbContext.SaveChanges();

                    var ex = Assert.Throws <RestApiErrorException>(() => RestApiQueries.DeletePlaylistAsync(dbContext, user.UserId, canDeleteAllPublicPlaylists, playlist.PlaylistId + 1, CancellationToken.None).GetAwaiter().GetResult());

                    var expectedException = RestApiErrorException.DataNotFoundError();
                    Assert.Equal(expectedException.Message, ex.Message);
                    Assert.Equal(expectedException.Code, ex.Code);
                }
            }
            public static void DeletePlaylistAsync_PublicPlaylistOwnedByOtherUserAndNotCanDeleteAllPublicPlaylists_ThrowsUserNotAuthorizedError()
            {
                var dbConnection = OpenSqliteDatabase();

                var dbContextOptionsBuilder = new DbContextOptionsBuilder <MediaInfoContext>()
                                              .DisableClientSideEvaluation()
                                              .UseSqlite(dbConnection);

                using (var dbContext = new MediaInfoContext(dbContextOptionsBuilder.Options))
                {
                    var random   = new RandomPopulator(dbContext);
                    var user1    = random.AddUser();
                    var user2    = random.AddUser();
                    var playlist = random.AddPlaylist(user1, @public: true);
                    dbContext.SaveChanges();

                    bool canDeleteAllPublicPlaylists = false;
                    var  ex = Assert.Throws <RestApiErrorException>(() => RestApiQueries.DeletePlaylistAsync(dbContext, user2.UserId, canDeleteAllPublicPlaylists, playlist.PlaylistId, CancellationToken.None).GetAwaiter().GetResult());

                    var expectedException = RestApiErrorException.UserNotAuthorizedError();
                    Assert.Equal(expectedException.Message, ex.Message);
                    Assert.Equal(expectedException.Code, ex.Code);
                }
            }