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 8079063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:59:23+00:00 2026-06-05T15:59:23+00:00

I have a project that I have divided quite aggressively into different layers. I

  • 0

I have a project that I have divided quite aggressively into different layers. I have

  • REST Service (asp.net Web Api)
  • Service Layer
  • Data Layer
  • Filters (extension methods on top of Data Layer)
  • A number of Models and separate DTOs
  • DbContext

What should I unit test?

Technically my REST Service points at my Service. So if I test my REST, I am also testing my Service.

Models, I don’t see how I can test these?

DBContext, is it necessary to test these?

If I test my Service I am testing my DataLayer

  • 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-06-05T15:59:24+00:00Added an answer on June 5, 2026 at 3:59 pm

    A good rule of thumb is anything containing business logic should be able to be unit tested. Ideally, all of your layers would be separated by interfaces and you should be able to inject mocked interfaces into the various layers. Anything that accesses an external component (disk, database, network, etc) should also be abstracted away. For example, in your data layer, the code that is responsible for opening the connection to the database, running a SQL statement, and closing the connection should be abstracted away. Then you can mock up the data access interface and the code you want to test, can be tested. In this example a data access layer method is mocked

    var mockAdapter = new Mock<IDataAdapter>();
    var repo = new Mock<RepositoryObject> (mockAdapter.Object) { CallBase = true };
    
    var param = new Mock<IDbDataParameter>();
    param.Setup(mock => mock.Value).Returns("TEST RESPONSE");
    
    var bindParam = new DynamicParameters.ParamInfo { Name = "strResponse", AttachedParam = param.Object };
    var paramList = new DynamicParameters();
    paramList.Parameters.Add("strResponse", bindParam);
    
    repo.Setup(mock => mock.GetParameters(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<string>())).Returns(paramList);
    
    string actual = repo.Object.ExecuteSomeSqlStatement(string.Empty, string.Empty, int.MinValue, string.Empty);
    
    Assert.AreEqual("TEST RESPONSE", actual);
    

    As far as your models, if they contain only properties then it serves no purpose in testing them.

    There are some instances where unit testing makes zero sense, such as creating a TCP server opening up listening point. Hopefully those are few and far between.

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

Sidebar

Related Questions

I have a java SE web application that is divided in layers. each database
I have a complex web project template where files can be divided into three
I'm working in a project that is divided into multiple modules. Each module have
I have a project that is supposed to run on different (at least 2)
In a Swing project, I have used a JFrame and divided it into three
I have a college programming project in C++ divided into two parts. I beggining
I have an MVC app divided into the usual layers: MVC presentation layer, Business
I currently have a program that i wrote that is divided up into 3
I have written a message board as my first ASP.NET project. It seems to
I have an Android Eclipse project that I'd like to divide into two sub-projects.

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.