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 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 the following 2 objects: User and DomainUser User.java: package com.domain; import java.io.Serializable;
Assume some domain and view objects (that have no common base class) public class
I have this huge domain object(say parent) which contains other domain objects. It takes
I have a list of System.DirectoryServices.ActiveDirectory.Domain objects gotten via this method. How do I
Assume I have this domain object... public class SpansMultipleTables { public int CommonID {get;
I have a domain object class User (it is a JPA entity): @Entity public
I have written my application logic in domain objects (to enable multiple user interfaces
I have an application that uses Hibernate for its domain objects. One part of
I have a dao jar file that contains all the domain objects and service
I use AutoMapper to map my domain objects to my view models. I have

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.