public void TableWriterMultipleRows() { var mockOutputter = new Mock <IConsoleOutputter>(); var target = new TableWriter(mockOutputter.Object, new ViewPort(100, 100)); var table = new DisplayTable() { Header = new TableRow { Cells = new[] { new BasicTableCell { ContentAreas = new ICellContent[] { new BasicCellContent { Value = "TestCell" }, new BreakingRuleContentArea(), new BasicCellContent { Value = "Line2" } } } } }, ColumnDetails = new[] { new ColumnDetails { columnName = "harrumph", columnWidth = 10, isNullable = false, type = Data.DataType.String } } }; target.Draw(table); string s = ConsoleOutputHelper.getConsoleOutput(mockOutputter.Invocations); string[] effectiveLines = s.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); Assert.Equal(4, effectiveLines.Length); }
public void TableWriterColumnConstraintsPadsWithTooLargeColumn() { var mockOutputter = new Mock <IConsoleOutputter>(); var target = new TableWriter(mockOutputter.Object, new ViewPort(100, 100)); int columnWidth = 25; var table = new DisplayTable() { Header = new TableRow { Cells = new[] { new BasicTableCell { ContentAreas = new[] { new BasicCellContent { Value = "TestCell" } } } } }, ColumnDetails = new[] { new ColumnDetails { columnName = "harrumph", columnWidth = columnWidth, isNullable = false, type = Data.DataType.String } }, Rows = new[] { new TableRow { Cells = new[] { new BasicTableCell { ContentAreas = new[] { new BasicCellContent { Value = "This is a test value." } } } } } } }; target.Draw(table); string s = ConsoleOutputHelper.getConsoleOutput(mockOutputter.Invocations); Assert.Contains(" This is a test value.", s); }
public void TableWriterColumnConstraintsRespectedOverallWidth() { var mockOutputter = new Mock <IConsoleOutputter>(); var target = new TableWriter(mockOutputter.Object, new ViewPort(100, 100)); int columnWidth = new Random().Next(95); var table = new DisplayTable() { Header = new TableRow { Cells = new[] { new BasicTableCell { ContentAreas = new[] { new BasicCellContent { Value = "TestCell" } } } } }, ColumnDetails = new[] { new ColumnDetails { columnName = "harrumph", columnWidth = columnWidth, isNullable = false, type = Data.DataType.String } }, Rows = new[] { new TableRow { Cells = new[] { new BasicTableCell { ContentAreas = new[] { new BasicCellContent { Value = "This is a test value." } } } } } } }; target.Draw(table); string s = ConsoleOutputHelper.getConsoleOutput(mockOutputter.Invocations); string[] effectiveLines = s.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); Assert.True(effectiveLines.All(l => l.Length == columnWidth + ("|".Length * 2)), GetLengths(effectiveLines)); }
public void TableWriterWritesSomething() { var mockOutputter = new Mock <IConsoleOutputter>(); var target = new TableWriter(mockOutputter.Object, new ViewPort(100, 100)); var table = new DisplayTable() { Header = new TableRow { Cells = new[] { new BasicTableCell { ContentAreas = new ICellContent[] { new BasicCellContent { Value = "TestCell" }, new BreakingRuleContentArea(), new BasicCellContent { Value = "Line2" } } } } }, ColumnDetails = new [] { new ColumnDetails { columnName = "harrumph", columnWidth = 10, isNullable = false, type = Data.DataType.String } } }; target.Draw(table); string s = ConsoleOutputHelper.getConsoleOutput(mockOutputter.Invocations); Assert.Contains("Line2", s); }
public void TableWriterWritesExpected() { var mockOutputter = new Mock <IConsoleOutputter>(); var target = new TableWriter(mockOutputter.Object, new ViewPort(100, 100)); Guid expectedValue = Guid.NewGuid(); var table = new DisplayTable() { Header = new TableRow { Cells = new[] { new BasicTableCell { ContentAreas = new[] { new BasicCellContent { Value = "TestCell" } } } } }, ColumnDetails = new[] { new ColumnDetails { columnName = "harrumph", columnWidth = expectedValue.ToString().Length + 2, isNullable = false, type = Data.DataType.String } }, Rows = new[] { new TableRow { Cells = new[] { new BasicTableCell { ContentAreas = new[] { new BasicCellContent { Value = expectedValue.ToString() } } } } } } }; target.Draw(table); string s = ConsoleOutputHelper.getConsoleOutput(mockOutputter.Invocations); Assert.Contains(expectedValue.ToString(), s); }
public void Should_edit_user_group() { string key = Guid.NewGuid().ToString(); string groupName = Guid.NewGuid().ToString(); string groupName2 = Guid.NewGuid().ToString(); _webBrowser.ScreenCaptureOnFailure(() => { AddNewUserGroup(key, groupName); var table = new DisplayTable <UserGroupInput>(_webBrowser); table.AddRowFilter(u => u.Name, groupName); Assert.IsTrue(table.VerifyRowExists()); table.ClickLink(CodeCampSite.Admin.EditUserGroup); _webBrowser.VerifyPage <UserGroupController>( p => p.Edit((UserGroupInput)null)); var form = new InputForm <UserGroupInput>(_webBrowser); form .Input(u => u.Name, groupName2) .Submit(); var table2 = new DisplayTable <UserGroupInput>(_webBrowser); table2.AddRowFilter(u => u.Name, groupName2); table2.AddRowFilter(u => u.Key, key); Assert.IsTrue(table2.VerifyRowExists()); }); }
public void Should_edit_user_group() { string key = Guid.NewGuid().ToString(); string groupName = Guid.NewGuid().ToString(); string groupName2 = Guid.NewGuid().ToString(); _webBrowser.ScreenCaptureOnFailure(() => { AddNewUserGroup(key, groupName); var table = new DisplayTable<UserGroupInput>(_webBrowser); table.AddRowFilter(u => u.Name, groupName); Assert.IsTrue(table.VerifyRowExists()); table.ClickLink(CodeCampSite.Admin.EditUserGroup); _webBrowser.VerifyPage<UserGroupController>( p => p.Edit((UserGroupInput) null)); var form = new InputForm<UserGroupInput>(_webBrowser); form .Input(u => u.Name, groupName2) .Submit(); var table2 = new DisplayTable<UserGroupInput>(_webBrowser); table2.AddRowFilter(u => u.Name, groupName2); table2.AddRowFilter(u => u.Key, key); Assert.IsTrue(table2.VerifyRowExists()); }); }
private void DrawLine(DisplayTable displayTable, ViewPort viewPort, bool drawRefs = false) { consoleOutputter.Write(cellDivider); for (int c = 0; c < displayTable.Header.Cells.Length; c++) { TableCell column = displayTable.Header.Cells[c]; ColumnDetails details = displayTable.ColumnDetails[c]; int columnNameLength = c.ToString().Length; if (IsOverlyLargeColumn(details, viewPort)) { for (int i = 0; i < ((viewPort.Width - (verticalSeparator.Length * 2) - Environment.NewLine.Length) / 2) - (columnNameLength / 2); i++) { consoleOutputter.Write(horizontalSeparator); } if (drawRefs) { consoleOutputter.Write(c.ToString()); } else { consoleOutputter.Write(horizontalSeparator); } for (int i = 0; i < ((viewPort.Width - (verticalSeparator.Length * 2) - Environment.NewLine.Length) / 2) - (columnNameLength / 2) - ((columnNameLength + 1) % 2); i++) { consoleOutputter.Write(horizontalSeparator); } } else { for (int i = 0; i < (details.columnWidth / 2) - (c.ToString().Length / 2); i++) { consoleOutputter.Write(horizontalSeparator); } if (drawRefs) { consoleOutputter.Write(c.ToString()); } else { consoleOutputter.Write(horizontalSeparator); } for (int i = 0; i < (details.columnWidth / 2) - (c.ToString().Length / 2) - ((details.columnWidth + 1) % 2); i++) { consoleOutputter.Write(horizontalSeparator); } } consoleOutputter.Write(cellDivider); } consoleOutputter.Write(Environment.NewLine); }
public void Draw(DisplayTable table) { if (table.Header.Cells.Any()) { DrawLine(table, viewPort); WriteHeaderLine(table, viewPort); DrawLine(table, viewPort); } if (table.Rows.Any()) { WriteValues(table, viewPort, true, "...", false); DrawLine(table, viewPort); } }
public void Should_Create_New_User_Groups() { string key = Guid.NewGuid().ToString(); string groupName = Guid.NewGuid().ToString(); _webBrowser.ScreenCaptureOnFailure(() => { AddNewUserGroup(key, groupName); var table = new DisplayTable<UserGroupInput>(_webBrowser); table.AddRowFilter(u => u.Name, groupName); Assert.IsTrue(table.VerifyRowExists()); table.ClickLink(CodeCampSite.Admin.ViewUserGroup); _webBrowser.VerifyPage<UserGroupController>(p => p.Index(null)); }); }
private void WriteValues(DisplayTable table, ViewPort viewPort, bool displayNulls = true, string truncationIdentifier = "...", bool displayRefs = false) { for (int i = 0; i < table.Rows.Length; i++) { TableRow row = table.Rows.ElementAt(i); consoleOutputter.Write(verticalSeparator); for (int j = 0; j < row.Cells.Length; j++) { ColumnDetails header = table.ColumnDetails.ElementAt(j); TableCell cell = row.Cells[j]; cell.Write(consoleOutputter, viewPort, 0, header); consoleOutputter.Write(verticalSeparator); } consoleOutputter.Write(Environment.NewLine); } }
public void Should_Create_New_User_Groups() { string key = Guid.NewGuid().ToString(); string groupName = Guid.NewGuid().ToString(); _webBrowser.ScreenCaptureOnFailure(() => { AddNewUserGroup(key, groupName); var table = new DisplayTable <UserGroupInput>(_webBrowser); table.AddRowFilter(u => u.Name, groupName); Assert.IsTrue(table.VerifyRowExists()); table.ClickLink(CodeCampSite.Admin.ViewUserGroup); _webBrowser.VerifyPage <UserGroupController>(p => p.Index(null)); }); }
public void TableWriterWritesHeaderResetsColorChoice() { var mockOutputter = new Mock <IConsoleOutputter>(); var target = new TableWriter(mockOutputter.Object, new ViewPort(100, 100)); var table = new DisplayTable() { Header = new TableRow { Cells = new[] { new BasicTableCell { ContentAreas = new[] { new BasicCellContent { Value = "TestCell", ForegroundColor = ConsoleColor.Green } } } } }, ColumnDetails = new[] { new ColumnDetails { columnName = "harrumph", columnWidth = 10, isNullable = false, type = Data.DataType.String } } }; target.Draw(table); mockOutputter.Verify(m => m.ResetColor(), Times.Once()); }
public static void GetAll() { //get the list of stuff from the service _stuffList = _stuffOps.GetAll(); //create a DisplayTable object for displaying output like a table DisplayTable stuff_ct = new DisplayTable(111); Console.Clear(); Console.WriteLine(); Console.WriteLine(" YOUR STUFF"); stuff_ct.PrintLine(); string[] headers = new[] { "ID", "Stuff", "Location", "Last Known Date" }; //Console.WriteLine(_stuffList); if (_stuffList.Any()) { stuff_ct.PrintRow(headers); stuff_ct.PrintLine(); foreach (var stuff in _stuffList) { string[] rowData = new[] { stuff.Stuff_ID.ToString(), stuff.Stuff_Name, stuff.Location_Name, stuff.Location_Date.ToString() }; stuff_ct.PrintRow(rowData); } } else { Console.WriteLine(" This is odd...you have no stuff. Try adding some of your junk cause I know you have it."); } stuff_ct.PrintLine(); Console.WriteLine(); Console.WriteLine(" Hit [Enter] to get back to the previous menu."); Console.ReadLine(); }
public void TableWriter_SimpleTable_WritesHeaderLines3LineBreaks() { var mockOutputter = new Mock <IConsoleOutputter>(); var target = new TableWriter(mockOutputter.Object, new ViewPort(100, 100)); var table = new DisplayTable() { Header = new TableRow { Cells = new[] { new BasicTableCell { ContentAreas = new[] { new BasicCellContent { Value = "TestCell" } } } } }, ColumnDetails = new[] { new ColumnDetails { columnName = "harrumph", columnWidth = 10, isNullable = false, type = Data.DataType.String } } }; target.Draw(table); mockOutputter.Verify(m => m.Write(It.Is <string>(s => s == Environment.NewLine)), Times.Exactly(3)); }
private void WriteHeaderLine(DisplayTable table, ViewPort viewPort, bool displayTypes = false) { for (int j = 0; j < table.Header.MaxCellLineCount; j++) { consoleOutputter.Write(verticalSeparator); for (int h = 0; h < table.Header.Cells.Length; h++) { ColumnDetails column = table.ColumnDetails[h]; TableCell cell = table.Header.Cells[h]; cell.Write(consoleOutputter, viewPort, j, column); consoleOutputter.Write(verticalSeparator); } consoleOutputter.Write(Environment.NewLine); } // todo: the idea of a TableCell is to handle this /*if (displayTypes) * { * consoleOutputter.Write(verticalSeparator); * foreach (ColumnDetails column in sheet.Columns) * { * int offset = column.isNullable ? 1 : 0; * if (IsOverlyLargeColumn(column, viewPort)) * { * for (int i = 0; i < viewPort.Width - offset - column.type.ToString().Length - (verticalSeparator.Length * 2) - Environment.NewLine.Length; i++) * { * consoleOutputter.Write(" "); * } * } * else * { * for (int i = 0; i < column.columnWidth - column.type.ToString().Length - offset; i++) * { * consoleOutputter.Write(" "); * } * } * consoleOutputter.ForegroundColor = ConsoleColor.Blue; * * if (column.columnWidth > column.type.ToString().Length + (verticalSeparator.Length * 2)) * { * consoleOutputter.Write(column.type.ToString()); * } * else * { * int howMuchSpaceDoWeHave = column.isNullable ? column.columnWidth - 1 : column.columnWidth; * consoleOutputter.Write(column.type.ToString().Substring(0, howMuchSpaceDoWeHave)); * } * * * if (column.isNullable) * { * consoleOutputter.ForegroundColor = ConsoleColor.Cyan; * consoleOutputter.Write("?"); * consoleOutputter.ResetColor(); * } * consoleOutputter.Write(verticalSeparator); * } * consoleOutputter.Write(Environment.NewLine); * }*/ }
private static void ReviewAuction(CharacterInstance ch, IAuctionManager auctionManager) { if (CheckFunctions.CheckIfNullObject(ch, (auctionManager ?? AuctionManager.Instance).Auction, "There is nothing being auctioned right now. What would you like to auction?")) { return; } ch.SetColor(ATTypes.AT_BLUE); ch.SendTo("Auctions:"); var auction = (auctionManager ?? AuctionManager.Instance).Auction; if (auction.BidAmount > 0) { ch.Printf("Current bid on this item is %s coin.", auction.BidAmount); } else { ch.SendTo("No bids on this item have been received."); } ch.SetColor(ATTypes.AT_LBLUE); ch.Printf("Object '%s' is %s, special properties: %s\r\nIts weight is %d, value is %d, and level is %d.", auction.ItemForSale.Name, auction.ItemForSale.Name.AOrAn(), auction.ItemForSale.ExtraFlags.ToString(), auction.ItemForSale.Weight, auction.ItemForSale.Cost, auction.ItemForSale.Level); if (auction.ItemForSale.WearLocation != WearLocations.Light) { ch.Printf("Item's wear location: %s", auction.ItemForSale.WearLocation); } ch.SetColor(ATTypes.AT_BLUE); if (DisplayTable.ContainsKey(auction.ItemForSale.ItemType)) { DisplayTable[auction.ItemForSale.ItemType].Invoke(ch, auction.ItemForSale); } foreach (var af in auction.ItemForSale.ObjectIndex.Affects) { handler.showaffect(ch, af); } foreach (var af in auction.ItemForSale.Affects) { handler.showaffect(ch, af); } if ((auction.ItemForSale.ItemType == ItemTypes.Container || auction.ItemForSale.ItemType == ItemTypes.KeyRing || auction.ItemForSale.ItemType == ItemTypes.Quiver) && auction.ItemForSale.Contents.Any()) { ch.SetColor(ATTypes.AT_OBJECT); ch.SendTo("Contents:"); act_info.show_list_to_char(auction.ItemForSale.Contents.ToList(), (PlayerInstance)ch, true, false); } if (ch.IsImmortal()) { ch.Printf("Seller: %s. Bidder: %s. Round: %d,", auction.Seller.Name, auction.Buyer.Name, auction.GoingCounter + 1); ch.Printf("Time left in round: %d.", auction.PulseFrequency); } }
private void DrawSheet(ViewModel viewModel, ConsoleSheet currentSheet, ConsoleFold currentFold, ViewPort viewPort, bool displayTypes, bool displayNulls, string truncationIdentifier, bool displayRefs) { Console.Clear(); DisplayTable displayTable = new DisplayTable(); displayTable.Header = GenerateHeaderFromSheet(viewModel, currentSheet); displayTable.ColumnDetails = currentSheet.Columns.ToArray(); displayTable.Rows = GenerateRowsFromFold(viewModel, currentFold, currentSheet); new Tablular.TableWriter(viewPort).Draw(displayTable); WriteSummary(viewModel, currentSheet, currentFold, displayNulls); Input input = AwaitInput(); switch (input) { case Input.NoOp: DrawSheet(viewModel, currentSheet, currentFold, viewPort, displayTypes, displayNulls, truncationIdentifier, displayRefs); break; case Input.Quit: break; case Input.NextSheet: if (unreadSheets.Any()) { readSheets.Push(currentSheet); ConsoleSheet nextPage = unreadSheets.Pop(); _currentSheet = nextPage; DrawSheet(viewModel, nextPage, currentFold, viewPort, displayTypes, displayNulls, truncationIdentifier, displayRefs); } else { DrawSheet(viewModel, currentSheet, currentFold, viewPort, displayTypes, displayNulls, truncationIdentifier, displayRefs); } break; case Input.PrevSheet: if (readSheets.Any()) { unreadSheets.Push(currentSheet); ConsoleSheet lastPage = readSheets.Pop(); _currentSheet = lastPage; DrawSheet(viewModel, lastPage, currentFold, viewPort, displayTypes, displayNulls, truncationIdentifier, displayRefs); } else { DrawSheet(viewModel, currentSheet, currentFold, viewPort, displayTypes, displayNulls, truncationIdentifier, displayRefs); } break; case Input.NextFold: if (unreadFolds.Any()) { readFolds.Push(currentFold); ConsoleFold nextFold = unreadFolds.Pop(); _currentFold = nextFold; this.Update(viewModel, displayTypes, displayNulls, truncationIdentifier, displayRefs); } else { DrawSheet(viewModel, currentSheet, currentFold, viewPort, displayTypes, displayNulls, truncationIdentifier, displayRefs); } break; case Input.PrevFold: if (readFolds.Any()) { unreadFolds.Push(currentFold); ConsoleFold lastFold = readFolds.Pop(); _currentFold = lastFold; this.Update(viewModel, displayTypes, displayNulls, truncationIdentifier, displayRefs); } else { DrawSheet(viewModel, currentSheet, currentFold, viewPort, displayTypes, displayNulls, truncationIdentifier, displayRefs); } break; } }