public static void TestRemovePlaylistSongsAsync()
            {
                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 trackFile      = random.AddFile(directory);
                    var artist         = random.AddArtist();
                    var album          = random.AddAlbum(artist);
                    var track1         = random.AddTrack(trackFile, artist, album);
                    var track2         = random.AddTrack(trackFile, artist, album);
                    var playlist       = random.AddPlaylist(user);
                    var playlistTrack1 = random.AddPlaylistTrack(playlist, track1, 0);
                    var playlistTrack2 = random.AddPlaylistTrack(playlist, track2, 1);
                    dbContext.SaveChanges();

                    RestApiQueries.RemovePlaylistSongsAsync(dbContext, user.UserId, playlist.PlaylistId, new[] { 0 }, CancellationToken.None).GetAwaiter().GetResult();
                    dbContext.SaveChanges();

                    Assert.False(dbContext.PlaylistTracks.Any(pt => pt.PlaylistId == playlist.PlaylistId && pt.TrackId == track1.TrackId));
                    Assert.True(dbContext.PlaylistTracks.Any(pt => pt.PlaylistId == playlist.PlaylistId && pt.TrackId == track2.TrackId));
                }
            }
            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));
                }
            }
Exemple #3
0
            public static void AddPlaylistSongsAsync_DuplicateTrack_AddsTracksToPlaylist()
            {
                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 artist        = random.AddArtist();
                    var album         = random.AddAlbum(artist);
                    var directory     = random.AddDirectory(library);
                    var file          = random.AddFile(directory);
                    var track         = random.AddTrack(file, artist, album);
                    var playlist      = random.AddPlaylist(user);
                    var playlistTrack = random.AddPlaylistTrack(playlist, track, 0);
                    dbContext.SaveChanges();

                    RestApiQueries.AddPlaylistSongsAsync(dbContext, user.UserId, playlist.PlaylistId, new[] { track.TrackId }, CancellationToken.None).GetAwaiter().GetResult();
                    dbContext.SaveChanges();

                    var playlistTracks = dbContext.PlaylistTracks
                                         .Where(pt => pt.PlaylistId == playlist.PlaylistId)
                                         .OrderBy(pt => pt.Index);
                    Assert.Equal(new[] { track.TrackId, track.TrackId }, playlistTracks.Select(pt => pt.TrackId).ToArray());
                    Assert.Equal(Enumerable.Range(0, 2).ToArray(), playlistTracks.Select(pt => pt.Index).ToArray());
                }
            }
Exemple #4
0
            public static void TestGetPlaylistAsync()
            {
                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 trackFile     = random.AddFile(directory);
                    var artist        = random.AddArtist();
                    var album         = random.AddAlbum(artist);
                    var track         = random.AddTrack(trackFile, artist, album);
                    var playlist      = random.AddPlaylist(user);
                    var playlistTrack = random.AddPlaylistTrack(playlist, track, 0);
                    dbContext.SaveChanges();

                    var result = RestApiQueries.GetPlaylistAsync(dbContext, user.UserId, playlist.PlaylistId, "opus", CancellationToken.None).GetAwaiter().GetResult();

                    Assert.NotNull(result);
                    // TODO
                }
            }
Exemple #5
0
            public static void AddPlaylistSongsAsync_VariousExistingAndAddedTrackCounts_AddsTracksToPlaylist(int tracksInPlaylistCount, int tracksToAddCount)
            {
                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 artist    = random.AddArtist();
                    var album     = random.AddAlbum(artist);
                    var directory = random.AddDirectory(library);
                    var file      = random.AddFile(directory);
                    var playlist  = random.AddPlaylist(user);
                    var tracks    = new List <Track>();
                    for (int i = 0; i < tracksInPlaylistCount; ++i)
                    {
                        var track = random.AddTrack(file, artist, album);
                        tracks.Add(track);
                        var playlistTrack = random.AddPlaylistTrack(playlist, track, i);
                    }
                    var tracksToAdd = new List <Track>();
                    for (int i = 0; i < tracksToAddCount; ++i)
                    {
                        var track = random.AddTrack(file, artist, album);
                        tracksToAdd.Add(track);
                    }
                    dbContext.SaveChanges();

                    int[] trackIdsToAdd = tracksToAdd.Select(t => t.TrackId).ToArray();
                    RestApiQueries.AddPlaylistSongsAsync(dbContext, user.UserId, playlist.PlaylistId, trackIdsToAdd, CancellationToken.None).GetAwaiter().GetResult();
                    dbContext.SaveChanges();

                    int[] expectedTrackIds = tracks.Concat(tracksToAdd).Select(t => t.TrackId).ToArray();

                    var playlistTracks = dbContext.PlaylistTracks
                                         .Where(pt => pt.PlaylistId == playlist.PlaylistId)
                                         .OrderBy(pt => pt.Index);
                    Assert.Equal(expectedTrackIds, playlistTracks.Select(pt => pt.TrackId).ToArray());
                    Assert.Equal(Enumerable.Range(0, expectedTrackIds.Length).ToArray(), playlistTracks.Select(pt => pt.Index).ToArray());
                }
            }