Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4088514
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:59:32+00:00 2026-05-20T18:59:32+00:00

Here is my test: [TestFixture] public class DisplayingPageLinks { [Test] public void Can_Generate_Links_To_Other_Pages() {

  • 0

Here is my test:

[TestFixture]
public class DisplayingPageLinks
{
    [Test]
    public void Can_Generate_Links_To_Other_Pages()
    {
        //Arrange: We're going to extend the Html helper class.
        //It doesn't matter if the variable we use is null            
        HtmlHelper html = null;

        PagingInfo pagingInfo = new PagingInfo(){
            CurrentPage = 2,
            TotalItems = 28,
            ItemsPerPage = 10
        };

        Func<int, String> pageUrl = i => "Page" + 1;

        //Act: Here's how it should format the links.
        MvcHtmlString result = html.PageLinks(pagingInfo, pageUrl);

        //Assert:
        result.ToString().ShouldEqual(@"<a href=""Page1"">1</a><a href=""Page2"">2</a><a href=""Page3"">3</a>");
    }
}

Here is the PageLinks extension method:

public static MvcHtmlString PageLinks(this HtmlHelper html, PagingInfo pagingInfo, Func<int,string> pageUrl)
{
    StringBuilder result = new StringBuilder();

    for (int i = 1; i < pagingInfo.TotalPages; i++)
    {
        TagBuilder tag = new TagBuilder("a");
        tag.MergeAttribute("href", pageUrl(i));
        tag.InnerHtml = i.ToString();
        if (i == pagingInfo.CurrentPage)
        {
            tag.AddCssClass("selected");
        }
        result.Append(tag.ToString());
    }

    return MvcHtmlString.Create(result.ToString());
}

Finally here is the result for the running test:

SportsStore.UnitTests.DisplayingPageLinks.Can_Generate_Links_To_Other_Pages:
Expected string length 63 but was 59.
Strings differ at index 24.
Expected: “123” But was: “12”
———————————–^

The error doesn’t copy the way it’s shown in the GUI – sorry.

Can you give me some suggestions as to why NUnit is saying it receives something I don’t expect it to give out.

According to what I’m reading in the PageLinks extension method, it seems that the markup should be formed correctly.

Any suggestions? I’m a TDD newbie and really trying to learn here. 🙂


Edit:

It seems the culprit was this. My Test was using:
Func pageUrl = i => “Page” + 1;

instead of

Func pageUrl = i => “Page” + i;

But now there’s another error. 🙁

It seems something is wrong when calculating the amount of pages in the PagingInfo class:

public class PagingInfo
{
    public int TotalItems { get; set; }
    public int ItemsPerPage { get; set; }
    public int CurrentPage { get; set; }

    public int TotalPages
    {
        get { return (int)Math.Ceiling((decimal)TotalItems / ItemsPerPage); }
    }
}

It seems the error stems on the fact that this is returning 2 pages, instead of 3.

Is there something wrong in this calculation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:59:33+00:00Added an answer on May 20, 2026 at 6:59 pm

    (Replying to the new question posed in your edit.) Your loop in PageLinks() is starting with i = 1 and having i < pagingInfo.TotalPages as condition – a classical off-by-one error. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the unit test: [TestFixture] public class HomeControllerTests { [Test] public void Index_GET_Asks_For_Index_View()
[TestFixture] public class ExpandoToMessageConverterTests { /// <summary> /// CanConvertEvent /// </summary> [Test] public void
Here's what I have in my test so far: [TestFixture] public class IndividualMovieTests {
here is the test page http://www.studioteknik.com/html/test-portfolio.html I got no error, but no hover-slide effect...
Test.h class Test { public: Test(); //some methods private: int var; //some vars }
I often hear around here from test driven development people that having a function
Here is a test description, testing the Create New Widget use-case. Confirm that you
Here is a test framework to show what I am doing: create a new
Here is my test page (dont mind the layout right now) https://www.bcidaho.com/test_kalyani/employer-plans-test.asp i found
My test site here is working fine I believe (haven't tested it in all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.