Beispiel #1
0
        public async Task ShowSongHelperMessageIsTrueForUpdatedLibrary()
        {
            var song = new LocalSong("C://Song.mp3", TimeSpan.Zero);

            var songFinder = Substitute.For<ILocalSongFinder>();
            songFinder.GetSongsAsync().Returns(Observable.Return(Tuple.Create(song, (byte[])null)));

            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { "C://Song.mp3", new MockFileData("Bla") } });

            using (Library library = new LibraryBuilder().WithFileSystem(fileSystem).WithSongFinder(songFinder).Build())
            {
                Guid accessToken = library.LocalAccessControl.RegisterLocalAccessToken();

                // NB: System.IO.Abstractions only likes backslashes
                library.ChangeSongSourcePath("C:\\", accessToken);

                var vm = new LocalViewModel(library, new ViewSettings(), new CoreSettings(), accessToken);

                await library.AwaitInitializationAndUpdate();

                Assert.False(vm.ShowAddSongsHelperMessage);
            }
        }
Beispiel #2
0
            public async Task UpdateRemovesArtworkOnlyWithoutReferenceToSong()
            {
                var existingSong = new LocalSong("C://Existing.mp3", TimeSpan.Zero, "artwork-abcdefg");
                var missingSong = new LocalSong("C://Missing.mp3", TimeSpan.Zero, "artwork-abcdefg");
                await BlobCache.LocalMachine.Insert("artwork-abcdefg", new byte[] { 0, 1 });

                var libraryReader = Substitute.For<ILibraryReader>();
                libraryReader.LibraryExists.Returns(true);
                libraryReader.ReadSongSourcePath().Returns("C://");
                libraryReader.ReadPlaylists().Returns(new List<Playlist>());
                libraryReader.ReadSongs().Returns(new[] { existingSong, missingSong });

                var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { existingSong.OriginalPath, new MockFileData("DontCare") } });

                using (Library library = new LibraryBuilder().WithFileSystem(fileSystem).WithReader(libraryReader).Build())
                {
                    await library.AwaitInitializationAndUpdate();

                    Assert.NotNull(BlobCache.LocalMachine.GetAllKeys().FirstOrDefault(x => x == "artwork-abcdefg"));
                }
            }
Beispiel #3
0
            public async Task UpdateRemovesArtworkWhenSongIsMissing()
            {
                var missingSong = new LocalSong("C://Missing.mp3", TimeSpan.Zero, "artwork-abcdefg");
                await BlobCache.LocalMachine.Insert("artwork-abcdefg", new byte[] { 0, 1 });

                var libraryReader = Substitute.For<ILibraryReader>();
                libraryReader.LibraryExists.Returns(true);
                libraryReader.ReadSongSourcePath().Returns("C://");
                libraryReader.ReadPlaylists().Returns(new List<Playlist>());
                libraryReader.ReadSongs().Returns(new[] { missingSong });

                var fileSystem = new MockFileSystem();
                fileSystem.Directory.CreateDirectory("C://");

                using (Library library = new LibraryBuilder().WithFileSystem(fileSystem).WithReader(libraryReader).Build())
                {
                    await library.AwaitInitializationAndUpdate();

                    Assert.Null(BlobCache.LocalMachine.GetAllKeys().FirstOrDefault(x => x == "artwork-abcdefg"));
                }
            }
Beispiel #4
0
            public async Task UpdateRemovesMissingSongWithoutArtworkFromLibraryWhenOtherArtworksArePresent()
            {
                var existingSong = new LocalSong("C://Existing.mp3", TimeSpan.Zero, "artwork-abcdefg");
                var missingSong = new LocalSong("C://Missing.mp3", TimeSpan.Zero);

                var libraryReader = Substitute.For<ILibraryReader>();
                libraryReader.LibraryExists.Returns(true);
                libraryReader.ReadSongSourcePath().Returns("C://");
                libraryReader.ReadPlaylists().Returns(new List<Playlist>());
                libraryReader.ReadSongs().Returns(new[] { existingSong, missingSong });

                var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { existingSong.OriginalPath, new MockFileData("DontCare") } });

                using (Library library = new LibraryBuilder().WithFileSystem(fileSystem).WithReader(libraryReader).Build())
                {
                    await library.AwaitInitializationAndUpdate();

                    Assert.Equal(1, library.Songs.Count());
                }
            }
Beispiel #5
0
            public async Task ExternalTagChangesArePropagated()
            {
                var song = new LocalSong("C://Song.mp3", TimeSpan.Zero) { Title = "A" };
                var updatedSong = new LocalSong("C://Song.mp3", TimeSpan.Zero) { Title = "B" };

                var libraryReader = Substitute.For<ILibraryReader>();
                libraryReader.LibraryExists.Returns(true);
                libraryReader.ReadSongSourcePath().Returns("C://");
                libraryReader.ReadPlaylists().Returns(new List<Playlist>());
                libraryReader.ReadSongs().Returns(new[] { song });

                var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { song.OriginalPath, new MockFileData("DontCare") } });

                var songFinder = Substitute.For<ILocalSongFinder>();
                songFinder.GetSongsAsync().Returns(Observable.Return(Tuple.Create(updatedSong, (byte[])null)));

                using (Library library = new LibraryBuilder().WithFileSystem(fileSystem).WithReader(libraryReader).WithSongFinder(songFinder).Build())
                {
                    await library.AwaitInitializationAndUpdate();

                    Assert.Equal("B", library.Songs[0].Title);
                }
            }
Beispiel #6
0
            public async Task UpdateRemovesMissingSongsFromPlaylists()
            {
                var existingSong = new LocalSong("C://Existing.mp3", TimeSpan.Zero);
                var missingSong = new LocalSong("C://Missing.mp3", TimeSpan.Zero);

                var songs = new[] { existingSong, missingSong };

                var playlist1 = new Playlist("Playlist 1");
                playlist1.AddSongs(songs);

                var playlist2 = new Playlist("Playlist 2");
                playlist2.AddSongs(songs);

                var libraryReader = Substitute.For<ILibraryReader>();
                libraryReader.LibraryExists.Returns(true);
                libraryReader.ReadSongSourcePath().Returns("C://");
                libraryReader.ReadPlaylists().Returns(new[] { playlist1, playlist2 });
                libraryReader.ReadSongs().Returns(songs);

                var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { existingSong.OriginalPath, new MockFileData("DontCare") } });

                using (Library library = new LibraryBuilder().WithFileSystem(fileSystem).WithReader(libraryReader).Build())
                {
                    await library.AwaitInitializationAndUpdate();

                    Assert.Equal(1, library.Playlists[0].Count());
                    Assert.Equal(1, library.Playlists[1].Count());
                }
            }
Beispiel #7
0
            public async Task SmokeTest()
            {
                var fileSystem = new MockFileSystem();
                fileSystem.Directory.CreateDirectory("C://Test");

                using (var library = new LibraryBuilder().WithFileSystem(fileSystem).Build())
                {
                    Guid token = library.LocalAccessControl.RegisterLocalAccessToken();

                    library.ChangeSongSourcePath("C://Test", token);

                    var isUpdating = library.WhenAnyValue(x => x.IsUpdating).CreateCollection();

                    var last = library.WhenAnyValue(x => x.IsUpdating).Where(x => !x).ElementAt(1).PublishLast();
                    last.Connect();

                    await library.AwaitInitializationAndUpdate();

                    Assert.Equal(new[] { false, true, false }, isUpdating);
                }
            }
Beispiel #8
0
            public async Task InvokesSongsUpdatedObservableWhenSongMetadataChanged()
            {
                var artworkKey = BlobCacheKeys.GetKeyForArtwork(new byte[] { 0, 1 });
                var song = new LocalSong("C://Song.mp3", TimeSpan.Zero, artworkKey)
                {
                    Album = "Album-A",
                    Artist = "Artist-A",
                    Title = "Title-A",
                    Genre = "Genre-A"
                };

                byte[] updatedArtworkData = { 1, 0 };
                var updatedSong = new LocalSong("C://Song.mp3", TimeSpan.Zero)
                {
                    Album = "Album-B",
                    Artist = "Artist-B",
                    Title = "Title-B",
                    Genre = "Genre-B"
                };

                var libraryReader = Substitute.For<ILibraryReader>();
                libraryReader.LibraryExists.Returns(true);
                libraryReader.ReadSongSourcePath().Returns("C://");
                libraryReader.ReadPlaylists().Returns(new List<Playlist>());
                libraryReader.ReadSongs().Returns(new[] { song });

                var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { song.OriginalPath, new MockFileData("DontCare") } });

                var songFinder = Substitute.For<ILocalSongFinder>();
                songFinder.GetSongsAsync().Returns(Observable.Return(Tuple.Create(updatedSong, updatedArtworkData)));

                using (Library library = new LibraryBuilder().WithFileSystem(fileSystem).WithReader(libraryReader).WithSongFinder(songFinder).Build())
                {
                    var update = library.SongsUpdated.CreateCollection();

                    await library.AwaitInitializationAndUpdate();

                    Assert.Equal(1, update.Count); ;
                }
            }
Beispiel #9
0
            public async Task InvokesSongsUpdatedObservableWhenSongAdded()
            {
                var song = new LocalSong("C://Song.mp3", TimeSpan.Zero);

                var libraryReader = Substitute.For<ILibraryReader>();
                libraryReader.LibraryExists.Returns(true);
                libraryReader.ReadSongSourcePath().Returns("C://");
                libraryReader.ReadPlaylists().Returns(new List<Playlist>());
                libraryReader.ReadSongs().Returns(new List<LocalSong>());

                var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { song.OriginalPath, new MockFileData("DontCare") } });

                var songFinder = Substitute.For<ILocalSongFinder>();
                songFinder.GetSongsAsync().Returns(Observable.Return(Tuple.Create(song, (byte[])null)));

                using (Library library = new LibraryBuilder().WithFileSystem(fileSystem).WithReader(libraryReader).WithSongFinder(songFinder).Build())
                {
                    var update = library.SongsUpdated.CreateCollection();

                    await library.AwaitInitializationAndUpdate();

                    Assert.Equal(1, update.Count);
                }
            }
Beispiel #10
0
            public async Task ExternalTagChangesArePropagated()
            {
                var artworkKey = BlobCacheKeys.GetKeyForArtwork(new byte[] { 0, 1 });
                var song = new LocalSong("C://Song.mp3", TimeSpan.Zero, artworkKey)
                {
                    Album = "Album-A",
                    Artist = "Artist-A",
                    Title = "Title-A",
                    Genre = "Genre-A"
                };

                byte[] updatedArtworkData = { 1, 0 };
                var updatedSong = new LocalSong("C://Song.mp3", TimeSpan.Zero)
                {
                    Album = "Album-B",
                    Artist = "Artist-B",
                    Title = "Title-B",
                    Genre = "Genre-B"
                };

                var libraryReader = Substitute.For<ILibraryReader>();
                libraryReader.LibraryExists.Returns(true);
                libraryReader.ReadSongSourcePath().Returns("C://");
                libraryReader.ReadPlaylists().Returns(new List<Playlist>());
                libraryReader.ReadSongs().Returns(new[] { song });

                var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { song.OriginalPath, new MockFileData("DontCare") } });

                var songFinder = Substitute.For<ILocalSongFinder>();
                songFinder.GetSongsAsync().Returns(Observable.Return(Tuple.Create(updatedSong, updatedArtworkData)));

                using (Library library = new LibraryBuilder().WithFileSystem(fileSystem).WithReader(libraryReader).WithSongFinder(songFinder).Build())
                {
                    await library.AwaitInitializationAndUpdate();

                    Assert.True(ReferenceEquals(song, library.Songs[0]));

                    Assert.Equal(updatedSong.Album, song.Album);
                    Assert.Equal(updatedSong.Artist, song.Artist);
                    Assert.Equal(BlobCacheKeys.GetKeyForArtwork(updatedArtworkData), song.ArtworkKey);
                    Assert.Equal(updatedSong.Genre, song.Genre);
                    Assert.Equal(updatedSong.Title, song.Title);
                }
            }