public void ApplicationLoadedEventHandler_IfNoPlaylistSessionDataExist_DoesNotLoadAnySongs() { // Arrange var sessionServiceStub = new Mock <ISessionDataService>(); sessionServiceStub.Setup(x => x.GetData <PlaylistData>("SongPlaylistData", It.IsAny <CancellationToken>())).ReturnsAsync((PlaylistData)null); var mocker = new AutoMocker(); mocker.Use(sessionServiceStub); var target = mocker.CreateInstance <PersistentPlaylistViewModel>(); PlaylistLoadedEventArgs playlistLoadedEvent = null; Messenger.Default.Register <PlaylistLoadedEventArgs>(this, e => e.RegisterEvent(ref playlistLoadedEvent)); NoPlaylistLoadedEventArgs noPlaylistLoadedEvent = null; Messenger.Default.Register <NoPlaylistLoadedEventArgs>(this, e => e.RegisterEvent(ref noPlaylistLoadedEvent)); // Act Messenger.Default.Send(new ApplicationLoadedEventArgs()); // Assert target.Songs.Should().BeEmpty(); playlistLoadedEvent.Should().BeNull(); noPlaylistLoadedEvent.Should().NotBeNull(); }
private async void OnPlaylistLoaded(PlaylistLoadedEventArgs e, CancellationToken cancellationToken) { var disc = e.Disc; if (disc != null) { SwitchToDisc(disc); } else { await LoadRootFolder(cancellationToken); } }
public void ApplicationLoadedEventHandler_IfValidPlaylistSessionDataExist_LoadsPlaylistSongsCorrectly() { // Arrange var playlistData = new PlaylistData { Songs = new[] { new PlaylistSongData { Id = "song 0" }, new PlaylistSongData { Id = "song 1" }, new PlaylistSongData { Id = "song 2" }, new PlaylistSongData { Id = "song 3" }, }, CurrentSongIndex = 1, }; var songIds = new[] { new ItemId("song 0"), new ItemId("song 1"), new ItemId("song 2"), new ItemId("song 3"), }; var songs = new[] { new SongModel { Id = new ItemId("song 0") }, new SongModel { Id = new ItemId("song 1") }, new SongModel { Id = new ItemId("song 2") }, new SongModel { Id = new ItemId("song 3") }, }; // ISongsService.GetSongs() does not guarantee songs order. var songsReturnedByService = new[] { songs[3], songs[2], songs[0], songs[1] }; var sessionServiceStub = new Mock <ISessionDataService>(); sessionServiceStub.Setup(x => x.GetData <PlaylistData>("SongPlaylistData", It.IsAny <CancellationToken>())).ReturnsAsync(playlistData); var songServiceStub = new Mock <ISongsService>(); songServiceStub.Setup(x => x.GetSongs(songIds, It.IsAny <CancellationToken>())).ReturnsAsync(songsReturnedByService); var mocker = new AutoMocker(); mocker.Use(sessionServiceStub); mocker.Use(songServiceStub); var target = mocker.CreateInstance <PersistentPlaylistViewModel>(); PlaylistLoadedEventArgs playlistLoadedEvent = null; Messenger.Default.Register <PlaylistLoadedEventArgs>(this, e => e.RegisterEvent(ref playlistLoadedEvent)); NoPlaylistLoadedEventArgs noPlaylistLoadedEvent = null; Messenger.Default.Register <NoPlaylistLoadedEventArgs>(this, e => e.RegisterEvent(ref noPlaylistLoadedEvent)); PlaylistChangedEventArgs playlistChangedEventArgs = null; Messenger.Default.Register <PlaylistChangedEventArgs>(this, e => e.RegisterEvent(ref playlistChangedEventArgs)); var propertyChangedEvents = new List <PropertyChangedEventArgs>(); target.PropertyChanged += (_, e) => propertyChangedEvents.Add(e); // Act Messenger.Default.Send(new ApplicationLoadedEventArgs()); // Assert target.Songs.Should().BeEquivalentTo(songs, x => x.WithStrictOrdering()); target.CurrentSong.Should().Be(songs[1]); playlistLoadedEvent.VerifyPlaylistEvent(songs, 1); noPlaylistLoadedEvent.Should().BeNull(); propertyChangedEvents.VerifySongListPropertyChangedEvents(); }
public void ApplicationLoadedEventHandler_IfSomeSongsAreNotFound_DoesNotLoadPlaylist() { // Arrange var playlistData = new PlaylistData { Songs = new[] { new PlaylistSongData { Id = "song 0" }, new PlaylistSongData { Id = "song 1" }, new PlaylistSongData { Id = "song 2" }, }, CurrentSongIndex = 0, }; var loadedSongs = new[] { new SongModel { Id = new ItemId("song 0") }, new SongModel { Id = new ItemId("song 2") }, }; var sessionServiceStub = new Mock <ISessionDataService>(); sessionServiceStub.Setup(x => x.GetData <PlaylistData>("SongPlaylistData", It.IsAny <CancellationToken>())).ReturnsAsync(playlistData); var songServiceStub = new Mock <ISongsService>(); songServiceStub.Setup(x => x.GetSongs(It.IsAny <IEnumerable <ItemId> >(), It.IsAny <CancellationToken>())).ReturnsAsync(loadedSongs); var mocker = new AutoMocker(); mocker.Use(sessionServiceStub); mocker.Use(songServiceStub); var target = mocker.CreateInstance <PersistentPlaylistViewModel>(); PlaylistLoadedEventArgs playlistLoadedEvent = null; Messenger.Default.Register <PlaylistLoadedEventArgs>(this, e => e.RegisterEvent(ref playlistLoadedEvent)); NoPlaylistLoadedEventArgs noPlaylistLoadedEvent = null; Messenger.Default.Register <NoPlaylistLoadedEventArgs>(this, e => e.RegisterEvent(ref noPlaylistLoadedEvent)); // Act Messenger.Default.Send(new ApplicationLoadedEventArgs()); // Assert target.Songs.Should().BeEmpty(); playlistLoadedEvent.Should().BeNull(); noPlaylistLoadedEvent.Should().NotBeNull(); }
public void ApplicationLoadedEventHandler_IfSomeSongsAreDeleted_SkipsDeletedSongsFromLoading() { // Arrange var playlistData = new PlaylistData { Songs = new[] { new PlaylistSongData { Id = "active song 0" }, new PlaylistSongData { Id = "deleted song 1" }, new PlaylistSongData { Id = "active song 2" }, new PlaylistSongData { Id = "deleted song 3" }, }, // Current song index is set between deleted songs, so that we could test index adjustment. CurrentSongIndex = 2, }; var loadedSongs = new[] { new SongModel { Id = new ItemId("active song 2") }, new SongModel { // Song title for deleted song is logged differently depending on whether it has track number or not. // That's why first deleted song has track number and 2nd does not. Id = new ItemId("deleted song 1"), TrackNumber = 1, DeleteDate = new DateTime(2021, 07, 11), }, new SongModel { Id = new ItemId("active song 0") }, new SongModel { Id = new ItemId("deleted song 3"), TrackNumber = null, DeleteDate = new DateTime(2021, 07, 11), }, }; var sessionServiceStub = new Mock <ISessionDataService>(); sessionServiceStub.Setup(x => x.GetData <PlaylistData>("SongPlaylistData", It.IsAny <CancellationToken>())).ReturnsAsync(playlistData); var songServiceStub = new Mock <ISongsService>(); songServiceStub.Setup(x => x.GetSongs(It.IsAny <IEnumerable <ItemId> >(), It.IsAny <CancellationToken>())).ReturnsAsync(loadedSongs); var mocker = new AutoMocker(); mocker.Use(sessionServiceStub); mocker.Use(songServiceStub); var target = mocker.CreateInstance <PersistentPlaylistViewModel>(); PlaylistLoadedEventArgs playlistLoadedEvent = null; Messenger.Default.Register <PlaylistLoadedEventArgs>(this, e => e.RegisterEvent(ref playlistLoadedEvent)); PlaylistChangedEventArgs playlistChangedEventArgs = null; Messenger.Default.Register <PlaylistChangedEventArgs>(this, e => e.RegisterEvent(ref playlistChangedEventArgs)); // Act Messenger.Default.Send(new ApplicationLoadedEventArgs()); // Assert var expectedSongs = new[] { loadedSongs[2], loadedSongs[0], }; target.Songs.Should().BeEquivalentTo(expectedSongs, x => x.WithStrictOrdering()); target.CurrentSong.Should().Be(expectedSongs[1]); playlistLoadedEvent.VerifyPlaylistEvent(expectedSongs, 1); }
public void ApplicationLoadedEventHandler_IfCurrentSongInPlaylistDataIsNotSet_LoadsPlaylistCorrectly() { // Arrange var playlistData = new PlaylistData { Songs = new[] { new PlaylistSongData { Id = "song 0" }, new PlaylistSongData { Id = "song 1" }, }, CurrentSongIndex = null, }; var songs = new[] { new SongModel { Id = new ItemId("song 0") }, new SongModel { Id = new ItemId("song 1") }, }; var sessionServiceStub = new Mock <ISessionDataService>(); sessionServiceStub.Setup(x => x.GetData <PlaylistData>("SongPlaylistData", It.IsAny <CancellationToken>())).ReturnsAsync(playlistData); var songServiceStub = new Mock <ISongsService>(); songServiceStub.Setup(x => x.GetSongs(It.IsAny <IEnumerable <ItemId> >(), It.IsAny <CancellationToken>())).ReturnsAsync(songs); var mocker = new AutoMocker(); mocker.Use(sessionServiceStub); mocker.Use(songServiceStub); var target = mocker.CreateInstance <PersistentPlaylistViewModel>(); PlaylistLoadedEventArgs playlistLoadedEvent = null; Messenger.Default.Register <PlaylistLoadedEventArgs>(this, e => e.RegisterEvent(ref playlistLoadedEvent)); PlaylistChangedEventArgs playlistChangedEventArgs = null; Messenger.Default.Register <PlaylistChangedEventArgs>(this, e => e.RegisterEvent(ref playlistChangedEventArgs)); // Act Messenger.Default.Send(new ApplicationLoadedEventArgs()); // Assert target.Songs.Should().BeEquivalentTo(songs, x => x.WithStrictOrdering()); target.CurrentSong.Should().BeNull(); playlistLoadedEvent.VerifyPlaylistEvent(songs, null); }