コード例 #1
0
        public async void TestSongNotSelectedException()
        {
            var playList = _defaultPlayList.DeepClone();
            var emptyPlayList = _defaultPlayList.DeepClone();
            emptyPlayList["song"] = new JArray();
            var serverConnectionMock = new Mock<IServerConnection>();
            serverConnectionMock.Setup(s => s.Get(It.Is<Uri>(u => u.AbsolutePath.EndsWith("playlist") && u.GetQueries().Contains(new KeyValuePair<string, string>("type", "n"))),
                It.IsAny<Action<HttpWebRequest>>())).ReturnsAsync(playList.ToString()).Verifiable();
            serverConnectionMock.Setup(s => s.Get(It.Is<Uri>(u => u.AbsolutePath.EndsWith("playlist") && u.GetQueries().Contains(new KeyValuePair<string, string>("type", "p"))),
                It.IsAny<Action<HttpWebRequest>>())).ReturnsAsync(playList.ToString()).Verifiable();
            serverConnectionMock.Setup(s => s.Get(It.Is<Uri>(u => u.AbsolutePath.EndsWith("playlist") && u.GetQueries().Contains(new KeyValuePair<string, string>("type", "s"))),
                It.IsAny<Action<HttpWebRequest>>())).ReturnsAsync(emptyPlayList.ToString()).Verifiable();

            var session = new Session(serverConnectionMock.Object);
            var player = new Player(session);
            await player.ChangeChannel(new Channel(0));
            await AssertEx.ThrowsAsync<NoAvailableSongsException>(async () => await player.Next(NextCommandType.SkipCurrentSong));
            Assert.IsNotNull(player.CurrentChannel);
            Assert.IsNull(player.CurrentSong);
            await AssertEx.ThrowsAsync<SongNotSelectedException>(async () => await player.SetRedHeart(true));
        }
コード例 #2
0
        public async void TestNoAvailableSongs_SetRedHeart(bool redHeart)
        {
            var emptyPlayList = _defaultPlayList.DeepClone();
            emptyPlayList["song"] = new JArray();
            var serverConnectionMock = new Mock<IServerConnection>();
            serverConnectionMock.Setup(s => s.Get(It.Is<Uri>(u => u.AbsolutePath.EndsWith("playlist") && u.GetQueries().Contains(new KeyValuePair<string, string>("type", "n"))),
                It.IsAny<Action<HttpWebRequest>>())).ReturnsAsync(Resource.PlayList).Verifiable();
            serverConnectionMock.Setup(s => s.Get(It.Is<Uri>(u => u.AbsolutePath.EndsWith("playlist") && u.GetQueries().Contains(new KeyValuePair<string, string>("type", GetReportTypeStringByRedHeart(redHeart)))),
                It.IsAny<Action<HttpWebRequest>>())).ReturnsAsync(emptyPlayList.ToString()).Verifiable();

            var player = new Player(new Session(serverConnectionMock.Object));
            await player.ChangeChannel(new Channel(0));
            await AssertEx.ThrowsAsync<NoAvailableSongsException>(async () => await player.SetRedHeart(redHeart));
            serverConnectionMock.Verify();
        }
コード例 #3
0
        public async void TestSetRedHeart(bool redHeart)
        {
            string reportType = GetReportTypeStringByRedHeart(redHeart);
            var serverConnectionMock = new Mock<IServerConnection>();
            serverConnectionMock.Setup(s => s.Get(It.Is<Uri>(u => u.AbsolutePath.EndsWith("playlist")
                                                                  && u.GetQueries().Contains(new KeyValuePair<string, string>("type", "n"))),
                It.IsAny<Action<HttpWebRequest>>())).ReturnsAsync(Resource.PlayList).Verifiable();
            var session = new Session(serverConnectionMock.Object);
            var player = new Player(session);
            await player.ChangeChannel(new Channel(0));

            var originalSong = player.CurrentSong;
            serverConnectionMock.Setup(s => s.Get(It.Is<Uri>(u => u.AbsolutePath.EndsWith("playlist")
                                                                  && u.GetQueries().Contains(new KeyValuePair<string, string>("type", reportType))
                                                                  && u.GetQueries().Contains(new KeyValuePair<string, string>("sid", player.CurrentSong.Sid))),
                It.IsAny<Action<HttpWebRequest>>())).ReturnsAsync(Resource.PlayList).Verifiable();
            await player.SetRedHeart(redHeart);
            Assert.AreEqual(originalSong, player.CurrentSong);
            serverConnectionMock.Verify();
        }