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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:20:57+00:00 2026-05-13T10:20:57+00:00

So in my domain I have 3 objects. User, Item and Tag. Each user

  • 0

So in my domain I have 3 objects. User, Item and Tag. Each user has items and tags, each item has tags and each tag has items.

The objects look a little like this:

public class User
{
    public List<Item> Items { get; set; }
    public List<Tag> Tags { get; set; }
}
public class Item
{
     public List<Tag> Tags { get; set; }
}
public class Tag
{
     public List<Item> Items { get; set;}
}

This is the first time I have a go TDD so I was wondering how do I get mocks/fakes(not sure about the right term) that I can use in my tests. At first I tried to just create some fake objects but with the many to many it seems like a lot of work.

Thanks in advance

  • 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-13T10:20:57+00:00Added an answer on May 13, 2026 at 10:20 am

    Generally you would create an interface for all of those use those interfaces with a Mock framework:

    public interface IUser
    {
        List<Item> Items { get; set; }
        List<Tag> Tags { get; set; }
    }
    public interface IItem
    {
         List<Tag> Tags { get; set; }
    }
    public interface ITag
    {
         List<Item> Items { get; set;}
    }
    

    If, for example, you use NMock, you would something like this:

    IUser user = mockery.NewMock<IUser>();
    var testTags = new List<ITag.();
    user.Expect().Once.On("Tags").Will(Return.Value(testTags));
    

    This technique allows you to slice your components and place mock object and use those for testing. Also the mock framework will create temporary implementations of the interface which is very convinient.

    As always, when you start with TDD and mocking, you must read this Martin Fowler article:

    http://martinfowler.com/articles/mocksArentStubs.html

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

Sidebar

Related Questions

I have a collection of domain objects that I need to convert into another
So let's say we have a domain object such as the following public class
I have a basic domain object, say like Person or Campaign or Event that
I have the current basic structure for each domain object that I need to
Let's say I have an interface representing a domain object: public interface IFoo {
I have a property on a domain object that is declared in a many-to-one
I have the following models. # app/models/domain/domain_object.rb class Domain::DomainObject < ActiveRecord::Base has_many :links_from, :class_name
We have our domain model declared in rusty old hbm files, we wish to
I have a domain class containing a couple of fields. I can access them
I have a domain and a group of sub-domains that require authentication to access.

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.