コード例 #1
0
        public async Task Ticker_OnTick()
        {
            const string key    = "ticker";
            var          ticker = new Ticker();
            var          tracks = new List <ExampleTrack>
            {
                new ExampleTrack {
                    Start = DateTime.Now.AddSeconds(-1), Stop = DateTime.Now.AddSeconds(3), Title = "1"
                },
                new ExampleTrack {
                    Start = DateTime.Now.AddSeconds(3), Stop = DateTime.Now.AddSeconds(5), Title = "2"
                },
                new ExampleTrack {
                    Start = DateTime.Now.AddSeconds(5), Stop = DateTime.Now.AddSeconds(7), Title = "3"
                }
            };
            var outcome = new List <ExampleTrack>();

            ticker.AddChannel(key, tracks);
            ticker.TrackChanged += (sender, changed) => outcome.Add(changed.Current as ExampleTrack);
            ticker.Start();
            while (outcome.Count != 2)
            {
                await Task.Delay(TimeSpan.FromSeconds(1));
            }

            string.Join("", outcome.Select(x => x.Title)).Should().Be("23");
        }
コード例 #2
0
        public void Ticker_AddChannel(string key)
        {
            var ticker = new Ticker();
            var tracks = new List <ExampleTrack>
            {
                new ExampleTrack {
                    Start = DateTime.Now.AddSeconds(-1), Stop = DateTime.Now.AddSeconds(3), Title = "1"
                },
                new ExampleTrack {
                    Start = DateTime.Now.AddSeconds(3), Stop = DateTime.Now.AddSeconds(5), Title = "2"
                },
                new ExampleTrack {
                    Start = DateTime.Now.AddSeconds(5), Stop = DateTime.Now.AddSeconds(7), Title = "3"
                }
            };

            ticker.AddChannel(key, tracks);
            ticker.AddChannel(key, tracks);
        }
コード例 #3
0
        public async Task Ticker_OnTick_PlaylistEnded()
        {
            const string key    = "ticker";
            var          ticker = new Ticker();
            var          tracks = new List <ExampleTrack>
            {
                new ExampleTrack {
                    Start = DateTime.Now.AddSeconds(-1), Stop = DateTime.Now.AddSeconds(1), Title = "1"
                }
            };
            var playlistEnded = new PlaylistEnded();

            ticker.AddChannel(key, tracks);
            ticker.PlaylistEnded += (sender, ended) => playlistEnded = ended;
            ticker.Start();
            await Task.Delay(TimeSpan.FromSeconds(3));

            playlistEnded.PlaylistName.Should().Be(key);
        }
コード例 #4
0
        public void Ticker_CurrentAs()
        {
            const string key    = "ticker";
            var          ticker = new Ticker();
            var          tracks = new List <ExampleTrack>
            {
                new ExampleTrack {
                    Start = DateTime.Now.AddSeconds(-1), Stop = DateTime.Now.AddSeconds(1), Title = "1"
                }
            };

            ticker.AddChannel(key, tracks);
            ticker.Start();
            var channel = ticker["ticker"];
            var current = channel.Current <ExampleTrack>();

            current.Should().BeOfType <ExampleTrack>();
            current.Title.Should().Be("1");
            var current2 = channel.Current <AnotherTrack>();

            current2.Should().BeNull();
        }
コード例 #5
0
        public void Ticker_Next()
        {
            const string key    = "ticker";
            var          ticker = new Ticker();
            var          tracks = new List <ExampleTrack>
            {
                new ExampleTrack {
                    Start = DateTime.Now.AddSeconds(-1), Stop = DateTime.Now.AddSeconds(3), Title = "1"
                },
                new ExampleTrack {
                    Start = DateTime.Now.AddSeconds(3), Stop = DateTime.Now.AddSeconds(5), Title = "2"
                },
                new ExampleTrack {
                    Start = DateTime.Now.AddSeconds(5), Stop = DateTime.Now.AddSeconds(7), Title = "3"
                }
            };

            ticker.AddChannel(key, tracks);
            ticker.Start();
            var playlist = ticker[key];

            ((ExampleTrack)playlist.Next()).Title.Should().Be("2");
        }
コード例 #6
0
        public void Ticker_Current(string key)
        {
            var ticker = new Ticker();
            var tracks = new List <ExampleTrack>
            {
                new ExampleTrack {
                    Start = DateTime.Now.AddSeconds(-1), Stop = DateTime.Now.AddSeconds(3), Title = "1"
                },
                new ExampleTrack {
                    Start = DateTime.Now.AddSeconds(3), Stop = DateTime.Now.AddSeconds(5), Title = "2"
                },
                new ExampleTrack {
                    Start = DateTime.Now.AddSeconds(5), Stop = DateTime.Now.AddSeconds(7), Title = "3"
                }
            };

            ticker.AddChannel(key, tracks);
            ticker.Start();
            var playlist = ticker[key];

            playlist.Should().NotBeNull();
            playlist.Title.Should().Be(key);
            ((ExampleTrack)playlist.Current()).Title.Should().Be("1");
        }