public static void TestGetUsersAsync() { 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 library1 = random.AddLibrary(); random.AddLibraryUser(library1, user1); var library2 = random.AddLibrary(); random.AddLibraryUser(library2, user1); random.AddLibraryUser(library2, user2); dbContext.SaveChanges(); var result = RestApiQueries.GetUsersAsync(dbContext, CancellationToken.None).GetAwaiter().GetResult(); Assert.NotNull(result); // TODO } }
public static void CanAddTracksAsync_AccessibleAccessControlledTrack_ReturnsTrue() { 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 libraryUser = random.AddLibraryUser(library, user); 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(); int[] trackIds = new[] { track.TrackId }; bool result = RestApiQueries.CanAddTracksAsync(dbContext, user.UserId, trackIds, CancellationToken.None).GetAwaiter().GetResult(); Assert.True(result); } }
public static void GetCoverArtStreamInfoAsync_PictureHasAccessibleAccessControlledFile_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(accessControlled: true); var libraryUser = random.AddLibraryUser(library, user); var directory = random.AddDirectory(library); var file = random.AddFile(directory); var picture = random.AddPicture(file); dbContext.SaveChanges(); var result = RestApiQueries.GetCoverArtStreamInfoAsync(dbContext, user.UserId, picture.StreamHash, CancellationToken.None).GetAwaiter().GetResult(); Assert.Equal(picture.File.Directory.Path, result.DirectoryPath); Assert.Equal(picture.File.Name, result.FileName); Assert.Equal(picture.StreamIndex, result.StreamIndex); } }
public static void GetGenresAsync_GenreHasAcessibleAccessControlledTrack_GenreIsReturned() { 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 libraryUser = random.AddLibraryUser(library, user); var genre = random.AddGenre(); 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 trackGenre = random.AddTrackGenre(track, genre); dbContext.SaveChanges(); var result = RestApiQueries.GetGenresAsync(dbContext, user.UserId, CancellationToken.None).GetAwaiter().GetResult(); var resultGenre = Assert.Single(result.genre); Assert.Equal(genre.Name, resultGenre.Text.Single()); } }
public static void AddPlaylistSongsAsync_AccessibleAccessControledTrack_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(accessControlled: true); var libraryUser = random.AddLibraryUser(library, user); 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); dbContext.SaveChanges(); int[] trackIds = new[] { track.TrackId }; RestApiQueries.AddPlaylistSongsAsync(dbContext, user.UserId, playlist.PlaylistId, trackIds, 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 }, playlistTracks.Select(pt => pt.TrackId).ToArray()); Assert.Equal(Enumerable.Range(0, 1).ToArray(), playlistTracks.Select(pt => pt.Index).ToArray()); } }