Пример #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();
        }
Пример #2
0
        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();
        }
Пример #3
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();
        }