Ejemplo n.º 1
0
        public void ShowTextInput()
        {
            var app = new CliTestHarness(this.TestContext, 80, 20, true);

            app.InvokeNextCycle(async() =>
            {
                Task <ConsoleString> dialogTask;
                dialogTask = Dialog.ShowRichTextInput(new RichTextDialogOptions()
                {
                    Message = "Rich text input prompt text".ToGreen(),
                });
                await app.PaintAndRecordKeyFrameAsync();
                Assert.IsFalse(dialogTask.IsFulfilled());
                app.SendKey(new ConsoleKeyInfo('A', ConsoleKey.A, false, false, false));
                await app.PaintAndRecordKeyFrameAsync();
                app.SendKey(new ConsoleKeyInfo('d', ConsoleKey.D, false, false, false));
                await app.PaintAndRecordKeyFrameAsync();
                app.SendKey(new ConsoleKeyInfo('a', ConsoleKey.A, false, false, false));
                await app.PaintAndRecordKeyFrameAsync();
                app.SendKey(new ConsoleKeyInfo('m', ConsoleKey.M, false, false, false));
                await app.PaintAndRecordKeyFrameAsync();
                Assert.IsFalse(dialogTask.IsFulfilled());
                app.SendKey(new ConsoleKeyInfo(' ', ConsoleKey.Enter, false, false, false));
                var stringVal = (await dialogTask).ToString();
                await app.RequestPaintAsync();
                app.RecordKeyFrame();
                Assert.AreEqual("Adam", stringVal);
                app.Stop();
            });

            app.Start().Wait();
            app.AssertThisTestMatchesLKG();
        }
Ejemplo n.º 2
0
        public void TestMonthCalendarBasicRender()
        {
            var app = new CliTestHarness(this.TestContext, MonthCalendar.MinWidth, MonthCalendar.MinHeight, true);

            app.InvokeNextCycle(() => app.LayoutRoot.Add(new MonthCalendar(new MonthCalendarOptions()
            {
                Year = 2000, Month = 1
            })).Fill());
            app.InvokeNextCycle(async() =>
            {
                await app.RequestPaintAsync();
                app.RecordKeyFrame();
                app.Stop();
            });
            app.Start().Wait();
            app.AssertThisTestMatchesLKG();
        }
Ejemplo n.º 3
0
        public void RenderChartTestCommon(XYChartOptions options, int w = 80, int h = 30)
        {
            var app = new CliTestHarness(this.TestContext, w, h, true)
            {
                SetFocusOnStart = false
            };

            app.InvokeNextCycle(() => app.LayoutRoot.Add(new XYChart(options)).Fill());
            app.InvokeNextCycle(async() =>
            {
                await app.RequestPaintAsync();
                app.RecordKeyFrame();
                app.Stop();
            });
            app.Start().Wait();
            app.AssertThisTestMatchesLKG();
        }
Ejemplo n.º 4
0
        public void TestRenderTextBox()
        {
            var app = new CliTestHarness(this.TestContext, 9, 1);

            app.InvokeNextCycle(async() =>
            {
                app.LayoutRoot.Add(new TextBox()
                {
                    Value = "SomeText".ToWhite()
                }).Fill();
                await app.RequestPaintAsync();
                Assert.IsTrue(app.Find("SomeText".ToWhite()).HasValue);
                app.Stop();
            });

            app.Start().Wait();
            app.AssertThisTestMatchesLKG();
        }
Ejemplo n.º 5
0
        public void DrawLines()
        {
            var bitmap  = new ConsoleBitmap(80, 30);
            var centerX = bitmap.Width / 2;
            var centerY = bitmap.Height / 2;

            var app = new CliTestHarness(TestContext, bitmap.Width, bitmap.Height, true);

            app.InvokeNextCycle(async() =>
            {
                app.LayoutRoot.Add(new BitmapControl()
                {
                    Bitmap = bitmap
                }).Fill();
                await app.RequestPaintAsync();
                app.RecordKeyFrame();

                bitmap.DrawLine(new ConsoleCharacter('X', ConsoleColor.Gray), centerX, centerY, 0, centerY / 2);
                await app.RequestPaintAsync();
                app.RecordKeyFrame();

                bitmap.DrawLine(new ConsoleCharacter('X', ConsoleColor.Red), centerX, centerY, 0, 0);
                await app.RequestPaintAsync();
                app.RecordKeyFrame();

                bitmap.DrawLine(new ConsoleCharacter('X', ConsoleColor.Yellow), centerX, centerY, centerX / 2, 0);
                await app.RequestPaintAsync();
                app.RecordKeyFrame();

                bitmap.DrawLine(new ConsoleCharacter('X', ConsoleColor.Green), centerX, centerY, centerX, 0);
                await app.RequestPaintAsync();
                app.RecordKeyFrame();

                bitmap.DrawLine(new ConsoleCharacter('X', ConsoleColor.Magenta), centerX, centerY, (int)(bitmap.Width * .75), 0);
                await app.RequestPaintAsync();
                app.RecordKeyFrame();

                bitmap.DrawLine(new ConsoleCharacter('X', ConsoleColor.Cyan), centerX, centerY, bitmap.Width - 1, 0);
                await app.RequestPaintAsync();
                app.RecordKeyFrame();

                bitmap.DrawLine(new ConsoleCharacter('X', ConsoleColor.Gray), centerX, centerY, bitmap.Width - 1, centerY / 2);
                await app.RequestPaintAsync();
                app.RecordKeyFrame();

                bitmap.DrawLine(new ConsoleCharacter('X', ConsoleColor.White), centerX, centerY, 0, bitmap.Height / 2);
                await app.RequestPaintAsync();
                app.RecordKeyFrame();

                bitmap.DrawLine(new ConsoleCharacter('X', ConsoleColor.Blue), centerX, centerY, bitmap.Width - 1, bitmap.Height / 2);
                await app.RequestPaintAsync();
                app.RecordKeyFrame();

                bitmap.DrawLine(new ConsoleCharacter('X', ConsoleColor.Gray), centerX, centerY, 0, (int)(bitmap.Height * .75));
                await app.RequestPaintAsync();
                app.RecordKeyFrame();

                bitmap.DrawLine(new ConsoleCharacter('X', ConsoleColor.Red), centerX, centerY, 0, bitmap.Height - 1);
                await app.RequestPaintAsync();
                app.RecordKeyFrame();

                bitmap.DrawLine(new ConsoleCharacter('X', ConsoleColor.Yellow), centerX, centerY, centerX / 2, bitmap.Height - 1);
                await app.RequestPaintAsync();
                app.RecordKeyFrame();

                bitmap.DrawLine(new ConsoleCharacter('X', ConsoleColor.Green), centerX, centerY, centerX, bitmap.Height - 1);
                await app.RequestPaintAsync();
                app.RecordKeyFrame();

                bitmap.DrawLine(new ConsoleCharacter('X', ConsoleColor.Magenta), centerX, centerY, (int)(bitmap.Width * .75), bitmap.Height - 1);
                await app.RequestPaintAsync();
                app.RecordKeyFrame();

                bitmap.DrawLine(new ConsoleCharacter('X', ConsoleColor.Cyan), centerX, centerY, bitmap.Width - 1, bitmap.Height - 1);
                await app.RequestPaintAsync();
                app.RecordKeyFrame();

                bitmap.DrawLine(new ConsoleCharacter('X', ConsoleColor.Gray), centerX, centerY, bitmap.Width - 1, (int)(bitmap.Height * .75));

                await app.RequestPaintAsync();
                app.RecordKeyFrame();
                app.Stop();
            });

            app.Start().Wait();
            app.AssertThisTestMatchesLKG();
        }
Ejemplo n.º 6
0
        public void GridLayoutEndToEnd()
        {
            var app = new CliTestHarness(this.TestContext, 80, 20, true);

            app.InvokeNextCycle(async() =>
            {
                var gridLayout = app.LayoutRoot.Add(new GridLayout(new GridLayoutOptions()
                {
                    Columns = new List <GridColumnDefinition>()
                    {
                        new GridColumnDefinition()
                        {
                            Width = 5, Type = GridValueType.Pixels
                        },
                        new GridColumnDefinition()
                        {
                            Width = 2, Type = GridValueType.RemainderValue
                        },
                        new GridColumnDefinition()
                        {
                            Width = 2, Type = GridValueType.RemainderValue
                        },
                    },
                    Rows = new List <GridRowDefinition>()
                    {
                        new GridRowDefinition()
                        {
                            Height = 1, Type = GridValueType.Pixels
                        },
                        new GridRowDefinition()
                        {
                            Height = 2, Type = GridValueType.RemainderValue
                        },
                        new GridRowDefinition()
                        {
                            Height = 1, Type = GridValueType.Pixels
                        },
                    }
                })).Fill();

                var colorWheel = new List <ConsoleColor>()
                {
                    ConsoleColor.Red, ConsoleColor.DarkRed, ConsoleColor.Red,
                    ConsoleColor.Black, ConsoleColor.White, ConsoleColor.Black,
                    ConsoleColor.Green, ConsoleColor.DarkGreen, ConsoleColor.Green
                };
                var colorIndex = 0;
                for (var y = 0; y < gridLayout.NumRows; y++)
                {
                    for (var x = 0; x < gridLayout.NumColumns; x++)
                    {
                        gridLayout.Add(new ConsoleControl()
                        {
                            Background = colorWheel[colorIndex],
                        }, x, y);
                        colorIndex = colorIndex == colorWheel.Count - 1 ? 0 : colorIndex + 1;
                    }
                }

                await app.RequestPaintAsync();
                app.RecordKeyFrame();
                app.Stop();
            });

            app.Start().Wait();
            app.AssertThisTestMatchesLKG();
        }