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

  • SEARCH
  • Home
  • 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 5950379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:23:06+00:00 2026-05-22T17:23:06+00:00

Lets assume I’ve created the following test for my sample blog app: [TestClass] public

  • 0

Lets assume I’ve created the following test for my sample blog app:

[TestClass]
public class when_the_blog_controller_index_action_executes : BlogControllerTests
{
      //...

    [TestMethod]
    [TestCategory("BlogController")]
    public void it_should_pass_the_latest_blogentries_to_the_view()
    {
        blogs = new List<BlogEntry>() { new BlogEntry("title1", "b1"), new BlogEntry("title2", "b2"), new BlogEntry("title3", "b3") };
        blogServiceMock = new Mock<IBlogService>();

        blogServiceMock.Setup(s => s.GetLatestBlogEntries())
                       .Returns(blogs);

        var controller = new BlogController(blogServiceMock.Object);

        var model = ((ViewResult)controller.Index()).Model as IEnumerable<BlogEntry>;

        Assert.IsTrue(blogs.SequenceEqual(model));
        blogServiceMock.VerifyAll();
    }
}

After the BlogController implementation, I have a running test:

public class BlogController : Controller
{
    IBlogService blogService;

    public BlogController(IBlogService blogService)
    {
        this.blogService = blogService;
    }

    public ActionResult Index()
    {
        var model = blogService.GetLatestBlogEntries();

        return View(model);
    }
}

So what is the next step? Should I create the implementation for the IBlogService (with test) and after create the repository (with test)?
If I’d have a service like this, basically i wouldn’t test anything, because I’d just mocking the repository…

public class BlogService : IBlogService
{
    IBlogRepository blogRepository;

    public BlogService(IBlogRepository blogRepository)
    {
        this.blogRepository = blogRepository;
    }

    public IEnumerable<BlogEntry> GetLatestBlogEntries()
    {
        return blogRepository.GetLatestBlogEntries();
    }
}
  • 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-22T17:23:07+00:00Added an answer on May 22, 2026 at 5:23 pm

    The next step is to unit test the BlogService implementation you have written. In this test you should ensure that the proper methods are being called on a mocked repository. If later your service logic evolves and you have some methods that perform more than just CRUD repository access your test will start to make more sense.

    Your current implementation of this service simply delegates the calls to the repository and that’s what you should unit test.

    And if you find yourself having your service layer consist of simple CRUD methods that are doing nothing more than delegating the call to some repository maybe you should ask yourself on the usefulness of this service layer and whether it wouldn’t be also possible to directly use the repository from the controller.

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

Sidebar

Related Questions

Lets assume following classes definition: public class A { public final static String SOME_VALUE;
Lets assume we have the following code: abstract class Base1 { protected int num;
Lets assume I had the following Model class A(Models.model): def __init__(self,data): B(a=self,data=data).save() class B(Models.model):
Lets assume I have the following Java code: public String foo() { // returns
Lets assume I have created a facebook app.So all those who(Admin) have facebook fan
Lets assume this hierarchy. public class A { public int Id { get; set;
Lets assume: List<element> which element is: public class Element { int Weight { get;
Lets assume a xml file named data.xml with following content: <root> <record> <id>1</id> <name>test
Lets assume I have the following 3 entities: Customer,Order,Product which interact in the View
Lets assume we have a class car. How would You name parameters of function

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.