예제 #1
0
            public static void GetAlbumList2OrderedByArtistNameAsync_LibraryDoesNotExist_ThrowsDataNotFoundError()
            {
                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);
                    dbContext.SaveChanges();

                    var ex = Assert.Throws <RestApiErrorException>(() => RestApiQueries.GetAlbumList2OrderedByArtistNameAsync(dbContext, user.UserId, library.LibraryId + 1, 0, 10, CancellationToken.None).GetAwaiter().GetResult());

                    var expectedException = RestApiErrorException.DataNotFoundError();
                    Assert.Equal(expectedException.Message, ex.Message);
                    Assert.Equal(expectedException.Code, ex.Code);
                }
            }
예제 #2
0
            public static void GetAlbumList2OrderedByArtistNameAsync_LibraryIsSpecified_ReturnsExpectedAlbums()
            {
                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 otherLibrary   = 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 otherDirectory = random.AddDirectory(otherLibrary);
                    var otherFile      = random.AddFile(otherDirectory);
                    var otherTrack     = random.AddTrack(otherFile, artist, album);
                    dbContext.SaveChanges();

                    var result = RestApiQueries.GetAlbumList2OrderedByArtistNameAsync(dbContext, user.UserId, library.LibraryId, 0, 10, CancellationToken.None).GetAwaiter().GetResult();

                    var resultAlbum = Assert.Single(result.album);
                    Assert.Equal("a" + album.AlbumId, resultAlbum.id);
                    Assert.Equal(1, resultAlbum.songCount);
                    Assert.Equal(Math.Round(track.Duration ?? 0), resultAlbum.duration);
                }
            }
예제 #3
0
            public static void GetAlbumList2OrderedByArtistNameAsync_VariousOffsetAndCount_ReturnsExpectedAlbumDetails(int albumCount, int count)
            {
                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 albums  = new List <Album>();
                    var tracks  = new List <Track>();
                    for (int i = 0; i < albumCount; ++i)
                    {
                        var album = random.AddAlbum(artist);
                        albums.Add(album);
                        var directory = random.AddDirectory(library);
                        var file      = random.AddFile(directory);
                        var track     = random.AddTrack(file, artist, album);
                        tracks.Add(track);
                    }
                    dbContext.SaveChanges();

                    albums = albums
                             .OrderBy(a => a.Artist.SortName ?? a.Artist.Name, _stringComparer)
                             .ThenBy(a => a.Date)
                             .ThenBy(a => a.SortTitle ?? a.Title, _stringComparer)
                             .ThenBy(a => a.AlbumId)
                             .ToList();

                    for (int i = 0; i <= albumCount; ++i)
                    {
                        var result = RestApiQueries.GetAlbumList2OrderedByArtistNameAsync(dbContext, user.UserId, null, i, count, CancellationToken.None).GetAwaiter().GetResult();

                        Assert.Equal(albums.Skip(i).Take(count).Select(a => "a" + a.AlbumId).ToArray(),
                                     result.album.Select(a => a.id).ToArray());
                        foreach (var resultAlbum in result.album)
                        {
                            var album       = albums.Single(a => "a" + a.AlbumId == resultAlbum.id);
                            var albumTracks = tracks.Where(t => t.Album == album);

                            Assert.Equal(album.Title, resultAlbum.name);
                            Assert.Equal(album.Artist.Name, resultAlbum.artist);
                            Assert.Equal("r" + album.ArtistId, resultAlbum.artistId);
                            Assert.Equal(album.CoverPictureId?.ToString("X8"), resultAlbum.coverArt);
                            Assert.Equal(albumTracks.Count(), resultAlbum.songCount);
                            Assert.Equal(Math.Round(albumTracks.Sum(t => t.Duration) ?? 0), resultAlbum.duration);
                            Assert.False(resultAlbum.playCountSpecified);
                            Assert.Equal(default, resultAlbum.playCount);