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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:33:34+00:00 2026-06-12T09:33:34+00:00

I have started thinking about adding some unit tests around some business logic in

  • 0

I have started thinking about adding some unit tests around some business logic in my project.

The first method that I would like to test is a method in my service layer that returns a list of child nodes for a given node.

The method looks like this:

public List<Guid> GetSubGroupNodes(string rootNode)
{
    List<Tree> tree = ssdsContext.Trees.ToList();
    Tree root = ssdsContext.Trees.Where(x => x.UserId == new Guid(rootNode)).FirstOrDefault();
    return GetChildNodeIds(root, tree);
} 

private List<Tree> GetChildNodes(Tree rootNode, List<Tree> tree)
{
    kids.Add(rootNode);
    foreach (Tree t in FindChilden(rootNode, tree))
    {
        GetChildNodes(t, tree);
    }
     return kids;
}

The way I’d imaginge testing something like this is to provide a fake Tree structure and then test that a providing a node returns the correct subnodes.

ssdsContext is an ObjectContext.

I’ve seen that its possible to extract and interface for the ObjectContext How to mock ObjectContext or ObjectQuery<T> in Entity Framework? but I’ve also read that mocking a DBContext is a waste of time Unit Testing DbContext.

I have also read that as Entity Framework is an implementation of the repository pattern and unit of work patten here: Generic Repository With EF 4.1 what is the point.

This has all left me a bit confused…is the only real way to test a method like this to create a Repository Layer? Is it even worth unit testing this method?

  • 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-12T09:33:36+00:00Added an answer on June 12, 2026 at 9:33 am

    Wrap the ObjectContext class in a wrapperclass — let’s call it ContextWrapper for fun — that only exposes what you need from it. Then you can inject an interface of this (IContextWrapper) in to your class with your method. A wrapper can be mocked with no hooks attached to the outside world. The treestructure, as you say, is easy to create, and get from your mock object. Thus making your test TRUE unittests instead of a kind of integration test.

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

Sidebar

Related Questions

I started doing some thinking about creating an Android application that can be used
With Google TV around the corner, I started thinking about developing a web application
I'm starting to write a small web application and have started thinking about securing
I have started learning flex 4 and I got myself thinking about how to
I have never used a lightbox before, but recently started thinking about using a
I'm creating a minecraft like voxel engine thing in xna, and have started about
After looking at how Go handles interfaces and liking it, I started thinking about
Since I learned about RDBMS, I started thinking in the relational model and less
I was thinking about how to implement a process that gives the number of
I just started thinking about this, but couldn't get any differences to expose themselves

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.