示例#1
0
        void Display(PagedModel pagedModel)
        {
            var formatted = _formatter.Format(pagedModel);

            _console.Clear();
            _console.Write(formatted);
            _console.WriteLine("Page {0} of {1}", pagedModel.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");
        }
示例#2
0
        public void ShouldYieldNumberOfPages()
        {
            var model = new Model();

            model.SetHeader(new[] { "Foo", "Bar" });
            model.AddRow(new[] { "1", "2" });
            model.AddRow(new[] { "1111", "2222" });
            model.AddRow(new[] { "1111", "2222" });
            model.AddRow(new[] { "1111", "2222" });
            model.AddRow(new[] { "1111", "2222" });
            model.AddRow(new[] { "1111", "2222" });
            model.AddRow(new[] { "1111", "2222" });

            var paged = new PagedModel(model, 0, 2);

            Assert.AreEqual(3, paged.MaxPageIndex);
        }
示例#3
0
        public void CanRenderPagedTable_Page1()
        {
            var model = new Model();

            model.SetHeader(new[] { "Foo", "Bar" });
            model.AddRow(new[] { "1", "2" });
            model.AddRow(new[] { "1111", "2222" });

            var page1 = new PagedModel(model, 1, 1);

            var output = new TableFormatter().Format(page1);

            Assert.AreEqual(@"Foo |Bar |
----+----+
1111|2222|
", output);
        }
示例#4
0
        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;
            }
        }
示例#5
0
 ICommand DetermineNextAction(PagedModel pagedModel, char userInput)
 {
     return(_possibleInteractions
            .First(x => x.CanHandle(userInput.ToString().ToUpperInvariant()))
            .GetCommand(pagedModel));
 }