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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:17:10+00:00 2026-05-17T16:17:10+00:00

I want to create an IList of objects that are all different concrete types,

  • 0

I want to create an IList of objects that are all different concrete types, so:

var tasks = new List<ITask>();
foreach (string taskName in taskNames)
{
    var task = MockRepository.GenerateStub<ITask>();
    task.Stub(t => t.Name).Return(taskName);
    tasks.Add(task);
}
return tasks;

The problem is that each stub object is all the same concrete type. Normally this is fine, but I have a case where I want to test each one being a different type. Can I somehow configure Rhino Mocks to do this, in this case?

EDIT:

The “you-must-be-doing-it-wrong-crew” are out in force today. Since you all seem to think I need to justify my use-case before you can take a stab at answering my question, here’s what I’m doing:

  • ITask is in my domain model, so it’s part of my business layer.
  • I have logic in a higher level (presentation) layer that takes an ITask as an argument.
  • The presentation layer logic normally executes a default Strategy on the ITask, but there can be special cases where we need to use a different Strategy, and the Strategy to use depends entirely upon the concrete type of the ITask object.
  • The regular Strategy pattern doesn’t work here because that requires my concrete ITask objects to know about a layer above them.
  • Decorators still have to know about the concrete type of the object they decorate, and have to be applied either at construction time (wrong layer for this case) or when used, but then that leaves me with the same problem – applying a decorator based on concrete type.
  • I decided to use the same pattern used by DataTemplates (and the DataType attribute) in WPF. That is, given an object from a lower layer, see if anyone’s registered a Strategy to handle that type, and if so, use it. Otherwise, use a default Strategy.

So, I hope you can see why I need the test logic. So far I’ve had to write my own Stub factory that generates from a limited pool of concrete ITask types. It works, but I’d rather let Rhino Mocks do it for me.

  • 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-17T16:17:11+00:00Added an answer on May 17, 2026 at 4:17 pm

    You could add a ITask.Type property.

    The code which is interested in the type behind the interface should then use this property instead of calling GetType(). In your tests, it then becomes trivial to take control of what the Type property returns for any given ITask stub.

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

Sidebar

Related Questions

I want to create a new field (or two) in my table that is
I want to create dynamic lambda expressions so that I can filter a list
I want create wordpress website into which I want create user management... That means
i want create a custom json data from the mssql 2008 results so that
i want create Dynamic Slideshow in Jquery i'm Write this code var ctx =
I want create module which update list of usb devices automatically (not only mass
I want to create a read-only keyed collection that implements IDictionary<'K, 'V> and IEnumerable<'V>.
I want to create a method that can take an NSMutableArray or an NSArray
I have a library function that returns a list of domain objects from a
When I list points I want to add up all the points for a

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.