public void TestGridBasic() { Grid grid = new Grid(); MemoryDataSource data = new MemoryDataSource(); grid.DataSource = data; for(int i = 0; i < 5; i++) { data.Items.Add(new { Id = i+1, StringValue = "Some value here" }); } grid.VisibleColumns.Add(new ColumnViewModel("Id".ToConsoleString())); grid.VisibleColumns.Add(new ColumnViewModel("StringValue".ToConsoleString())); grid.Width = app.LayoutRoot.Width; grid.Height = app.LayoutRoot.Height; app.LayoutRoot.Controls.Add(grid); Task doneTask = app.Start(); // give the UI thread a few milliseconds to paint before checking it // todo - maybe implement an after paint event on console app Thread.Sleep(100); // grab the state of the UI to check for the grid var consoleState = console.Buffer.ToString(); // exit the app by simulating an escape key press console.Input.Enqueue(new ConsoleKeyInfo(' ', ConsoleKey.Escape,false, false, false)); // wait for the app to exit normally doneTask.Wait(); // verify that the console state matches our expected state Assert.AreEqual(Resources.BasicGridExpectedOutput.Replace("\r\n", "\n").Replace("\r","\n"), consoleState.Replace("\r\n", "\n").Replace("\r", "\n")); }
public static void Run() { var app = new ConsoleApp(0, 0, 75, 22); var chart = new CpuAndMemoryChart(); var list = new Grid() { Size = new Size(30, 5) }; var source = new MemoryDataSource(); list.DataSource = source; Action syncChartToListAction = () => { source.Items.Clear(); if (chart.ViewModel.FocusedDataSeries != null && chart.ViewModel.FocusedDataPointIndex >= 0 && chart.ViewModel.FocusedDataPointIndex < chart.ViewModel.FocusedDataSeries.DataPoints.Count && chart.ViewModel.FocusedDataSeries.DataPoints.Count > 0) { source.Items.Add(new { Value = ContextAssistSearchResult.FromString(chart.ViewModel.FocusedDataSeries.DataPoints[chart.ViewModel.FocusedDataPointIndex].Y + "") }); } }; chart.ViewModel.FocusedDataPointChanged += syncChartToListAction; chart.ViewModel.FocusedSeriesChanged += syncChartToListAction; syncChartToListAction(); app.LayoutRoot.Controls.Add(chart); app.LayoutRoot.Controls.Add(list); app.Start(); }