Ejemplo n.º 1
0
        public async void TestChangeChannelAndValidateParameterStart(ChangeChannelCommandType type)
        {
            var serverConnectionMock = new Mock <IServerConnection>();

            serverConnectionMock.Setup(s => s.Get(It.Is <Uri>(u => u.AbsolutePath.EndsWith("playlist")), It.IsAny <Action <HttpWebRequest> >())).ReturnsAsync(Resource.PlayList).Verifiable();
            var session = new Session(serverConnectionMock.Object);
            var player  = new Player(session);
            var channel = new Channel(123)
            {
                Start = "StartCode"
            };
            await player.ChangeChannel(channel, type);

            serverConnectionMock.Verify();
            var startValidator = new Func <Uri, bool>(uri =>
            {
                var queries = uri.GetQueries();
                switch (type)
                {
                case ChangeChannelCommandType.Normal:
                    return(queries.ContainsKey("start") && queries["start"] == "StartCode");

                case ChangeChannelCommandType.PlayRelatedSongs:
                    return(!queries.ContainsKey("start"));

                default:
                    throw new ArgumentOutOfRangeException(nameof(type), type, null);
                }
            });

            serverConnectionMock.Verify(s => s.Get(It.Is <Uri>(u => u.AbsolutePath.EndsWith("playlist") && startValidator(u)), It.IsAny <Action <HttpWebRequest> >()));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Changes the channel.
        /// </summary>
        /// <param name="newChannel">The new channel.</param>
        /// <param name="type">The type of operation.</param>
        /// <returns></returns>
        public async Task ChangeChannel(Channel newChannel, ChangeChannelCommandType type = ChangeChannelCommandType.Normal)
        {
            AsyncExpectedChannelId = newChannel?.Id;
            CurrentChannel         = null;
            CurrentSong            = null;
            if (newChannel != null)
            {
                var start = type == ChangeChannelCommandType.Normal ? newChannel.Start : null;
                await Report(ReportType.CurrentChannelChanged, newChannel.Id, CurrentSong?.Sid, start);

                /*
                 *      If user called ChangeChannel twice in a short time, say call 1 and call 2.
                 *      But call 2 responded before call 1. Then we want to use call 2's response.
                 *      So we need to check AsyncExpectedChannelId here because it should be call 2's ID.
                 */
                if (AsyncExpectedChannelId == newChannel.Id)
                {
                    CurrentChannel = newChannel;
                }
            }
        }
Ejemplo n.º 3
0
 public async void TestChangeChannelAndValidateParameterStart(ChangeChannelCommandType type)
 {
     var serverConnectionMock = new Mock<IServerConnection>();
     serverConnectionMock.Setup(s => s.Get(It.Is<Uri>(u => u.AbsolutePath.EndsWith("playlist")), It.IsAny<Action<HttpWebRequest>>())).ReturnsAsync(Resource.PlayList).Verifiable();
     var session = new Session(serverConnectionMock.Object);
     var player = new Player(session);
     var channel = new Channel(123) { Start = "StartCode" };
     await player.ChangeChannel(channel, type);
     serverConnectionMock.Verify();
     var startValidator = new Func<Uri, bool>(uri =>
     {
         var queries = uri.GetQueries();
         switch (type)
         {
             case ChangeChannelCommandType.Normal:
                 return queries.ContainsKey("start") && queries["start"] == "StartCode";
             case ChangeChannelCommandType.PlayRelatedSongs:
                 return !queries.ContainsKey("start");
             default:
                 throw new ArgumentOutOfRangeException(nameof(type), type, null);
         }
     });
     serverConnectionMock.Verify(s => s.Get(It.Is<Uri>(u => u.AbsolutePath.EndsWith("playlist") && startValidator(u)), It.IsAny<Action<HttpWebRequest>>()));
 }
Ejemplo n.º 4
0
        public async Task <List <Song> > GetSongs(Channel newChannel, string Songsid = null, ChangeChannelCommandType type = ChangeChannelCommandType.Normal)
        {
            var start       = type == ChangeChannelCommandType.Normal ? newChannel.Start : null;
            var uri         = ServerConnection.CreateGetPlayListUri(newChannel.Id, type: ReportType.CurrentChannelChanged, sid: Songsid, start: start, formats: null, kbps: null, playedTime: null, mode: null, excludedSids: null, max: null);
            var jsonContent = await ServerConnection.Get(uri, ServerConnection.SetSessionInfoToRequest);

            var newPlayList = ServerRequests.ParseGetPlayListResult(jsonContent);

            if (newPlayList == null || newPlayList?.Count == 0)
            {
                //TODO
                return(new List <Song>());
            }
            else
            {
                return(newPlayList);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Changes the channel.
        /// </summary>
        /// <param name="newChannel">The new channel.</param>
        /// <param name="type">The type of operation.</param>
        /// <returns></returns>
        public async Task ChangeChannel(Channel newChannel, ChangeChannelCommandType type = ChangeChannelCommandType.Normal)
        {
            AsyncExpectedChannelId = newChannel?.Id;
            CurrentChannel = null;
            CurrentSong = null;
            if (newChannel != null)
            {
                var start = type == ChangeChannelCommandType.Normal ? newChannel.Start : null;
                await Report(ReportType.CurrentChannelChanged, newChannel.Id, CurrentSong?.Sid, start);

                /*
                        If user called ChangeChannel twice in a short time, say call 1 and call 2.
                        But call 2 responded before call 1. Then we want to use call 2's response.
                        So we need to check AsyncExpectedChannelId here because it should be call 2's ID.
                        */
                if (AsyncExpectedChannelId == newChannel.Id)
                {
                    CurrentChannel = newChannel;
                }
            }
        }