Exemplo n.º 1
0
        public void TestPlaybackEndToEnd()
        {
            int w = 10, h = 1;
            var temp = Path.GetTempFileName();

            using (var stream = File.OpenWrite(temp))
            {
                var writer = new ConsoleBitmapStreamWriter(stream)
                {
                    CloseInnerStream = false
                };
                var bitmap = new ConsoleBitmap(w, h);

                for (var i = 0; i < bitmap.Width; i++)
                {
                    bitmap.Pen = new ConsoleCharacter(' ');
                    bitmap.FillRect(0, 0, bitmap.Width, bitmap.Height);
                    bitmap.Pen = new ConsoleCharacter(' ', backgroundColor: ConsoleColor.Red);
                    bitmap.DrawPoint(i, 0);
                    writer.WriteFrame(bitmap, true, TimeSpan.FromSeconds(.5 * i));
                }
                writer.Dispose();
            }

            var app = new CliTestHarness(this.TestContext, 80, 30);

            app.QueueAction(() =>
            {
                var player = app.LayoutRoot.Add(new ConsoleBitmapPlayer()).Fill();
                player.Load(File.OpenRead(temp));
                app.SetTimeout(() => app.SendKey(new ConsoleKeyInfo('p', ConsoleKey.P, false, false, false)), TimeSpan.FromMilliseconds(100));
                var playStarted = false;
                player.SubscribeForLifetime(nameof(player.State), () =>
                {
                    if (player.State == PlayerState.Playing)
                    {
                        playStarted = true;
                    }
                    else if (player.State == PlayerState.Stopped && playStarted)
                    {
                        app.Stop();
                    }
                }, app);
            });

            app.Start().Wait();
            Thread.Sleep(100);
            app.AssertThisTestMatchesLKGFirstAndLastFrame();
        }
Exemplo n.º 2
0
        public void TestPlaybackEndToEnd()
        {
            var app = new CliTestHarness(this.TestContext, 80, 30);

            app.InvokeNextCycle(async() =>
            {
                int w    = 10, h = 1;
                var temp = Path.GetTempFileName();
                using (var stream = File.OpenWrite(temp))
                {
                    var writer = new ConsoleBitmapVideoWriter(s => stream.Write(Encoding.Default.GetBytes(s)));
                    var bitmap = new ConsoleBitmap(w, h);

                    for (var i = 0; i < bitmap.Width; i++)
                    {
                        bitmap.Fill(new ConsoleCharacter(' '));
                        bitmap.DrawPoint(new ConsoleCharacter(' ', backgroundColor: ConsoleColor.Red), i, 0);
                        writer.WriteFrame(bitmap, true, TimeSpan.FromSeconds(.1 * i));
                    }
                    writer.Finish();
                }

                var player = app.LayoutRoot.Add(new ConsoleBitmapPlayer()).Fill();
                Assert.IsFalse(player.Width == 0);
                Assert.IsFalse(player.Height == 0);
                player.Load(File.OpenRead(temp));

                var playStarted = false;
                player.SubscribeForLifetime(nameof(player.State), () =>
                {
                    if (player.State == PlayerState.Playing)
                    {
                        playStarted = true;
                    }
                    else if (player.State == PlayerState.Stopped && playStarted)
                    {
                        app.Stop();
                    }
                }, app);

                await Task.Delay(100);
                await app.SendKey(new ConsoleKeyInfo('p', ConsoleKey.P, false, false, false));
            });

            app.Start().Wait();
            Thread.Sleep(100);
            app.AssertThisTestMatchesLKGFirstAndLastFrame();
        }
Exemplo n.º 3
0
        public void TestThreeMonthCalendarBasicRender()
        {
            var app = new CliTestHarness(this.TestContext, 120, 40);

            app.Invoke(async() =>
            {
                var carousel = new ThreeMonthCarousel(new ThreeMonthCarouselOptions()
                {
                    Month = 1, Year = 2000
                });
                var start = carousel.Options.Month + "/" + carousel.Options.Year;
                app.LayoutRoot.Add(new FixedAspectRatioPanel(4f / 1f, carousel)).Fill();
                Assert.IsTrue(await carousel.SeekAsync(true, carousel.Options.AnimationDuration));
                await Task.Delay(1000);
                Assert.IsTrue(await carousel.SeekAsync(true, carousel.Options.AnimationDuration));
                await Task.Delay(1000);
                Assert.IsTrue(await carousel.SeekAsync(true, carousel.Options.AnimationDuration));
                await Task.Delay(1000);
                Assert.IsTrue(await carousel.SeekAsync(true, carousel.Options.AnimationDuration));

                await Task.Delay(3000);

                var now = carousel.Options.Month + "/" + carousel.Options.Year;
                Assert.AreNotEqual(start, now);

                Assert.IsTrue(await carousel.SeekAsync(false, carousel.Options.AnimationDuration));
                await Task.Delay(1000);
                Assert.IsTrue(await carousel.SeekAsync(false, carousel.Options.AnimationDuration));
                await Task.Delay(1000);
                Assert.IsTrue(await carousel.SeekAsync(false, carousel.Options.AnimationDuration));
                await Task.Delay(1000);
                Assert.IsTrue(await carousel.SeekAsync(false, carousel.Options.AnimationDuration));
                await Task.Delay(1000);

                now = carousel.Options.Month + "/" + carousel.Options.Year;
                Assert.AreEqual(start, now);
                app.Stop();
            });
            app.Run();
            app.AssertThisTestMatchesLKGFirstAndLastFrame();
        }