public void Display(string file, int pageSize) { var model = new NumberedModel(_fileReader.Read(file)); var pageIndex = 0; while (true) { var pagedModel = new PagedModel(model, pageIndex, pageSize); var formatted = _formatter.Format(pagedModel); _console.Clear(); _console.Write(formatted); _console.WriteLine("Page {0} of {1}", pageIndex + 1, pagedModel.MaxPageIndex + 1); _console.WriteLine(String.Empty); _console.Write("N(ext page, P(revious page, F(irst page, L(ast page, J(ump to page, eX(it"); var userInput = _console.Read(); var nextAction = DetermineNextAction(pagedModel, userInput, pageIndex); pageIndex = nextAction.Execute(); if (pageIndex < 0) { return; } } }
public void RowsOfNumbredModel_Should_ContainNumbers() { var model = new Model() .SetHeader(new[] { "header" }) .AddRow(new[] { "one" }) .AddRow(new[] { "two" }); var numbered = new NumberedModel(model); Assert.AreEqual(2, numbered.Header.Count()); Assert.AreEqual(2, numbered.Rows.First().Count()); Assert.AreEqual("No.", numbered.Header.First()); Assert.AreEqual("1.", numbered.Rows.First().First()); Assert.AreEqual("2.", numbered.Rows.Skip(1).First().First()); }
public void RowsOfNumbredModel_Should_ContainNumbers() { var model = new Model() .SetHeader(new[] { "header" }) .AddRow(new[] { "one" }) .AddRow(new[] { "two" }); var numbered = new NumberedModel(model); Assert.AreEqual(2, numbered.Header.Count()); Assert.AreEqual(2, numbered.Rows.First().Count()); Assert.AreEqual("No.", numbered.Header.First()); Assert.AreEqual("1.", numbered.Rows.First().First()); Assert.AreEqual("2.", numbered.Rows.Skip(1).First().First()); }
public void Display(string file, int pageSize) { var modelFromFile = _fileReader.Read(file); var model = new NumberedModel(modelFromFile); var pageIndex = 0; while (true) { var pagedModel = new PagedModel(model, pageIndex, pageSize); Display(pagedModel); var userInput = _console.Read(); var nextAction = DetermineNextAction(pagedModel, userInput); var maybePageIndex = nextAction.GetNextPageIndex(); if (maybePageIndex == null) { return; } pageIndex = maybePageIndex.Value; } }