Responsive Ad Area

Share This Post

test

How to write unit test

I need to write some unit tests on this source code.

public class PagedCollection<T> : ReadOnlyCollection<T>, IPagedCollection<T>
{
    public int CurrentPage { get; }
    public int TotalPages { get; }
    public int PageSize { get; }
    public int TotalCount { get; }
    public bool HasPrevious => CurrentPage > 1;
    public bool HasNext => CurrentPage < TotalPages;

    public PagedCollection(ICollection<T> items, int count, int pageNumber, int pageSize) : base(items.ToList())
    {
        EnsureArg.IsGte(count, 0, nameof(count));
        EnsureArg.IsGt(pageNumber, 0, nameof(pageNumber));
        EnsureArg.IsGt(pageSize, 0, nameof(pageSize));

        TotalCount = count;
        CurrentPage = pageNumber;
        PageSize = pageSize;
        TotalPages = (int)Math.Ceiling(count / (double)pageSize);
    }
}

}

And I have 1 more question about unit testing. What is difference between mock and stub? Thank you for your reply and have a nice day!


How to write unit test
How to write unit test
test
{$excerpt:n}

Share This Post

Leave a Reply

Your email address will not be Publishedd. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>