Esempio n. 1
0
        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();
        }
Esempio n. 2
0
        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();
        }