public static void TestUnstarAlbumAsync() { 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 artist = random.AddArtist(); var album = random.AddAlbum(artist); var albumStar = random.AddAlbumStar(album, user); dbContext.SaveChanges(); for (int i = 0; i < 2; ++i) { RestApiQueries.UnstarAlbumAsync(dbContext, user.UserId, album.AlbumId, CancellationToken.None).GetAwaiter().GetResult(); dbContext.SaveChanges(); Assert.False(dbContext.AlbumStars.Any(s => s.AlbumId == album.AlbumId && s.UserId == user.UserId)); } } }
public static void TestGetStarred2Async() { 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 genre = random.AddGenre(); var artist = random.AddArtist(); var album = random.AddAlbum(artist); var track = random.AddTrack(trackFile, artist, album, genre: genre); var artistStar = random.AddArtistStar(artist, user); var albumStar = random.AddAlbumStar(album, user); var trackStar = random.AddTrackStar(track, user); dbContext.SaveChanges(); var result = RestApiQueries.GetStarred2Async(dbContext, user.UserId, null, "opus", CancellationToken.None).GetAwaiter().GetResult(); Assert.NotNull(result); // TODO } }
public static void GetAlbumList2StarredAsync_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 albumStar = random.AddAlbumStar(album, user); 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.GetAlbumList2StarredAsync(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); } }
public static void GetAlbumList2StarredAsync_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 albumStar = random.AddAlbumStar(album, user); 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.GetAlbumList2StarredAsync(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); } }
public static void GetAlbumList2StarredAsync_AlbumHasStarFromOtherUser_AlbumIsNotReturned() { 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 otherUser = random.AddUser(); var library = random.AddLibrary(accessControlled: false); var artist = random.AddArtist(); var album = random.AddAlbum(artist); var albumStar = random.AddAlbumStar(album, otherUser); var directory = random.AddDirectory(library); var file = random.AddFile(directory); var track = random.AddTrack(file, artist, album); dbContext.SaveChanges(); var result = RestApiQueries.GetAlbumList2StarredAsync(dbContext, user.UserId, null, 0, 10, CancellationToken.None).GetAwaiter().GetResult(); Assert.Empty(result.album); } }
public static void GetAlbumList2StarredAsync_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 albumStars = new List <AlbumStar>(); var tracks = new List <Track>(); for (int i = 0; i < albumCount; ++i) { var album = random.AddAlbum(artist); albums.Add(album); var albumStar = random.AddAlbumStar(album, user); albumStars.Add(albumStar); 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.SortTitle ?? a.Title, _stringComparer) .ThenBy(a => a.AlbumId) .ToList(); for (int i = 0; i <= albumCount; ++i) { var result = RestApiQueries.GetAlbumList2StarredAsync(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 albumStar = albumStars.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);