public static void GetCoverArtStreamInfoAsync_PictureHasAccessibleAndInaccessibleFiles_ReturnsPictureDetails()
            {
                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 inaccessibleLibrary   = random.AddLibrary(accessControlled: true);
                    var inaccessibleDirectory = random.AddDirectory(inaccessibleLibrary);
                    var inaccessibleFile      = random.AddFile(inaccessibleDirectory);
                    var inaccessiblePicture   = random.AddPicture(inaccessibleFile);
                    var accessibleLibrary     = random.AddLibrary(accessControlled: false);
                    var accessibleDirectory   = random.AddDirectory(accessibleLibrary);
                    var accessibleFile        = random.AddFile(accessibleDirectory);
                    var accessiblePicture     = random.AddPicture(accessibleFile);
                    dbContext.SaveChanges();

                    var result = RestApiQueries.GetCoverArtStreamInfoAsync(dbContext, user.UserId, accessiblePicture.StreamHash, CancellationToken.None).GetAwaiter().GetResult();

                    Assert.Equal(accessiblePicture.File.Directory.Path, result.DirectoryPath);
                    Assert.Equal(accessiblePicture.File.Name, result.FileName);
                    Assert.Equal(accessiblePicture.StreamIndex, result.StreamIndex);
                }
            }
            public static void GetCoverArtStreamInfoAsync_PictureHasMultipleAccessibleFiles_ReturnsPictureDetails()
            {
                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 picture      = random.AddPicture(file);
                    var otherFile    = random.AddFile(directory);
                    var otherPicture = random.AddPicture(otherFile);
                    otherPicture.StreamHash = picture.StreamHash;
                    dbContext.SaveChanges();

                    var result = RestApiQueries.GetCoverArtStreamInfoAsync(dbContext, user.UserId, picture.StreamHash, CancellationToken.None).GetAwaiter().GetResult();

                    Assert.Equal(picture.File.Directory.Path, result.DirectoryPath);
                    Assert.Contains(new[] { picture.File.Name, otherPicture.File.Name }, x => x == result.FileName);
                    Assert.Equal(picture.StreamIndex, result.StreamIndex);
                }
            }
            public static void GetCoverArtStreamInfoAsync_PictureHasInaccessibleFile_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(accessControlled: true);
                    var directory = random.AddDirectory(library);
                    var file      = random.AddFile(directory);
                    var picture   = random.AddPicture(file);
                    dbContext.SaveChanges();

                    var ex = Assert.Throws <RestApiErrorException>(() => RestApiQueries.GetCoverArtStreamInfoAsync(dbContext, user.UserId, picture.StreamHash, CancellationToken.None).GetAwaiter().GetResult());
                    Assert.Equal(RestApiErrorException.DataNotFoundError().Message, ex.Message);
                }
            }